Skip to main content

Pdu

Struct Pdu 

Source
pub struct Pdu { /* private fields */ }
Expand description

A zero-copy view of a generic CFDP PDU, containing the header and raw bytes.

+—————————————+—————+ | Field Name | Size | +—————————————+—————+ | – PDU Header (Variable Length) —– | ———–– | | | | | – Fixed Part (4 bytes) ———–– | ———–– | | | | | Version Number | 3 bits | | PDU Type | 1 bit | | Direction | 1 bit | | Transmission Mode | 1 bit | | CRC Flag | 1 bit | | Large File Flag | 1 bit | | | | | PDU Data Field Length | 16 bits | | | | | Segmentation Control | 1 bit | | Length of Entity IDs | 3 bits | | Segment Metadata Flag | 1 bit | | Length of Transaction Sequence Number | 3 bits | | | | | – Variable Part (3 to 24 bytes) –– | ———–– | | | | | Source Entity ID | 1 to 8 octets | | Transaction Sequence Number | 1 to 8 octets | | Destination Entity ID | 1 to 8 octets | | | | +—————————————+—————+ | – PDU Data Field (Variable Length) - | ———–– | | | | +—————————————+—————+

Implementations§

Source§

impl Pdu

Source

pub fn header(&self) -> &PduHeaderFixedPart

Returns the fixed part of the header.

Source

pub fn header_mut(&mut self) -> &mut PduHeaderFixedPart

Returns a mutable reference to the fixed part of the header.

Source

pub fn variant(&self) -> Result<PduVariant<'_>, CfdpError>

Parses the PDU data field into a typed PduVariant.

Source

pub fn set_header(&mut self, header: PduHeaderFixedPart)

Sets the fixed part of the header.

Source

pub fn rest(&self) -> &[u8]

Returns the raw rest field as a byte slice.

Source

pub fn header_len(&self) -> usize

Returns the total length of the PDU header (fixed + variable parts).

Source

pub fn source_entity_id(&self) -> Result<EntityId, CfdpError>

Parses and returns a slice for the source entity ID.

Source

pub fn set_source_entity_id( &mut self, source_entity_id: EntityId, ) -> Result<(), CfdpError>

Writes the source entity ID into the variable header.

Source

pub fn transaction_seq_num(&self) -> Result<TransactionSeqNum, CfdpError>

Parses and returns a slice for the transaction sequence number.

Source

pub fn set_transaction_seq_num( &mut self, txn_seq_num: TransactionSeqNum, ) -> Result<(), CfdpError>

Writes the transaction sequence number into the variable header.

Source

pub fn set_destination_entity_id( &mut self, dest_entity_id: EntityId, ) -> Result<(), CfdpError>

Parses and returns a slice for the destination entity ID.

Source

pub fn data_field(&self) -> Result<&[u8], CfdpError>

Returns a slice representing the PDU’s data field.

Source

pub fn data_field_mut(&mut self) -> Result<&mut [u8], CfdpError>

Returns a mutable slice representing the PDU’s data field.

Source

pub fn from_bytes(buffer: &[u8]) -> Result<&Pdu, CfdpError>

A convenience method to parse the entire PDU from a byte buffer.

Source

pub fn from_bytes_mut(buffer: &mut [u8]) -> Result<&mut Pdu, CfdpError>

A convenience method to parse the entire PDU from a byte buffer.

Source§

impl Pdu

Source

pub fn builder<'a>() -> PduBuilder<'a>

Builds a new PDU in the given buffer with header and entity IDs.

Methods from Deref<Target = PduHeaderFixedPart>§

Source

pub fn version(&self) -> u8

Returns the 3-bit CFDP version number.

Source

pub fn set_version(&mut self, version: u8)

Sets the 3-bit CFDP version number.

Source

pub fn pdu_type(&self) -> PduType

Returns the PDU type (File Data or File Directive).

Source

pub fn set_pdu_type(&mut self, pdu_type: PduType)

Sets the PDU type field.

Source

pub fn direction(&self) -> Direction

Returns the direction of the PDU.

Source

pub fn set_direction(&mut self, direction: Direction)

Sets the direction field.

Source

pub fn tx_mode(&self) -> TransmissionMode

Returns the transmission mode (Acknowledged or Unacknowledged).

Source

pub fn set_tx_mode(&mut self, tx_mode: TransmissionMode)

Sets the transmission mode field.

Source

pub fn crc_flag(&self) -> bool

Returns true if the PDU includes a CRC.

Source

pub fn set_crc_flag(&mut self, crc_flag: bool)

Sets the CRC flag.

Source

pub fn large_file_flag(&self) -> bool

Returns true if this is a large-file transaction (64-bit offsets).

Source

pub fn set_large_file_flag(&mut self, large_file_flag: bool)

Sets the large file flag.

Source

pub fn data_field_len(&self) -> usize

Returns the length of the PDU data field in bytes.

Source

pub fn set_data_field_len(&mut self, len: u16)

Sets the PDU data field length.

Source

pub fn segmentation_control(&self) -> bool

Returns the segmentation control flag.

Source

pub fn set_segmentation_control(&mut self, seg_ctrl: bool)

