ltcodecs#

ltcodecs.bool_codec module#

ltcodecs.bytes_codec module#

ltcodecs.bytes_codec#

This module contains the BytesCodec class, which is used to encode and decode bytes.

class ltcodecs.bytes_codec.BytesCodec(max_length: int, fail_on_overflow=False, **kwargs)#

Bases: FieldCodec

codec for bytes

decode(bits_to_decode: ConstBitStream) bytes#

decode bytes

Parameters:

bits_to_decode – the bits to decode

encode(value: bytes) tuple[Bits, bytes]#

encode bytes

Parameters:

value – the bytes to encode

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.ccl_latlon_bcd_codec module#

ltcodecs.ccl_latlon_codec module#

ltcodecs.exceptions module#

ltcodecs.exceptions#

This module contains custom exceptions for ltcodecs

exception ltcodecs.exceptions.EncodingFailed(message: str = 'Encoding failed')#

Bases: Exception

Raised when encoding fails

ltcodecs.exponentialgolomb_integer_codec module#

ltcodecs.exponentialgolomb_integer_codec#

This module contains the ExponentialGolombIntegerCodec class, which uses Exponential-Golomb coding to encode and decode integers.

class ltcodecs.exponentialgolomb_integer_codec.ExponentialGolombIntegerCodec(min_value: int, max_value: int, resolution: int = 1, base_value: int | None = None, **kwargs)#

Bases: FieldCodec

An encoder and decoder using Exponential-Golomb coding for integer values.

This codec operates based on Exponential-Golomb encoding, allowing efficient representation of integer values within a defined range using a variable-length encoding scheme. The encoding behavior (signed or unsigned, reversed or not) depends on the relationship between min_value, max_value, and base_value.

Exponential-Golomb encoding is suited to encoding values that are more likely to be near the base value. It encodes values near the base value more efficiently at the cost of less-efficient encoding of values further from the base value.

Variables:
  • min_value – Minimum value of the range supported by the codec. Used to constrain input.

  • max_value – Maximum value of the range supported by the codec. Used to constrain input.

  • resolution – Step size or granularity for encoding and decoding values. Defines the smallest possible difference between encoded values.

  • base_value – Reference value used to calculate offsets for encoding. Determines the codec’s operational mode (e.g., signed/unsigned, reversed/non-reversed). Defaults to min_value if not specified during initialization.

decode(bits_to_decode: ConstBitStream) int#

Decodes a given bitstream into an integer value based on the configuration of the decoder.

Parameters:

bits_to_decode (ConstBitStream) – A bitstream containing the encoded value to be decoded. Data is read in either signed or unsigned representation depending on the decoder configuration.

Returns:

The decoded integer value computed after applying the transformations and adjustments based on the decoder’s configuration.

Return type:

int

encode(value: int) tuple[Bits, int]#

Encodes the given integer value into a tuple consisting of an encoded representation and the compressed integer value. The value is clamped within the predefined range determined by min_value and max_value.

Parameters:

value – The integer value to be encoded. This value is adjusted within the limits of min_value and max_value and then processed to generate its encoded counterpart.

Returns:

A tuple containing the encoded representation (Bits object) and the encoded integer value

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.field_codec module#

abstract base class for field codecs

class ltcodecs.field_codec.FieldCodec(**kwargs)#

Bases: ABC

abstract base class for field codecs

abstract decode(bits_to_decode: ConstBitStream) Any#

decodes value

Parameters:

bits_to_decode – ConstBitStream to decode

abstract encode(value: Any) tuple[Bits, Any]#

encodes value

Parameters:

value – value to encode

abstract property max_length_bits: int#
abstract property min_length_bits: int#

ltcodecs.fixed_len_array_codec module#

ltcodecs.fixed_len_array_codec#

This module contains the FixedLenArrayCodec class, which is used to encode and decode fixed length arrays.

class ltcodecs.fixed_len_array_codec.FixedLenArrayCodec(element_type: str, length: int, element_params=None, **kwargs)#

Bases: FieldCodec

codec for fixed length arrays

decode(bits_to_decode: ConstBitStream) List#

decode a fixed length array

Parameters:

bits_to_decode – the bits to decode

encode(value: List) tuple[Bits, List]#

encode a fixed length array

Parameters:

value – the fixed length array to encode

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.fixedint_codec module#

ltcodecs.fixedint_codec#

This module contains classes for fixed width integer codecs

class ltcodecs.fixedint_codec.FixedIntCodec(num_bits: int, signed: bool = False, min_value: int | None = None, resolution: int = 1, little_endian: bool = False, **kwargs)#

Bases: VarintCodec

FixedIntCodec base class

class ltcodecs.fixedint_codec.Int16Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for int16 codec

class ltcodecs.fixedint_codec.Int32Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for int32 codec

class ltcodecs.fixedint_codec.Int64Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for int64 codec

class ltcodecs.fixedint_codec.Int8Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for int8 codec

class ltcodecs.fixedint_codec.UInt16Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for uint16 codec

class ltcodecs.fixedint_codec.UInt32Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for uint32 codec

class ltcodecs.fixedint_codec.UInt64Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for uint64 codec

class ltcodecs.fixedint_codec.UInt8Codec(**kwargs)#

Bases: FixedIntCodec

metaclass for uint8 codec

