use codec_proto::generated::proto::reallyme::codec::v1 as proto;
pub struct Header<'a> {
pub(super) identifier: &'a [u8],
pub(super) length_octets: &'a [u8],
pub(super) received: &'a [u8],
pub(super) remainder: &'a [u8],
pub(super) receipt: proto::CodecTlvHeader,
}
impl<'a> Header<'a> {
#[must_use]
pub const fn identifier_bytes(&self) -> &'a [u8] {
self.identifier
}
#[must_use]
pub const fn length_octets(&self) -> &'a [u8] {
self.length_octets
}
#[must_use]
pub const fn received_bytes(&self) -> &'a [u8] {
self.received
}
#[must_use]
pub const fn supplied_remainder(&self) -> &'a [u8] {
self.remainder
}
#[must_use]
pub const fn declared_value_length(&self) -> u64 {
self.receipt.declared_value_length
}
#[must_use]
pub const fn consumed_bytes(&self) -> usize {
self.received.len()
}
#[must_use]
pub const fn contract(&self) -> &proto::CodecTlvHeader {
&self.receipt
}
#[must_use]
pub fn into_contract(self) -> proto::CodecTlvHeader {
self.receipt
}
}
pub struct Frame<'a> {
pub(super) header: Header<'a>,
pub(super) received: &'a [u8],
pub(super) contents: &'a [u8],
pub(super) received_span: proto::CodecByteSpan,
pub(super) contents_span: proto::CodecByteSpan,
pub(super) consumed: u64,
}
impl<'a> Frame<'a> {
#[must_use]
pub const fn header(&self) -> &Header<'a> {
&self.header
}
#[must_use]
pub const fn received_bytes(&self) -> &'a [u8] {
self.received
}
#[must_use]
pub const fn value_bytes(&self) -> &'a [u8] {
self.contents
}
#[must_use]
pub const fn consumed_bytes(&self) -> usize {
self.received.len()
}
#[must_use]
pub fn into_contract(self) -> proto::CodecTlvFrame {
proto::CodecTlvFrame {
header: Some(self.header.into_contract()).into(),
received: Some(self.received_span).into(),
contents: Some(self.contents_span).into(),
consumed_bytes: self.consumed,
}
}
}