pub struct GbpFrame {
pub version: u8,
pub group_id: ByteBuf,
pub epoch: u64,
pub transition_id: u32,
pub stream_type: u8,
pub stream_id: u32,
pub flags: u16,
pub sequence_no: u32,
pub payload_size: u32,
pub encrypted_payload: ByteBuf,
pub payload_format: u8,
}Expand description
CBOR-encoded GBP frame.
Fields§
§version: u8Protocol version (currently 1).
group_id: ByteBuf16-byte group identifier.
epoch: u64Sender’s current epoch.
transition_id: u32Last applied transition_id.
stream_type: u8StreamType as a u8 (see gbp_core::StreamType).
stream_id: u32Logical stream identifier within the session.
flags: u16Delivery flags (see gbp_core::GbpFlags).
sequence_no: u32Per-stream sequence number (replay window key).
payload_size: u32Declared payload length; MUST equal encrypted_payload.len().
encrypted_payload: ByteBufEncrypted payload (an opaque byte string).
payload_format: u8Payload codec discriminant (see gbp_core::PayloadCodec).
Omitted when 0 (CBOR) for backward-compatibility with pre-1.5 peers.
Implementations§
Source§impl GbpFrame
impl GbpFrame
Sourcepub fn new(
group_id: [u8; 16],
epoch: u64,
transition_id: u32,
stream_type: StreamType,
stream_id: u32,
flags: u16,
sequence_no: u32,
encrypted_payload: Vec<u8>,
payload_format: u8,
) -> GbpFrame
pub fn new( group_id: [u8; 16], epoch: u64, transition_id: u32, stream_type: StreamType, stream_id: u32, flags: u16, sequence_no: u32, encrypted_payload: Vec<u8>, payload_format: u8, ) -> GbpFrame
Builds a frame from already-encrypted payload bytes.
payload_size is set to encrypted_payload.len() automatically.
Pass PayloadCodec::Cbor (or 0) for the default CBOR encoding; the
pf field is omitted from the wire when the codec is CBOR so older
peers continue to decode the frame correctly.
Sourcepub fn payload_codec(&self) -> PayloadCodec
pub fn payload_codec(&self) -> PayloadCodec
Returns the payload_format field as a PayloadCodec, falling back
to PayloadCodec::Cbor for unknown discriminants.
Sourcepub fn to_cbor(&self) -> Vec<u8> ⓘ
pub fn to_cbor(&self) -> Vec<u8> ⓘ
Serialises the frame into a freshly allocated CBOR byte vector.
Sourcepub fn from_cbor(data: &[u8]) -> Result<GbpFrame, CodecError>
pub fn from_cbor(data: &[u8]) -> Result<GbpFrame, CodecError>
Decodes a CBOR-encoded frame and validates payload_size.
The order of all §6.2 checks (version, group_id, epoch,
payload_size, transition_id, sequence_no) is what governs which
error a malformed frame produces. Most callers should use
GroupNode::on_wire which decodes via
GbpFrame::decode and runs the full pipeline. This convenience
wrapper exists for tests and ad-hoc tooling that want both decode
and the length check in one shot.
Sourcepub fn decode(data: &[u8]) -> Result<GbpFrame, CodecError>
pub fn decode(data: &[u8]) -> Result<GbpFrame, CodecError>
Decodes a CBOR-encoded frame without running any §6.2 checks.
Use GbpFrame::validate_payload_size (and the higher-priority
version / group_id / epoch checks at the calling layer) before
trusting the result.
Sourcepub fn validate_payload_size(&self) -> Result<(), CodecError>
pub fn validate_payload_size(&self) -> Result<(), CodecError>
Returns Ok(()) if payload_size equals the actual payload length,
Err(CodecError::PayloadSizeMismatch) otherwise.
Sourcepub fn stream_type_typed(&self) -> Result<StreamType, CodecError>
pub fn stream_type_typed(&self) -> Result<StreamType, CodecError>
Returns the typed StreamType, or CodecError::UnknownEnumValue for
unknown stream classes.
Sourcepub fn group_id_array(&self) -> [u8; 16]
pub fn group_id_array(&self) -> [u8; 16]
Returns group_id as a 16-byte array, padding with zeros or
truncating if necessary.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for GbpFrame
impl<'de> Deserialize<'de> for GbpFrame
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GbpFrame, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GbpFrame, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for GbpFrame
impl Serialize for GbpFrame
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for GbpFrame
impl RefUnwindSafe for GbpFrame
impl Send for GbpFrame
impl Sync for GbpFrame
impl Unpin for GbpFrame
impl UnsafeUnpin for GbpFrame
impl UnwindSafe for GbpFrame
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more