Skip to main content

GbpFrame

Struct GbpFrame 

Source
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: u8

Protocol version (currently 1).

§group_id: ByteBuf

16-byte group identifier.

§epoch: u64

Sender’s current epoch.

§transition_id: u32

Last applied transition_id.

§stream_type: u8

StreamType as a u8 (see gbp_core::StreamType).

§stream_id: u32

Logical stream identifier within the session.

§flags: u16

Delivery flags (see gbp_core::GbpFlags).

§sequence_no: u32

Per-stream sequence number (replay window key).

§payload_size: u32

Declared payload length; MUST equal encrypted_payload.len().

§encrypted_payload: ByteBuf

Encrypted payload (an opaque byte string).

§payload_format: u8

Payload codec discriminant (see gbp_core::PayloadCodec). Omitted when 0 (CBOR) for backward-compatibility with pre-1.5 peers.

Implementations§

Source§

impl GbpFrame

Source

pub fn new( group_id: GroupId, epoch: u64, transition_id: u32, stream_type: StreamType, stream_id: u32, flags: u16, sequence_no: u32, encrypted_payload: Vec<u8>, payload_format: u8, ) -> Self

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.

Source

pub fn payload_codec(&self) -> PayloadCodec

Returns the payload_format field as a PayloadCodec, falling back to PayloadCodec::Cbor for unknown discriminants.

Source

pub fn to_cbor(&self) -> Vec<u8>

Serialises the frame into a freshly allocated CBOR byte vector.

Source

pub fn from_cbor(data: &[u8]) -> Result<Self, 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.

Source

pub fn decode(data: &[u8]) -> Result<Self, 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.

Source

pub fn validate_payload_size(&self) -> Result<(), CodecError>

Returns Ok(()) if payload_size equals the actual payload length, Err(CodecError::PayloadSizeMismatch) otherwise.

Source

pub fn stream_type_typed(&self) -> Result<StreamType, CodecError>

Returns the typed StreamType, or CodecError::UnknownEnumValue for unknown stream classes.

Source

pub fn group_id_array(&self) -> GroupId

Returns group_id as a 16-byte array, padding with zeros or truncating if necessary.

Trait Implementations§

Source§

impl Clone for GbpFrame

Source§

fn clone(&self) -> GbpFrame

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GbpFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GbpFrame

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GbpFrame

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.