pub struct ProtocolEnvelope {
pub protocol_version: u32,
pub message_type: u32,
pub payload: Vec<u8>,
pub payload_crc32: u32,
}Expand description
The versioned, checksummed form of every protocol message.
Fields§
§protocol_version: u32Protocol version; see PROTOCOL_VERSION.
message_type: u32Discriminant of the payload message; numbers are never reused.
payload: Vec<u8>Encoded message payload. The envelope never interprets these bytes.
payload_crc32: u32CRC-32 over version, type, length, and payload.
Implementations§
Source§impl ProtocolEnvelope
impl ProtocolEnvelope
Sourcepub fn new(message_type: u32, payload: Vec<u8>) -> Self
pub fn new(message_type: u32, payload: Vec<u8>) -> Self
Builds an envelope at the current protocol version, computing the checksum.
Sourcepub fn checksum(protocol_version: u32, message_type: u32, payload: &[u8]) -> u32
pub fn checksum(protocol_version: u32, message_type: u32, payload: &[u8]) -> u32
Computes the checksum covering version, type, length, and payload.
Sourcepub fn verify(&self) -> Result<(), EnvelopeError>
pub fn verify(&self) -> Result<(), EnvelopeError>
Fails closed unless the version is supported and the checksum matches.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Serializes to the canonical deterministic encoding: equal envelopes always produce byte-identical output.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, EnvelopeError>
pub fn decode(bytes: &[u8]) -> Result<Self, EnvelopeError>
Parses one envelope, verifying version and checksum (fails closed).
Trait Implementations§
Source§impl Clone for ProtocolEnvelope
impl Clone for ProtocolEnvelope
Source§fn clone(&self) -> ProtocolEnvelope
fn clone(&self) -> ProtocolEnvelope
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProtocolEnvelope
impl Debug for ProtocolEnvelope
Source§impl<'de> Deserialize<'de> for ProtocolEnvelope
impl<'de> Deserialize<'de> for ProtocolEnvelope
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ProtocolEnvelope
Source§impl PartialEq for ProtocolEnvelope
impl PartialEq for ProtocolEnvelope
Source§impl Serialize for ProtocolEnvelope
impl Serialize for ProtocolEnvelope
impl StructuralPartialEq for ProtocolEnvelope
Auto Trait Implementations§
impl Freeze for ProtocolEnvelope
impl RefUnwindSafe for ProtocolEnvelope
impl Send for ProtocolEnvelope
impl Sync for ProtocolEnvelope
impl Unpin for ProtocolEnvelope
impl UnsafeUnpin for ProtocolEnvelope
impl UnwindSafe for ProtocolEnvelope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request