Python API#
This page is generated from module docstrings and public class members. For a configuration-oriented view, see Codec Reference and Configuration Schema.
ltcodecs.bool_codec module#
ltcodecs.bool_codec#
This module contains the BoolCodec class, which is used to encode and decode bools.
- class ltcodecs.bool_codec.BoolCodec(**kwargs)#
Bases:
FieldCodeccodec for bools
- decode(bits_to_decode: ConstBitStream) bool#
decode a bool
- Parameters:
bits_to_decode – the bits to decode
- encode(value: bool) tuple[Bits, bool]#
encode a bool
- Parameters:
value – the bool to encode
- property max_length_bits: int#
- property min_length_bits: int#
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:
FieldCodeccodec 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_bcd_codec#
This module contains the the ccl latlon bcd codec
- class ltcodecs.ccl_latlon_bcd_codec.CclLatLonBcdCodec(lat_not_lon=True, **kwargs)#
Bases:
FieldCodecThis codec is horrifically inefficient, but included for compatibility with messages like MDAT_RANGER
- decode(bits_to_decode: ConstBitStream) float#
decodes value
- Parameters:
bits_to_decode – ConstBitStream to decode
- encode(value: float) tuple[Bits, float]#
encodes value
- Parameters:
value – value to encode
- property max_length_bits: int#
- property min_length_bits: int#
ltcodecs.ccl_latlon_codec module#
ltcodecs.ccl_latlon_codec#
ccl_latlon_codec encodes and decodes CCL latitude and longitude values
- class ltcodecs.ccl_latlon_codec.CclLatLonCodec(**kwargs)#
Bases:
FieldCodeccodec for CCL latitude and longitude values
- decode(bits_to_decode: ConstBitStream) float#
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: int#
- property min_length_bits: int#
ltcodecs.dict_codec module#
ltcodecs.dict_codec#
This module contains the top-level dictionary codec.
- class ltcodecs.dict_codec.DictCodec(fields_dict: dict = None, checksum=None)#
Bases:
objectTop-level codec for Python dictionaries.
DictCodecis the simplest entry point for usingltcodecswithout ROS. It encodes a dictionary according to a field configuration and decodes the resulting bit stream back into a dictionary with the configured field names.- Parameters:
fields_dict – Field configuration mapping. Each key is a field name and each value is a codec parameter dictionary containing at least a
codecalias.checksum – Optional checksum appended after the payload. Supported values are
"crc8"and"crc32".
- decode(bits_to_decode: ConstBitStream, received_packet=None) dict#
Decode a dictionary from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the start of this encoded dictionary.
received_packet – Optional metadata packet or dictionary used by metadata decoder fields.
- Returns:
Decoded dictionary.
- Raises:
ValueError – If checksum verification is enabled and the received checksum does not match the decoded payload.
- encode(message_dict: dict) tuple[Bits, dict | None]#
Encode a dictionary into bits and optional metadata.
- Parameters:
message_dict – Dictionary containing values for the configured fields.
- Returns:
Tuple of
(bits, metadata).bitscontains the encoded payload and optional checksum.metadatais usuallyNone; it is a dictionary when the field config contains metadata encoder aliases such asdest.- Raises:
EncodingFailed – If one of the configured fields cannot be encoded.
- classmethod from_codec_file(codec_file_path: str, codec_include_directory: str = None, checksum=None) DictCodec#
Create a dictionary codec from a YAML field configuration file.
- Parameters:
codec_file_path – Path to the YAML codec configuration.
codec_include_directory – Optional base directory used by
rospy_yaml_includefor YAML includes.checksum – Optional checksum appended after the payload.
- classmethod from_yaml(codec_yaml: str, codec_include_directory: str = None, checksum=None) DictCodec#
Create a dictionary codec from YAML text.
- Parameters:
codec_yaml – YAML field configuration text.
codec_include_directory – Optional base directory used by
rospy_yaml_includefor YAML includes.checksum – Optional checksum appended after the payload.
- property max_length_bits: int#
Maximum encoded dictionary length, including checksum bits.
- property min_length_bits: int#
Minimum encoded dictionary length, including checksum bits.
ltcodecs.dict_field_codec module#
ltcodecs.dict_field_codec#
This module contains the field codec used for nested dictionaries.
- class ltcodecs.dict_field_codec.DictFieldCodec(fields: dict = None, **kwargs)#
Bases:
FieldCodecField codec for Python dictionaries.
This codec is used internally by
ltcodecs.DictCodecand as the implementation for thedict/dictionaryfield aliases. It encodes fields in configuration order and decodes them in the same order.- decode(bits_to_decode: ConstBitStream, metadata=None) dict#
Decode a dictionary field from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the start of this encoded dictionary field.
metadata – Optional packet metadata used by metadata decoder fields.
- Returns:
Decoded dictionary.
- decode_as_dict(bits_to_decode: ConstBitStream) Dict[Any, Any]#
Decode the given bits as a dictionary.
This is used by top-level codecs to calculate checksums without constructing a ROS message object.
- Parameters:
bits_to_decode – Bit stream positioned at the start of this encoded dictionary field.
- Returns:
Decoded dictionary.
- encode(message: dict, metadata=None) tuple[BitArray, dict]#
Encode a dictionary field.
- Parameters:
message – Dictionary containing values for the configured fields.
metadata – Optional packet metadata. This argument is accepted for compatibility with other field codecs.
- Returns:
Tuple of
(bits, encoded_values).encoded_valuescontains the values after any field-level compression or quantization.- Raises:
EncodingFailed – If a configured field cannot be encoded.
- property max_length_bits: int#
Maximum encoded dictionary field length.
- property min_length_bits: int#
Minimum encoded dictionary field length.
ltcodecs.exceptions module#
ltcodecs.exceptions#
This module contains custom exceptions for ltcodecs
- exception ltcodecs.exceptions.EncodingFailed(message: str = 'Encoding failed')#
Bases:
ExceptionRaised 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:
FieldCodecAn 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:
ABCabstract base class for field codecs
- abstractmethod decode(bits_to_decode: ConstBitStream) Any#
decodes value
- Parameters:
bits_to_decode – ConstBitStream to decode
- abstractmethod 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:
FieldCodecCodec for fixed-length arrays.
The encoded stream contains only the element values. The array length is defined by configuration and is not encoded in the payload.
- Parameters:
element_type – Codec alias used to encode each element.
length – Number of elements the decoder will read.
element_params – Optional parameter dictionary passed to the element codec constructor.
- decode(bits_to_decode: ConstBitStream) List#
Decode a fixed-length array.
The decoder always reads
lengthelements.
- encode(value: List) tuple[Bits, List]#
Encode a fixed-length array.
Values longer than
lengthare truncated during encoding.
- 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, resolution: int = 1, little_endian: bool = False, **kwargs)#
Bases:
VarintCodecCodec for fixed-width integer values.
- Parameters:
num_bits – Number of bits used to encode the value.
signed – If true, default range is centered around zero. If false, default minimum is zero.
min_value – Optional explicit minimum value. When omitted, the minimum is derived from
signed,num_bits, andresolution.resolution – Spacing between representable values.
little_endian – If true, encode using little-endian bit order.
- class ltcodecs.fixedint_codec.Int16Codec(**kwargs)#
Bases:
FixedIntCodecSigned 16-bit integer codec.
- class ltcodecs.fixedint_codec.Int32Codec(**kwargs)#
Bases:
FixedIntCodecSigned 32-bit integer codec.
- class ltcodecs.fixedint_codec.Int64Codec(**kwargs)#
Bases:
FixedIntCodecSigned 64-bit integer codec.
- class ltcodecs.fixedint_codec.Int8Codec(**kwargs)#
Bases:
FixedIntCodecSigned 8-bit integer codec.
- class ltcodecs.fixedint_codec.UInt16Codec(**kwargs)#
Bases:
FixedIntCodecUnsigned 16-bit integer codec.
- class ltcodecs.fixedint_codec.UInt32Codec(**kwargs)#
Bases:
FixedIntCodecUnsigned 32-bit integer codec.
- class ltcodecs.fixedint_codec.UInt64Codec(**kwargs)#
Bases:
FixedIntCodecUnsigned 64-bit integer codec.
- class ltcodecs.fixedint_codec.UInt8Codec(**kwargs)#
Bases:
FixedIntCodecUnsigned 8-bit integer 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:
FieldCodecCodec for bounded decimal floating-point values.
Values are clipped to
min_value/max_valueand quantized using decimalprecision. For example,precision=2preserves two decimal places.- Parameters:
min_value – Minimum representable value.
max_value – Maximum representable value.
precision – Number of decimal places to preserve.
- decode(bits_to_decode: ConstBitStream) float#
Decode a floating-point value from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the encoded value.
- encode(value: float) tuple[Bits, float]#
Encode a floating-point value.
- Returns:
Tuple of
(bits, encoded_value).encoded_valueis the clipped and rounded value represented by the bits.
- property max_length_bits: int#
Encoded float length in bits.
- property min_length_bits: int#
Encoded float length in bits.
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:
IeeeFloatCodecIEEE 32-bit floating-point codec.
- class ltcodecs.ieee_float_codec.IeeeFloat64Codec(**kwargs)#
Bases:
IeeeFloatCodecIEEE 64-bit floating-point codec.
- class ltcodecs.ieee_float_codec.IeeeFloatCodec(num_bits=32, **kwargs)#
Bases:
FieldCodecCodec for IEEE floating-point values.
- Parameters:
num_bits – IEEE float width. Supported values are
32and64.
- decode(bits_to_decode: ConstBitStream)#
Decode a floating-point value from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the encoded value.
- encode(value: float) tuple[Bits, float]#
Encode a floating-point value.
- Returns:
Tuple of
(bits, encoded_value).encoded_valueis the value represented by the selected IEEE format.
- property max_length_bits#
Encoded float length in bits.
- property min_length_bits#
Encoded float length in 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, num_values: int = None, num_bits: int = None, **kwargs)#
Bases:
FieldCodecCodec for linearly spaced floating-point values.
Configure exactly one of
resolution,num_values, ornum_bits. Values are clipped to the configured range and quantized to the nearest lower representable value.- Parameters:
min_value – Minimum representable value.
max_value – Maximum representable value.
resolution – Spacing between representable values.
num_values – Number of representable values across the range.
num_bits – Number of bits used to encode the value.
- decode(bits_to_decode: ConstBitStream) float#
Decode a floating-point value from a bit stream.
- encode(value: float) tuple[Bits, float]#
Encode a floating-point value.
- Returns:
Tuple of
(bits, encoded_value).encoded_valueis the clipped and quantized value represented by the bits.
- property max_length_bits: int#
Encoded float length in bits.
- property min_length_bits: int#
Encoded float length in bits.
ltcodecs.lzma_codec module#
ltcodecs.LzmaCodec#
This module contains the LzmaCodec class, which is used to encode and decode bytes using LZMA.
- class ltcodecs.lzma_codec.LzmaCodec(max_length: int, **kwargs)#
Bases:
FieldCodecLZMA codec for bytes
- decode(bits_to_decode: ConstBitStream) bytes#
decode a bool
- 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.optional_field_codec module#
ltcodecs.optional_field_codec#
This module contains the OptionalCodec class, which uses a boolean field to control whether a set of target fields is encoded in the message (making those fields optional).
- class ltcodecs.optional_field_codec.OptionalFieldCodec(target_fields: dict = None, **kwargs: object)#
Bases:
MultipleFieldCodecCodec for optional fields.
The field using this codec is a boolean controller. If the controller is true, each field in
target_fieldsis encoded immediately after the controller bit. If false, only the controller bit is encoded and the target fields use no payload bits.- Parameters:
target_fields – Mapping of optional target field names to codec parameter dictionaries, in the same shape used by
DictCodecandRosMessageCodecfield configs.
- decode_multiple(bits_to_decode: ConstBitStream) tuple[bool, dict]#
Decode the controller boolean and any present target fields.
- Parameters:
bits_to_decode – Bit stream positioned at the controller bit.
- Returns:
Tuple of
(controller_value, decoded_target_values).
- encode_multiple(value: bool, message_dict: dict) tuple[Bits, bool, dict]#
Encode the controller boolean and any present target fields.
- Parameters:
value – Controller value indicating whether target fields are present.
message_dict – Full message dictionary used to read target field values.
- Returns:
Tuple of
(bits, controller_value, encoded_target_values).
- property max_length_bits: int#
- property min_length_bits: int#
ltcodecs.padding_codec module#
ltcodecs.padding_codec#
padding_codec encodes and decodes padding
- class ltcodecs.padding_codec.PaddingCodec(num_bits, **kwargs)#
Bases:
FieldCodecCodec for fixed zero padding.
Padding reserves a configured number of bits in the payload. Encoding always writes zeros and decoding returns
None.- Parameters:
num_bits – Number of padding bits.
- decode(bits_to_decode: ConstBitStream) None#
Decode and discard padding bits.
- Returns:
None.
- encode(value=None) tuple[BitArray, None]#
Encode padding bits.
The input value is ignored.
- max_length_bits() int#
- min_length_bits() int#
ltcodecs.ros_message_codec module#
ltcodecs.ros_message_codec#
This module contains the top-level ROS message codec.
- class ltcodecs.ros_message_codec.RosMessageCodec(ros_type: None | str, fields_dict: dict = None, checksum=None)#
Bases:
objectTop-level codec for ROS messages.
RosMessageCodecencodes a ROS message object into abitstringbit stream and decodes that stream back into a new ROS message object. Field codecs can be inferred from the ROS message definition, or supplied explicitly withfields_dictorfrom_codec_file().- Parameters:
ros_type – ROS message type to encode. This may be a message class or a type string such as
"std_msgs/String".fields_dict – Optional field configuration mapping. When omitted, fields are inferred from the ROS message definition through ARMW.
checksum – Optional checksum appended after the payload. Supported values are
"crc8"and"crc32".
- decode(bits_to_decode: ConstBitStream, received_packet=None) armw.AnyMsg#
Decode a ROS message from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the start of this encoded ROS message.
received_packet – Optional packet metadata used by metadata decoder fields.
- Returns:
A new ROS message object of
ros_type.- Raises:
ValueError – If checksum verification is enabled and the received checksum does not match the decoded payload.
- encode(ros_msg: armw.AnyMsg) tuple[Bits, dict[Any]]#
Encode a ROS message into bits and optional metadata.
- Parameters:
ros_msg – ROS message instance to encode.
- Returns:
Tuple of
(bits, metadata).bitscontains the encoded payload and optional checksum.metadatais usuallyNone; it is a dictionary when the field config contains metadata encoder aliases such asdest.- Raises:
EncodingFailed – If one of the configured fields cannot be encoded.
- classmethod from_codec_file(ros_type: type | str, msg_codec_file_path: str, codec_include_directory: str = None) ROSMessageCodec#
Create a ROS message codec from a YAML field configuration file.
- Parameters:
ros_type – ROS message class or type string.
msg_codec_file_path – Path to the YAML codec configuration.
codec_include_directory – Optional base directory used by
rospy_yaml_includefor YAML includes.
- property max_length_bits: int#
Maximum encoded message length, including checksum bits.
- property min_length_bits: int#
Minimum encoded message length, including checksum bits.
ltcodecs.ros_msg_field_codec module#
ltcodecs.ros_msg_codec#
This module contains the field codec used for nested ROS messages.
- class ltcodecs.ros_msg_field_codec.RosMsgFieldCodec(ros_type: str | None, fields: dict = None, **kwargs)#
Bases:
FieldCodecField codec for ROS messages.
This codec is used internally by
ltcodecs.RosMessageCodecand as the implementation for themsg/ros_msgfield aliases. It can infer field codecs from a ROS message definition through ARMW, or it can use an explicit field configuration.- decode(bits_to_decode: ConstBitStream, metadata=None) None#
Decode a ROS message field from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the start of this encoded message field.
metadata – Optional packet metadata used by metadata decoder fields.
- Returns:
A new ROS message object built from the decoded fields.
- decode_as_dict(bits_to_decode: ConstBitStream) Dict[Any, Any]#
Decode the given bits as a dictionary (rather than a ROS message).
This function is primarily used to generate an object that we can use for calculating CRCs in the message codec. It seems like a bit of a hack, but the alternative would require adding a second return value to every field decoder. Since this only affects ROS messages, this keeps the bloat down.
- Parameters:
bits_to_decode – The bit stream to be decoded.
- Returns:
The decoded message as a dictionary.
- encode(message: None, metadata=None) tuple[BitArray, dict[Any]]#
Encode a ROS message field.
- Parameters:
message – ROS message instance to encode.
metadata – Optional packet metadata. This argument is accepted for compatibility with other field codecs.
- Returns:
Tuple of
(bits, encoded_values).encoded_valuescontains the values after any field-level compression or quantization.- Raises:
EncodingFailed – If a configured field cannot be encoded.
- property max_length_bits: int#
- property min_length_bits: int#
- ltcodecs.ros_msg_field_codec.normalize_field_params(field_params: dict) dict#
Normalize explicit field config that may contain ROS 2 type strings.
This allows a config that says
codec: msgwithros_type: sequence<pkg/msg/Msg>to become the equivalentvariable_len_arrayconfig before field codec construction.
- ltcodecs.ros_msg_field_codec.normalize_ros_msg_type(ros_type: str) str#
Normalize ROS 2 message type names to the package/message form ARMW expects.
pkg/msg/Msgis converted topkg/Msg. Other strings are returned unchanged.
- ltcodecs.ros_msg_field_codec.ros_type_to_field_params(msg_type: str, default_array_max_length: int = 10) dict#
Convert a ROS field type string to ltcodecs field parameters.
Supported forms include ROS 1 names such as
pkg/Msg[]andpkg/Msg[3]and ROS 2 introspection names such assequence<pkg/msg/Msg>andarray<pkg/msg/Msg, 3>.- Parameters:
msg_type – ROS field type string to convert.
default_array_max_length – Maximum array length used for unbounded variable-length arrays.
ltcodecs.rostime_codec module#
ltcodecs.ros_time_codec#
This module contains the RosTimeCodec class, which is used to encode and decode ROS times.
- class ltcodecs.rostime_codec.RosTimeCodec(precision: int = 0, epoch_start=1622520000, epoch_end=2147483647, ros_type: str | None = None, **kwargs)#
Bases:
FieldCodeccodec for encoding and decoding ROS times
- decode(bits_to_decode: ConstBitStream) Time#
decode rostime
- Parameters:
bits_to_decode – the bitstream to decode
- encode(value: Time) tuple[Bits, Time]#
encode rostime
- Parameters:
value – rostime to encode
- property max_length_bits: int#
- property min_length_bits: int#
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:
FieldCodecCodec for ASCII strings.
The encoded stream contains a length prefix followed by each character.
bits_per_charcontrols the character packing. Seven-bit mode stores standard ASCII. Six-bit mode stores a reduced uppercase-oriented alphabet and replaces unsupported characters with?.- Parameters:
max_length – Maximum number of characters to encode. Longer strings are truncated.
bits_per_char – Number of bits used per character. Common values are
7and6.tail – If false, keep the first
max_lengthcharacters when truncating. If true, keep the lastmax_lengthcharacters.
- decode(encoded_bits: ConstBitStream) str#
Decode a string from a bit stream.
- Parameters:
encoded_bits – Bit stream positioned at the encoded string.
- encode(value: str) tuple[Bits, str]#
Encode a string into a bit stream.
- Returns:
Tuple of
(bits, encoded_string).encoded_stringis the possibly truncated or character-set-reduced value represented by the encoded bits.
- 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:
FieldCodeccodec 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:
FieldCodecCodec for variable-length arrays.
The encoded stream contains the number of elements followed by each encoded element. Elements are encoded by another field codec selected by
element_type.- Parameters:
element_type – Codec alias used to encode each element, such as
"uint8","string","dict", or"msg".max_length – Maximum number of elements to encode. Longer lists are truncated to this length.
element_params – Optional parameter dictionary passed to the element codec constructor.
nullable – If true, encode an initial presence bit. Empty lists then encode as a single false bit; non-empty lists encode as true, then length, then elements.
- decode(bits_to_decode: ConstBitStream) list#
Decode a list of elements from a bit stream.
- encode(value: list) tuple[BitArray, list[Any]]#
Encode a list of elements.
- Returns:
Tuple of
(bits, encoded_values).encoded_valuescontains the element values after any element-level compression or quantization.
- 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:
FieldCodecCodec for bounded integer values.
Despite the name, this codec uses a fixed number of bits derived from
min_value,max_value, andresolution. Values are clipped to the configured range and quantized to the nearest lower resolution step.- Parameters:
min_value – Minimum representable value.
max_value – Maximum representable value.
resolution – Spacing between representable values.
little_endian – If true, encode the offset using little-endian bit order.
- decode(bits_to_decode: ConstBitStream) int#
Decode an integer value from a bit stream.
- Parameters:
bits_to_decode – Bit stream positioned at the encoded integer.
- encode(value: int) tuple[Bits, int]#
Encode an integer value.
- Returns:
Tuple of
(bits, encoded_value).encoded_valueis the clipped and quantized value represented by the bits.
- property max_length_bits: int#
Encoded integer length in bits.
- property min_length_bits: int#
Encoded integer length in bits.