Utility Module
- class spacepackets.util.ByteFieldEmpty(val: int = 0)
Bases:
UnsignedByteField
- class spacepackets.util.ByteFieldGenerator
Bases:
objectStatic helpers to create the U8, U16 and U32 byte field variants of unsigned byte fields
- static from_bytes(byte_len: int, stream: bytes | bytearray) UnsignedByteField
Generate an
UnsignedByteFieldfrom a raw bytestream and a length.- Raises:
ValueError – Byte length is not one of [1, 2, 4, 8].
- static from_int(byte_len: int, val: int) UnsignedByteField
Generate an
UnsignedByteFieldfrom the byte length and a value.- Raises:
ValueError – Byte length is not one of [1, 2, 4, 8].
- class spacepackets.util.ByteFieldU16(val: int)
Bases:
UnsignedByteFieldConcrete variant of a variable length byte field which has a length of 2 bytes
- classmethod from_u16_bytes(stream: bytes | bytearray) ByteFieldU16
- class spacepackets.util.ByteFieldU32(val: int)
Bases:
UnsignedByteFieldConcrete variant of a variable length byte field which has a length of 4 bytes
- classmethod from_u32_bytes(stream: bytes | bytearray) ByteFieldU32
- class spacepackets.util.ByteFieldU64(val: int)
Bases:
UnsignedByteFieldConcrete variant of a variable length byte field which has a length of 8 bytes
- classmethod from_u64_bytes(stream: bytes | bytearray) ByteFieldU64
- class spacepackets.util.ByteFieldU8(val: int)
Bases:
UnsignedByteFieldConcrete variant of a variable length byte field which has a length of 1 byte
- classmethod from_u8_bytes(stream: bytes | bytearray) ByteFieldU8
- class spacepackets.util.IntByteConversion
Bases:
object- static to_signed(byte_num: int, val: int) bytes
Convert number of bytes in a field to the struct API signed format specifier, assuming network endianness. Raises value error if number is not inside [1, 2, 4, 8]
- class spacepackets.util.PrintFormats(value)
Bases:
IntEnumAn enumeration.
- BIN = 2
- DEC = 1
- HEX = 0
- class spacepackets.util.UnsignedByteField(val: int, byte_len: int)
Bases:
objectGeneric base class for byte fields containing unsigned values. These are a common component for packet protocols or packed identifier fields. Each unsigned byte field has an unsigned value and a corresponding byte length. This base class implements commonly required boilerplate code to easily work with fields like that and convert them to the byte and integer representation accordingly.
>>> field = UnsignedByteField(2, 1) >>> int(field) 2 >>> field.as_bytes.hex(sep=',') '02' >>> field = UnsignedByteField(42, 2) >>> int(field) 42 >>> field.as_bytes.hex(sep=',') '00,2a'
- classmethod from_bytes(raw: bytes | bytearray) UnsignedByteField
- spacepackets.util.get_printable_data_string(print_format: PrintFormats, data: bytes | bytearray) str
Returns the TM data in a clean printable hex string format :return: The string