Space Packet
Simple and generic Rust implementation of the Consultative Committee for Space Data Systems (CCSDS) Space Packet Protocol, as defined in CCSDS 133.0-B-2.
Written to be fully no_std and without unsafe blocks: this makes it suitable for usage in high-assurance embedded environments.
The Kani model checker is used to formally prove the absence of certain classes of errors: parsing of byte sequences and creation of Space Packets shall succeed for all possible inputs without panicking. Violation of preconditions shall be handled gracefully by returning an error.
Usage
Reading Space Packets from some given byte buffer may be done as follows:
use *;
// Constructs a simple packet with pre-determined values.
let bytes = &;
// Parses the given byte buffer into a fully type-safe wrapper struct. No copies are made, the
// returned struct is a direct, type-safe view into the byte buffer.
let packet = parse.unwrap;
// Check that the packet contains the expected values.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Note the use of accessor functions to conveniently read off the Space Packet primary header fields. Rather than raw bytes, typed wrappers are returned to represent the stored header data.
Vice versa, Space Packets may be constructed directly on a pre-allocated byte buffer.
use *;
// A pre-allocated buffer must be used.
let buffer = &mut ;
// Construction happens in-place on this buffer: a `SpacePacket` is returned, or an appropriate
// error to indicate construction failure.
let packet = construct.unwrap;
// Initializes the packet data field with some arbitrary values.
for in packet.packet_data_field_mut.iter_mut.enumerate
// The returned packet may be queried for its header fields.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
This crate strictly follows the CCSDS Space Packet Protocol standard: not all byte sequences are valid Space Packets. In such cases, an appropriate error is returned to the caller, such that they can determine the appropriate course of action. This applies both to parsing and construction of Space Packets: once a SpacePacket is obtained, it must be a semantically valid Space Packet. Examples of failure cases:
use *;
// This Space Packet stores a packet data length of 8 bytes, which cannot actually be contained in
// this byte buffer. Either the packet is incomplete, or it is erroneous.
let bytes = &;
// Returns an error indicating that the given byte slice contains only a partial packet.
let result = parse;
assert_eq!;
// This Space Packet is an idle packet; such packets may not contain a secondary header field.
let bytes = &;
// Returns an error indicating that the given byte slice contains only a partial packet.
let result = parse;
assert_eq!;