Sets the segmentation control flag.

Source

pub fn entity_id_len(&self) -> usize

Returns the length of entity IDs in bytes (1 to 8).

Source

pub fn set_entity_id_len(&mut self, len: usize) -> Result<(), CfdpError>

Sets the entity ID length (must be 1 to 8).

Source

pub fn segment_metadata_flag(&self) -> bool

Returns the segment metadata flag.

Source

pub fn set_segment_metadata_flag(&mut self, seg_meta_flag: bool)

Sets the segment metadata flag.

Source

pub fn txn_seq_num_len(&self) -> usize

Returns the length of the transaction sequence number in bytes.

Source

pub fn set_txn_seq_num_len(&mut self, len: usize) -> Result<(), CfdpError>

Sets the transaction sequence number length (must be 1 to 8).

Source

pub fn fixed_header_len(&self) -> usize

Returns the size of the fixed header portion in bytes.

Source

pub fn variable_header_len(&self) -> usize

Calculates the length of the variable-sized portion of the PDU header

Source

pub fn total_header_len(&self) -> usize

Returns the total header length (fixed + variable parts).

Source

pub fn total_pdu_len(&self) -> usize

Returns the total PDU length (header + data field).

Trait Implementations§

Source§

impl Debug for Pdu

Source§

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

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

impl Deref for Pdu

Source§

type Target = PduHeaderFixedPart

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Pdu

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl FromBytes for Pdu
where PduHeaderFixedPart: FromBytes, [u8]: FromBytes,

§

fn ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout + Immutable,

Interprets the given source as a &Self. Read more
§

fn ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout + Immutable,

Interprets the prefix of the given source as a &Self without copying. Read more
§

fn ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: Immutable + KnownLayout,

Interprets the suffix of the given bytes as a &Self. Read more
§

fn mut_from_bytes( source: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the given source as a &mut Self. Read more
§

fn mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the prefix of the given source as a &mut Self without copying. Read more
§

fn mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the suffix of the given source as a &mut Self without copying. Read more
§

fn ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the given source as a &Self with a DST length equal to count. Read more
§

fn ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the prefix of the given source as a DST &Self with length equal to count. Read more
§

fn ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the suffix of the given source as a DST &Self with length equal to count. Read more
§

fn mut_from_bytes_with_elems( source: &mut [u8], count: usize, ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the given source as a &mut Self with a DST length equal to count. Read more
§

fn mut_from_prefix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize>,

Interprets the prefix of the given source as a &mut Self with DST length equal to count. Read more
§

fn mut_from_suffix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize>,

Interprets the suffix of the given source as a &mut Self with DST length equal to count. Read more
Source§

impl FromZeros for Pdu
where PduHeaderFixedPart: FromZeros, [u8]: FromZeros,

§

fn zero(&mut self)

Overwrites self with zeros. Read more
Source§

impl IntoBytes for Pdu
where PduHeaderFixedPart: IntoBytes, [u8]: IntoBytes, (): DynamicPaddingFree<Self, { _ }>,

§

fn as_bytes(&self) -> &[u8]
where Self: Immutable,

Gets the bytes of this value. Read more
§

fn as_mut_bytes(&mut self) -> &mut [u8]
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
Source§

impl KnownLayout for Pdu
where [u8]: KnownLayout,

Source§

type PointerMetadata = <[u8] as KnownLayout>::PointerMetadata

The type of metadata stored in a pointer to Self. Read more
§

fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>

Computes the size of an object of type Self with the given pointer metadata. Read more
Source§

impl TryFromBytes for Pdu
where PduHeaderFixedPart: TryFromBytes, [u8]: TryFromBytes,

§

fn try_ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the given source as a &Self. Read more
§

fn try_ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the prefix of the given source as a &Self. Read more
§

fn try_ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the suffix of the given source as a &Self. Read more
§

fn try_mut_from_bytes( bytes: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the given source as a &mut Self without copying. Read more
§

fn try_mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self. Read more
§

fn try_mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self. Read more
§

fn try_ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the given source as a &Self with a DST length equal to count. Read more
§

fn try_ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the prefix of the given source as a &Self with a DST length equal to count. Read more
§

fn try_ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the suffix of the given source as a &Self with a DST length equal to count. Read more
§

fn try_mut_from_bytes_with_elems( source: &mut [u8], count: usize, ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the given source as a &mut Self with a DST length equal to count. Read more
§

fn try_mut_from_prefix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self with a DST length equal to count. Read more
§

fn try_mut_from_suffix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self with a DST length equal to count. Read more
Source§

impl Immutable for Pdu
where PduHeaderFixedPart: Immutable, [u8]: Immutable,

Source§

impl Unaligned for Pdu
where PduHeaderFixedPart: Unaligned, [u8]: Unaligned,

Auto Trait Implementations§

§

impl Freeze for Pdu

§

impl RefUnwindSafe for Pdu

§

impl Send for Pdu

§

impl !Sized for Pdu

§

impl Sync for Pdu

§

impl Unpin for Pdu

§

impl UnsafeUnpin for Pdu

§

impl UnwindSafe for Pdu

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.