pub struct SpacePacket { /* private fields */ }Expand description
Space packet
Space packets are implemented as dynamically-sized structs that contain the primary header as their first field, followed by the packet data as pure byte array. In this manner, deserialization can be reduced to a simple byte cast followed by interpretation of the primary header - without any data copies needed. This is useful for high-throughput applications, and ensures that no allocation or significant additional memory is needed to consume Space Packets.
This does also mean that Space Packets may only be handled by reference. In the context of this crate that helps enforce that no spurious copies can be made of the user data (which may be rather large and would incur additional allocations), albeit at the cost of some convenience.
Any means of constructing a SpacePacket in this crate shall perform a consistency check on
any received bytes. Hence, any SpacePacket object may be assumed to be a valid Space Packet.
Implementations§
Source§impl SpacePacket
impl SpacePacket
Sourcepub fn parse(bytes: &[u8]) -> Result<&Self, InvalidSpacePacket>
pub fn parse(bytes: &[u8]) -> Result<&Self, InvalidSpacePacket>
Attempts to parse a Space Packet from a given byte slice. If this fails, a reason is given for this failure. Shall never panic: rather, an error enum is returned explaining why the given octet string is not a valid Space Packet.
This deserialization is fully zero-copy. The &SpacePacket returned on success directly
references the input slice bytes, but is merely validated to be a valid Space Packet.
§Errors
Shall return an error if the provided bytes do not make up a valid space packet.
Sourcepub fn construct(
buffer: &mut [u8],
packet_type: PacketType,
secondary_header_flag: SecondaryHeaderFlag,
apid: Apid,
sequence_flag: SequenceFlag,
sequence_count: PacketSequenceCount,
) -> Result<&mut Self, InvalidPacketDataLength>
pub fn construct( buffer: &mut [u8], packet_type: PacketType, secondary_header_flag: SecondaryHeaderFlag, apid: Apid, sequence_flag: SequenceFlag, sequence_count: PacketSequenceCount, ) -> Result<&mut Self, InvalidPacketDataLength>
Assembles a Space Packet in-place on a given buffer. Computes the required packet data length from the passed buffer size. It is assumed that the caller has reserved the first six bytes of the buffer for the packet header. All other bytes are assumed to form the packet data field. Will compute the packet data field length based on the length of the provided buffer.
§Errors
Shall error if the provided buffer is not large enough to store the described space packet,
if it is exactly 6 bytes (which would result in a zero-length data field, which is not
permitted), or if the resulting length is larger than the maximum supported by the space
packet data field length representation (u16::MAX + 7 bytes).
Sourcepub const fn primary_header_size() -> usize
pub const fn primary_header_size() -> usize
Returns the size of a Space Packet primary header, in bytes. In the version that is presently implemented, that is always 6 bytes.
Sourcepub fn set_packet_data_length(
&mut self,
packet_data_length: usize,
) -> Result<(), InvalidPacketDataLength>
pub fn set_packet_data_length( &mut self, packet_data_length: usize, ) -> Result<(), InvalidPacketDataLength>
Sets the packet data length field to the provided value. Note that the given value is not stored directly, but rather decremented by one first. Accordingly, and as per the CCSDS Space Packet Protocol standard, packet data lengths of 0 are not allowed.
§Errors
Shall raise an error if the provided packet data length is zero, or if it is larger than the provided packet data buffer.
Sourcepub const fn packet_length(&self) -> usize
pub const fn packet_length(&self) -> usize
Returns the total length of the packet in bytes. Note the distinction from the packet data length, which refers only to the length of the data field of the packet.
Sourcepub const fn packet_data_field(&self) -> &[u8] ⓘ
pub const fn packet_data_field(&self) -> &[u8] ⓘ
Returns a reference to the packet data field contained in this Space Packet.
Sourcepub const fn packet_data_field_mut(&mut self) -> &mut [u8] ⓘ
pub const fn packet_data_field_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the packet data field contained in this Space Packet.
Methods from Deref<Target = SpacePacketPrimaryHeader>§
Sourcepub fn packet_version(&self) -> PacketVersionNumber
pub fn packet_version(&self) -> PacketVersionNumber
Since the Space Packet protocol may technically support alternative packet structures in future versions, the 3-bit packet version field may not actually contain a “correct” value.
Sourcepub fn initialize_packet_version(&mut self)
pub fn initialize_packet_version(&mut self)
Initializes the packet version to the proper value. Must be a fixed value, so this function takes no arguments.
Sourcepub fn packet_type(&self) -> PacketType
pub fn packet_type(&self) -> PacketType
The packet type denotes whether a packet is a telecommand (request) or telemetry (report) packet. Note that the exact definition of telecommand and telemetry may differ per system, and indeed the “correct” value here may differ per project.
Sourcepub fn set_packet_type(&mut self, packet_type: PacketType)
pub fn set_packet_type(&mut self, packet_type: PacketType)
Sets the packet type to the given value.
Sourcepub fn secondary_header_flag(&self) -> SecondaryHeaderFlag
pub fn secondary_header_flag(&self) -> SecondaryHeaderFlag
Denotes whether the packet contains a secondary header. If no user field is present, the secondary header is mandatory (presumably, to ensure that some data is always transferred, considering the Space Packet header itself contains no meaningful data).
Sourcepub fn set_secondary_header_flag(
&mut self,
secondary_header_flag: SecondaryHeaderFlag,
)
pub fn set_secondary_header_flag( &mut self, secondary_header_flag: SecondaryHeaderFlag, )
Updates the value of the secondary header flag with the provided value.
Sourcepub fn apid(&self) -> Apid
pub fn apid(&self) -> Apid
Returns the application process ID stored in the packet. The actual meaning of this APID field may differ per implementation: technically, it only represents “some” data path. In practice, it will often be a identifier for a data channel, the packet source, or the packet destination.
Sourcepub fn set_apid(&mut self, apid: Apid)
pub fn set_apid(&mut self, apid: Apid)
Sets the APID used to route the packet to the given value.
Sourcepub fn sequence_flag(&self) -> SequenceFlag
pub fn sequence_flag(&self) -> SequenceFlag
Sequence flags may be used to indicate that the data contained in a packet is only part of a larger set of application data.
Sourcepub fn set_sequence_flag(&mut self, sequence_flag: SequenceFlag)
pub fn set_sequence_flag(&mut self, sequence_flag: SequenceFlag)
Sets the sequence flag to the provided value.
Sourcepub fn packet_sequence_count(&self) -> PacketSequenceCount
pub fn packet_sequence_count(&self) -> PacketSequenceCount
The packet sequence count is unique per APID and denotes the sequential binary count of each Space Packet (generated per APID). For telecommands (i.e., with packet type 1) this may also be a “packet name” that identifies the telecommand packet within its communications session.
Sourcepub fn set_packet_sequence_count(&mut self, sequence_count: PacketSequenceCount)
pub fn set_packet_sequence_count(&mut self, sequence_count: PacketSequenceCount)
Sets the packet sequence count to the provided value. This value must be provided by an external counter and is not provided at a Space Packet type level because it might differ between packet streams.
Sourcepub fn packet_data_length(&self) -> usize
pub fn packet_data_length(&self) -> usize
The packet data length field represents the length of the associated packet data field. However, it is not stored directly: rather, the “length count” is stored, which is the packet data length minus one.
Sourcepub fn set_packet_data_length(
&mut self,
packet_data_length: usize,
) -> Result<(), InvalidPacketDataLength>
pub fn set_packet_data_length( &mut self, packet_data_length: usize, ) -> Result<(), InvalidPacketDataLength>
Sets the packet data length field to the provided value. Note that the given value is not stored directly, but rather decremented by one first. Accordingly, and as per the CCSDS Space Packet Protocol standard, packet data lengths of 0 are not allowed.
§Errors
Shall return an error if an empty packet data length is requested.
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 SpacePacket
impl FromBytes for SpacePacket
Source§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,
Source§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,
Source§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 moreSource§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,
Source§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,
Source§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,
Source§fn ref_from_bytes_with_elems(
source: &[u8],
count: usize,
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
fn ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
Source§fn ref_from_prefix_with_elems(
source: &[u8],
count: usize,
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
fn ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
Source§fn ref_from_suffix_with_elems(
source: &[u8],
count: usize,
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
fn ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
Source§fn mut_from_bytes_with_elems(
source: &mut [u8],
count: usize,
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
fn mut_from_bytes_with_elems( source: &mut [u8], count: usize, ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
Source§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>>
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>>
Source§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>>
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>>
Source§impl FromZeros for SpacePacket
impl FromZeros for SpacePacket
Source§impl Hash for SpacePacket
impl Hash for SpacePacket
Source§impl IntoBytes for SpacePacket
impl IntoBytes for SpacePacket
Source§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
Source§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 moreSource§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 SpacePacket
impl PartialEq for SpacePacket
Source§impl TryFromBytes for SpacePacket
impl TryFromBytes for SpacePacket
Source§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,
Source§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,
Source§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,
Source§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,
Source§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,
Source§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,
Source§fn try_ref_from_bytes_with_elems(
source: &[u8],
count: usize,
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
Source§fn try_ref_from_prefix_with_elems(
source: &[u8],
count: usize,
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
source as a &Self with
a DST length equal to count. Read moreSource§fn try_ref_from_suffix_with_elems(
source: &[u8],
count: usize,
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
source as a &Self with
a DST length equal to count. Read moreSource§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>>>
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>>>
Source§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>>>
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>>>
source as a &mut Self
with a DST length equal to count. Read moreSource§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>>>
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>>>
source as a &mut Self
with a DST length equal to count. Read more