#[repr(C)]pub struct SpacePacket {
pub primary_header: PrimaryHeader,
pub data_field: [u8],
}Expand description
A zero-copy view over a CCSDS Space Packet in a raw byte buffer.
This struct provides a low-level, safe view over a byte slice that is
known to contain a valid Space Packet. It can be created via SpacePacket::parse()
or through the ergonomic SpacePacket::builder().
The data_field is an unsized [u8] slice, allowing this struct to represent
packets of any valid length without needing different types.
+------------------------------------+---------+
| Field Name | Size |
+------------------------------------+---------+
+ -- Primary Header (6 bytes) ------ | ------- |
| | |
| Packet Version Number | 3 bits |
| Packet Identification Field | 13 bits |
| - Packet Type | 1 bit |
| - Secondary Header Flag | 1 bit |
| - APID (Application Process ID) | 11 bits |
| Packet Sequence Control | 16 bits |
| - Sequence Flags | 2 bits |
| - Sequence Count | 14 bits |
| Packet Data Length | 16 bits |
| | |
| -- Packet Data Field (Variable) -- | ------- |
| | |
| Secondary Header (if present) | |
| User Data Field | 1-65536 |
| | bytes |
+------------------------------------+---------+Fields§
§primary_header: PrimaryHeaderThe 6-byte fixed primary header.
data_field: [u8]The variable-length data field (secondary header + user data).
Implementations§
Source§impl SpacePacket
impl SpacePacket
Sourcepub fn parse(bytes: &[u8]) -> Result<&Self, ParseError>
pub fn parse(bytes: &[u8]) -> Result<&Self, ParseError>
Parses (zero-copy) a raw byte slice into a SpacePacket.
This function reads the packet header to determine the packet’s total length and returns a view over that exact portion of the provided slice.
Sourcepub fn set_data_field<T: SpacePacketData>(
&mut self,
data: &T,
) -> Result<(), DataFieldError>
pub fn set_data_field<T: SpacePacketData>( &mut self, data: &T, ) -> Result<(), DataFieldError>
Copies a user-defined data structure into the packet’s data field.
The size of T must exactly match the length of the data field.
Sourcepub fn data_as<T: SpacePacketData>(&self) -> Result<&T, DataFieldError>
pub fn data_as<T: SpacePacketData>(&self) -> Result<&T, DataFieldError>
Returns a zero-copy, typed view of the packet’s data field.
This is the primary method for interpreting the packet’s payload as a
specific data structure. It will fail if the size of T does not match
the data field’s length.
Sourcepub fn data_field(&self) -> &[u8] ⓘ
pub fn data_field(&self) -> &[u8] ⓘ
Returns an immutable slice of the packet’s data field.
Sourcepub fn data_field_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_field_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice of the packet’s data field.
Warning: Modifying the data field directly will invalidate any
CRC checksum. If using a CrcSpacePacket, prefer the safe set_data()
method instead.
Sourcepub fn builder<'a, 'b>() -> SpacePacketBuilder<'a, 'b>
pub fn builder<'a, 'b>() -> SpacePacketBuilder<'a, 'b>
Constructs a new SpacePacket in the provided buffer.
Methods from Deref<Target = PrimaryHeader>§
Sourcepub fn version(&self) -> PacketVersion
pub fn version(&self) -> PacketVersion
Returns the 3-bit packet version number.
Sourcepub fn set_version(&mut self, version: PacketVersion)
pub fn set_version(&mut self, version: PacketVersion)
Sets the 3-bit packet version number.
Sourcepub fn packet_type(&self) -> PacketType
pub fn packet_type(&self) -> PacketType
Returns the PacketType (Telemetry or Telecommand).
Sourcepub fn set_packet_type(&mut self, packet_type: PacketType)
pub fn set_packet_type(&mut self, packet_type: PacketType)
Sets the PacketType (Telemetry or Telecommand).
Sourcepub fn secondary_header_flag(&self) -> SecondaryHeaderFlag
pub fn secondary_header_flag(&self) -> SecondaryHeaderFlag
Returns the SecondaryHeader flag (Present or Absent).
Sourcepub fn set_secondary_header_flag(&mut self, flag: SecondaryHeaderFlag)
pub fn set_secondary_header_flag(&mut self, flag: SecondaryHeaderFlag)
Sets the SecondaryHeader flag (Present or Absent).
Sourcepub fn sequence_flag(&self) -> SequenceFlag
pub fn sequence_flag(&self) -> SequenceFlag
Returns the 2-bit SequenceFlag.
Sourcepub fn set_sequence_flag(&mut self, flag: SequenceFlag)
pub fn set_sequence_flag(&mut self, flag: SequenceFlag)
Sets the 2-bit SequenceFlag.
Sourcepub fn sequence_count(&self) -> SequenceCount
pub fn sequence_count(&self) -> SequenceCount
Returns the 14-bit packet sequence count.
Sourcepub fn set_sequence_count(&mut self, count: SequenceCount)
pub fn set_sequence_count(&mut self, count: SequenceCount)
Sets the 14-bit SequenceCount.
Sourcepub fn data_field_len(&self) -> usize
pub fn data_field_len(&self) -> usize
Returns the length of the data field in bytes as specified by the header.
Sourcepub fn set_data_field_len(&mut self, len: u16)
pub fn set_data_field_len(&mut self, len: u16)
Sets the length of the data field in bytes. The value written to the header
will be len - 1 as per the CCSDS standard.
Sourcepub fn packet_len(&self) -> usize
pub fn packet_len(&self) -> usize
Returns the total length of the packet (header + data field) in bytes.
Sourcepub fn cfe_msg_id(&self) -> u16
pub fn cfe_msg_id(&self) -> u16
Reconstructs the CFE-style Message ID (MsgId) from the primary header fields.
This is a crucial convenience function for systems that interact with the cFE
Software Bus (SB). The SB uses a single integer MsgId for routing, which is
a composite value created from several fields in the CCSDS header.
A cFE MsgId is 16-bit integer with the following structure:
+-----------------+------+-----------------------------------------+
| Field | Size | Description |
+-----------------+------+-----------------------------------------+
| APID | 11 | The 11-bit Application Process ID. |
| SB Flag | 1 | 1 indicates a Software Bus message. |
| Type | 1 | 0 for Telemetry, 1 for Telecommand. |
| Reserved | 3 | Unused, should be zero. |
+-----------------+------+-----------------------------------------+Trait Implementations§
Source§impl Debug for SpacePacket
impl Debug for SpacePacket
Source§impl Deref for SpacePacket
impl Deref for SpacePacket
Source§impl DerefMut for SpacePacket
impl DerefMut for SpacePacket
Source§impl FromBytes for SpacePacketwhere
PrimaryHeader: FromBytes,
[u8]: FromBytes,
impl FromBytes for SpacePacketwhere
PrimaryHeader: FromBytes,
[u8]: FromBytes,
§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
&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,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
§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,
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,
§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,
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,
§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,
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,
§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,
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,
§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,
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,
§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,
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,
§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>,
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>,
§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>,
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>,
Source§impl FromZeros for SpacePacketwhere
PrimaryHeader: FromZeros,
[u8]: FromZeros,
impl FromZeros for SpacePacketwhere
PrimaryHeader: FromZeros,
[u8]: FromZeros,
Source§impl IntoBytes for SpacePacket
impl IntoBytes for SpacePacket
§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
Source§impl KnownLayout for SpacePacketwhere
[u8]: KnownLayout,
impl KnownLayout for SpacePacketwhere
[u8]: KnownLayout,
Source§type PointerMetadata = <[u8] as KnownLayout>::PointerMetadata
type PointerMetadata = <[u8] as KnownLayout>::PointerMetadata
Self. Read more§fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
Self with the given pointer
metadata. Read moreSource§impl PartialEq for SpacePacketwhere
Self: IntoBytes + Immutable,
impl PartialEq for SpacePacketwhere
Self: IntoBytes + Immutable,
Source§impl<'a> TryFrom<&'a SpacePacket> for &'a Telecommand
impl<'a> TryFrom<&'a SpacePacket> for &'a Telecommand
Source§type Error = TelecommandError
type Error = TelecommandError
Source§impl<'a> TryFrom<&'a SpacePacket> for &'a Telemetry
impl<'a> TryFrom<&'a SpacePacket> for &'a Telemetry
Source§type Error = TelemetryError
type Error = TelemetryError
Source§impl TryFromBytes for SpacePacketwhere
PrimaryHeader: TryFromBytes,
[u8]: TryFromBytes,
impl TryFromBytes for SpacePacketwhere
PrimaryHeader: 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,
fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§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,
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,
§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,
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,
§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,
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,
§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,
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,
§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,
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,
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,
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,
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,
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,
§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,
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,
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,
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,
source as a &mut Self
with a DST length equal to count. Read more