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: 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
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.
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<Self, CodecError>
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.
Sourcepub fn decode(data: &[u8]) -> Result<Self, CodecError>
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.
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) -> GroupId
pub fn group_id_array(&self) -> GroupId
Returns group_id as a 16-byte array, padding with zeros or
truncating if necessary.