@@ -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