ltcodecs.float_codec module#

ltcodecs.float_codec#

This module contains the the float codec

class ltcodecs.float_codec.FloatCodec(min_value: float, max_value: float, precision: int, **kwargs)#

Bases: FieldCodec

codec for floating point numbers

decode(bits_to_decode: ConstBitStream) float#

decode a float

Parameters:

bits_to_decode – the bitstream to decode

encode(value: float) tuple[Bits, float]#

encode a float

Parameters:

value – the value to encode

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.ieee_float_codec module#

ltcodecs.ieee_float_codec#

ieee_float_codec encodes and decodes IEEE floating point numbers

class ltcodecs.ieee_float_codec.IeeeFloat32Codec(**kwargs)#

Bases: IeeeFloatCodec

metaclass for IEEE 32 bit floating point numbers

class ltcodecs.ieee_float_codec.IeeeFloat64Codec(**kwargs)#

Bases: IeeeFloatCodec

metaclass for IEEE 64 bit floating point numbers

class ltcodecs.ieee_float_codec.IeeeFloatCodec(num_bits=32, **kwargs)#

Bases: FieldCodec

codec for IEEE floating point numbers

decode(bits_to_decode: ConstBitStream)#

decode value

Parameters:

bits_to_decode – the bitstream to decode

encode(value: float) tuple[Bits, float]#

encode value

Parameters:

value – the value to encode

property max_length_bits#
property min_length_bits#

ltcodecs.linspace_float_codec module#

ltcodecs.linspace_float_codec#

This module contains the the linspace float codec

class ltcodecs.linspace_float_codec.LinspaceFloatCodec(min_value: float, max_value: float, resolution: float | None = None, num_values: int | None = None, num_bits: int | None = None, **kwargs)#

Bases: FieldCodec

decode(bits_to_decode: ConstBitStream) float#

decode bits_to_decode into a value

encode(value: float) tuple[Bits, float]#

encode value

Parameters:

value – the value to encode

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.lzma_codec module#

ltcodecs.optional_field_codec module#

ltcodecs.padding_codec module#

ltcodecs.ros_message_codec module#

ltcodecs.ros_msg_field_codec module#

ltcodecs.rostime_codec module#

ltcodecs.string_codecs module#

ltcodecs.string_codecs#

This module contains codecs for encoding and decoding strings.

class ltcodecs.string_codecs.AsciiStringCodec(max_length: int = 128, bits_per_char: int = 7, tail=False, **kwargs)#

Bases: FieldCodec

codec for encoding and decoding ascii strings

decode(encoded_bits: ConstBitStream) str#

decode a string from a bitstream

Parameters:

encoded_bits – the bitstream to decode

encode(value: str) tuple[Bits, str]#

encode a string into a bitstream

Parameters:

value – the string to encode

property max_length_bits: int#
property min_length_bits: int#
ltcodecs.string_codecs.from_sixbit_ascii(sixbit_code: int) str#

return the ascii character corresponding to the sixbit code

Parameters:

sixbit_code – the sixbit code to convert

ltcodecs.string_codecs.to_sixbit_ascii(character: str) int#

return the sixbit code corresponding to the ascii character

Parameters:

character – the character to convert

ltcodecs.string_enum_codec module#

ltcodecs.string_enum_codec#

This module contains the StringEnumCodec class, which is used to encode and decode string enums.

class ltcodecs.string_enum_codec.StringEnumCodec(entries: List[str], unknown_value: str | None = None, case_sensitive: bool = False, strip: bool = False, **kwargs)#

Bases: FieldCodec

codec for string enums

decode(encoded_bits: ConstBitStream) str#

decode a string enum from a bitstream

Parameters:

encoded_bits – the bitstream to decode

encode(value: str) tuple[ConstBitStream, str]#

encode a string enum

Parameters:

value – the string to encode

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.variable_len_array_codec module#

variable_len_array_codec.py#

module for VariableLenArrayCodec

class ltcodecs.variable_len_array_codec.VariableLenArrayCodec(element_type: str, max_length: int, element_params=None, nullable=False, **kwargs)#

Bases: FieldCodec

codec for variable-length array

Parameters:
  • element_type – codec to use to encode each element of the array

  • max_length – maximum number of elements to encode

  • element_params – Codec parameters dictionary to use for the element codec

  • nullable – If this is True, use a bit to indicate if the array is empty. This allows encoding an empty array with a single bit.

decode(bits_to_decode: ConstBitStream) list#

decodes list of elements from bits

encode(value: list) tuple[BitArray, list[Any]]#

encodes list of elements

property max_length_bits: int#
property min_length_bits: int#

ltcodecs.varint_codec module#

ltcodecs.varint_codec#

This module contains the VarintCodec class, which is used to encode and decode variable-length integers.

class ltcodecs.varint_codec.VarintCodec(min_value: int, max_value: int, resolution: int = 1, little_endian: bool = False, **kwargs)#

Bases: FieldCodec

codec for variable-length integers

decode(bits_to_decode: ConstBitStream) int#

decodes encoded varint

Parameters:

bits_to_decode – ConstBitStream to decode

encode(value: int) tuple[Bits, int]#

turns int into variable-length int

Parameters:

value – int to encode

property max_length_bits: int#
property min_length_bits: int#