pub struct VarHeader {
pub key: VarKey,
pub seq_no: VarSeq,
}
Expand description
A variably sized message header
NOTE: We use the standard PartialEq here as it will do the correct things.
Sequence numbers must be EXACTLY the same, and keys must be equivalent when degraded to the smaller of the two.
We DO NOT impl Serialize/Deserialize for this type because we use non-postcard-compatible format (externally tagged)
Fields§
§key: VarKey
The variably sized Key
seq_no: VarSeq
The variably sized Sequence Number
Implementations§
Source§impl VarHeader
impl VarHeader
Sourcepub const KEY_ONE_BITS: u8 = 0u8
pub const KEY_ONE_BITS: u8 = 0u8
Bits for a key of ONE byte
Sourcepub const KEY_TWO_BITS: u8 = 64u8
pub const KEY_TWO_BITS: u8 = 64u8
Bits for a key of TWO bytes
Sourcepub const KEY_FOUR_BITS: u8 = 128u8
pub const KEY_FOUR_BITS: u8 = 128u8
Bits for a key of FOUR bytes
Sourcepub const KEY_EIGHT_BITS: u8 = 192u8
pub const KEY_EIGHT_BITS: u8 = 192u8
Bits for a key of EIGHT bytes
Sourcepub const KEY_MASK_BITS: u8 = 192u8
pub const KEY_MASK_BITS: u8 = 192u8
Mask bits
Sourcepub const SEQ_ONE_BITS: u8 = 0u8
pub const SEQ_ONE_BITS: u8 = 0u8
Bits for a sequence number of ONE bytes
Sourcepub const SEQ_TWO_BITS: u8 = 16u8
pub const SEQ_TWO_BITS: u8 = 16u8
Bits for a sequence number of TWO bytes
Sourcepub const SEQ_FOUR_BITS: u8 = 32u8
pub const SEQ_FOUR_BITS: u8 = 32u8
Bits for a sequence number of FOUR bytes
Sourcepub const SEQ_MASK_BITS: u8 = 48u8
pub const SEQ_MASK_BITS: u8 = 48u8
Mask bits
Sourcepub const VER_ZERO_BITS: u8 = 0u8
pub const VER_ZERO_BITS: u8 = 0u8
Bits for a version number of ZERO
Sourcepub const VER_MASK_BITS: u8 = 15u8
pub const VER_MASK_BITS: u8 = 15u8
Mask bits
Sourcepub fn write_to_vec(&self) -> Vec<u8> ⓘ
pub fn write_to_vec(&self) -> Vec<u8> ⓘ
Encode the header to a Vec of bytes
Sourcepub fn write_to_slice<'a>(
&self,
buf: &'a mut [u8],
) -> Option<(&'a mut [u8], &'a mut [u8])>
pub fn write_to_slice<'a>( &self, buf: &'a mut [u8], ) -> Option<(&'a mut [u8], &'a mut [u8])>
Attempt to write the header to the given slice
If the slice is large enough, a Some
will be returned with the bytes used
to encode the header, as well as the remaining unused bytes.
If the slice is not large enough, a None
will be returned, and some bytes
of the buffer may have been modified.
Sourcepub fn take_from_slice(buf: &[u8]) -> Option<(Self, &[u8])>
pub fn take_from_slice(buf: &[u8]) -> Option<(Self, &[u8])>
Attempt to decode a header from the given bytes.
If a well-formed header was found, a Some
will be returned with the
decoded header and unused remaining bytes.
If no well-formed header was found, a None
will be returned.