@@ -8,5 +8,11 @@ fn main() {
|
||||
.run()
|
||||
.unwrap();
|
||||
|
||||
prost_build::compile_protos(&["src/envelope.proto"], &["src/"]).unwrap();
|
||||
std::fs::create_dir_all("src/generated").unwrap();
|
||||
let mut config = prost_build::Config::default();
|
||||
config.out_dir("src/generated/");
|
||||
|
||||
config
|
||||
.compile_protos(&["src/envelope.proto"], &["src/"])
|
||||
.unwrap();
|
||||
}
|
||||
|
18
crates/crunch-envelope/src/generated/crunch.envelope.rs
Normal file
18
crates/crunch-envelope/src/generated/crunch.envelope.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Envelope {
|
||||
#[prost(message, optional, tag="1")]
|
||||
pub metadata: ::std::option::Option<Metadata>,
|
||||
#[prost(bytes, tag="2")]
|
||||
pub content: std::vec::Vec<u8>,
|
||||
}
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Metadata {
|
||||
#[prost(string, tag="1")]
|
||||
pub domain: std::string::String,
|
||||
#[prost(string, tag="2")]
|
||||
pub entity: std::string::String,
|
||||
#[prost(uint64, tag="3")]
|
||||
pub timestamp: u64,
|
||||
#[prost(uint64, tag="4")]
|
||||
pub sequence: u64,
|
||||
}
|
3
crates/crunch-envelope/src/generated/mod.rs
Normal file
3
crates/crunch-envelope/src/generated/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod crunch {
|
||||
include!("crunch.envelope.rs");
|
||||
}
|
@@ -3,6 +3,7 @@ mod envelope_capnp;
|
||||
#[cfg(feature = "json")]
|
||||
mod json_envelope;
|
||||
|
||||
mod generated;
|
||||
#[cfg(feature = "proto")]
|
||||
mod proto_envelope;
|
||||
|
||||
|
@@ -1,14 +1,11 @@
|
||||
pub mod envelope {
|
||||
include!(concat!(env!("OUT_DIR"), "/crunch.envelope.rs"));
|
||||
}
|
||||
|
||||
use prost::Message;
|
||||
|
||||
use crate::generated::crunch::*;
|
||||
use crate::EnvelopeError;
|
||||
|
||||
pub fn wrap<'a>(domain: &'a str, entity: &'a str, content: &'a [u8]) -> Vec<u8> {
|
||||
let out = envelope::Envelope {
|
||||
metadata: Some(envelope::Metadata {
|
||||
let out = Envelope {
|
||||
metadata: Some(Metadata {
|
||||
domain: domain.to_string(),
|
||||
entity: entity.to_string(),
|
||||
timestamp: 0,
|
||||
@@ -20,8 +17,8 @@ pub fn wrap<'a>(domain: &'a str, entity: &'a str, content: &'a [u8]) -> Vec<u8>
|
||||
out.encode_to_vec()
|
||||
}
|
||||
|
||||
pub fn unwrap<'a>(message: &'a [u8]) -> Result<(Vec<u8>, envelope::Metadata), EnvelopeError> {
|
||||
let out = envelope::Envelope::decode(message).map_err(EnvelopeError::ProtoError)?;
|
||||
pub fn unwrap<'a>(message: &'a [u8]) -> Result<(Vec<u8>, Metadata), EnvelopeError> {
|
||||
let out = Envelope::decode(message).map_err(EnvelopeError::ProtoError)?;
|
||||
|
||||
Ok((
|
||||
out.content,
|
||||
|
Reference in New Issue
Block a user