Utility Module

class spacepackets.util.ByteFieldEmpty(val: int = 0)

Bases: UnsignedByteField

class spacepackets.util.ByteFieldGenerator

Bases: object

Static 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 UnsignedByteField from 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 UnsignedByteField from 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: UnsignedByteField

Concrete 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: UnsignedByteField

Concrete 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: UnsignedByteField

Concrete 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: UnsignedByteField

Concrete 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 signed_struct_specifier(byte_num: int) str
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]

static to_unsigned(byte_num: int, val: int) bytes

Convert number of bytes in a field to the struct API unsigned format specifier, assuming network endianness. Raises value error if number is not inside [1, 2, 4, 8]

static unsigned_struct_specifier(byte_num: int) str
class spacepackets.util.PrintFormats(value)

Bases: IntEnum

An enumeration.

BIN = 2
DEC = 1
HEX = 0
class spacepackets.util.UnsignedByteField(val: int, byte_len: int)

Bases: object

Generic 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'
property as_bytes: bytes
property byte_len: int
default_string(prefix: str) str
classmethod from_bytes(raw: bytes | bytearray) UnsignedByteField
property hex_str: str | None
property value: int
static verify_byte_len(byte_len: int) None
spacepackets.util.get_bin_data_string(data: bytes) str
spacepackets.util.get_dec_data_string(data: bytes) str
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