Common Structs#

Numeric Structs#

class caterpillar.py.PyStructFormattedField(ch: str, type_: type)[source]#

A field class representing a binary format using format characters (e.g., ‘i’, ‘x’, etc.).

This class allows you to define fields for binary struct formats using format characters, which are often used in Python’s struct module. Each field is associated with a format character (like ‘x’ for padding or ‘i’ for a signed integer), and it determines how data is packed and unpacked.

Example usage:

>>> field = PyStructFormattedField('i', int)
>>> field.__repr__()
"<PyStructFormattedField(int) 'i' 32>"
Parameters:
  • ch – The format character (e.g., ‘i’, ‘x’, ‘f’) that defines how the field is packed and unpacked.

  • type – The Python type that corresponds to the format character.

Changed in version 2.4.0: FormatField renamed to PyStructFormattedField

text#

The format char (e.g. ‘x’, ‘i’, …)

ty#

The returned Python type

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single value into the stream using the defined format character.

Parameters:
  • obj – The value to pack (can be of the type defined by the format character).

  • context – The context that provides the stream and field-specific information.

pack_seq(seq: Sequence, context: _ContextLike) None[source]#

Pack a sequence of values into the stream.

If the context specifies a fixed amount, it will pack the sequence accordingly.

Parameters:
  • seq – The sequence of values to pack.

  • context – The context providing packing information.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single value from the stream.

Parameters:

context – The context that provides the stream and field-specific information.

Returns:

The unpacked value, converted to the field’s corresponding Python type.

unpack_seq(context: _ContextLike) List[Any][source]#

Unpack a sequence of values from the stream.

Parameters:

context – The context that provides the stream and field-specific information.

Returns:

A list of unpacked values.

get_length(context: _ContextLike) int[source]#

Get the length of the field, which may be dynamically determined based on the context.

Parameters:

context – The context providing the length information.

Returns:

The length of the field (1 if no length is specified).

Return type:

int

is_padding() bool[source]#

Check if the field represents padding.

Returns:

True if the field is padding (i.e., ‘x’ format character), False otherwise.

Return type:

bool

py.uint8 = <PyStructFormattedField(int) 'B' 8>#
py.int8 = <PyStructFormattedField(int) 'b' 8>#
py.uint16 = <PyStructFormattedField(int) 'H' 16>#
py.int16 = <PyStructFormattedField(int) 'h' 16>#
py.uint32 = <PyStructFormattedField(int) 'I' 32>#
py.int32 = <PyStructFormattedField(int) 'i' 32>#
py.uint64 = <PyStructFormattedField(int) 'Q' 64>#
py.int64 = <PyStructFormattedField(int) 'q' 64>#
py.size_t = <PyStructFormattedField(int) 'N' 64>#
py.ssize_t = <PyStructFormattedField(int) 'n' 64>#
py.float16 = <PyStructFormattedField(float) 'e' 16>#
py.float32 = <PyStructFormattedField(float) 'f' 32>#
py.float64 = <PyStructFormattedField(float) 'd' 64>#
py.void_ptr = <PyStructFormattedField(int) 'P' 64>#
py.char = <PyStructFormattedField(str) 'c' 8>#
py.boolean = <PyStructFormattedField(bool) '?' 8>#
py.padding = <PyStructFormattedField(padding) 'x' 8>#
class caterpillar.py.Int(bits: int, signed: bool = True)[source]#

Generic Integer

This class handles packing and unpacking integer values with a specified bit size, either signed or unsigned. The size of the integer is defined in bits, and the class ensures the appropriate byte representation is used for packing and unpacking.

Parameters:
  • bits – The bit width of the integer (e.g., 8, 16, 32, 64).

  • signed – Whether the integer is signed (default is True).

pack_single(obj: int, context: _ContextLike) None[source]#

Pack a single integer value into the stream.

This method converts the integer value into a byte representation using the specified byte order. The byte order is determined from the context’s field order (either little-endian or big-endian).

Parameters:
  • obj – The integer value to pack.

  • context – The current context, which provides the byte order (little-endian or big-endian).

Raises:

ValueError – If the integer is too large or small for the given bit width.

unpack_single(context: _ContextLike) int[source]#

Unpack a single integer value from the stream.

This method reads a byte sequence from the stream, interprets it as an integer using the specified byte order and signedness, and returns the integer value.

Parameters:

context – The current context, which provides the byte order (little-endian or big-endian).

Returns:

The unpacked integer value.

Raises:

ValueError – If the data cannot be unpacked as an integer of the specified size.

class caterpillar.py.UInt(bits: int)[source]#

Generic unsigned integer.

py.vint = <VarInt>#
class caterpillar.py.VarInt[source]#

Variable-length integer struct.

This class implements variable-length unsigned integer for big-endian and little-endian encoding. The default behaviour uses big-endian encoding. It has an additional flag that can be configured globally or once per field.

VARINT_LSB specifies that the last significant byte will use a 1 to identify the end of the varint. Otherwise, zero will be used (which is the default setting). The following configurations are therefore possible:

>>> field = be + vint; print(pack(1024, field))
b'\x88\x00'
>>> field = be + vint | VARINT_LSB; print(pack(1024, field))
b'\x08\x80'
>>> field = le + vint; print(pack(1024, field))
b'\x80\x08'
>>> field = le + vint | VARINT_LSB; print(pack(1024, field))
b'\x00\x88'
pack_single(obj: int, context: _ContextLike) None[source]#

Pack a single value into the stream.

Parameters:
  • obj – The value to pack.

  • context – The current context.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single value from the stream.

Parameters:
  • stream – The input stream.

  • context – The current context.

Returns:

The unpacked value.

Bytes, Strings#

class caterpillar.py.Memory(length: int | _ContextLambda | ellipsis)[source]#

A class representing a memory field that handles packing and unpacking byte-like objects of a specified length.

The Memory class is used to manage fields that contain raw byte data. It allows you to pack a byte object (either bytes or memoryview) into a stream and unpack byte data from a stream into a memoryview. The length of the memory field can be fixed or dynamically determined based on the context. If the length is unspecified, the entire available data in the stream is read.

This class can handle the following scenarios for the length argument: - Fixed length: A specific number of bytes (e.g., 10). - Dynamic length: A callable that returns the length based on the current context (e.g., lambda ctx: ctx[“length”]). - Greedy length: Using Ellipsis (), meaning the entire stream is read regardless of the size.

Examples:

>>> # Memory with a fixed length of 10 bytes
>>> memory = Memory(10)
>>> memory_dynamic = Memory(lambda ctx: ctx._root.length) # dynamic length based on context
>>> memory_greedy = Memory(...)
>>> pack(b"1234567890", memory, as_field=True)
b"1234567890"
>>> pack(b"1234567890", memory_dynamic, as_field=True, length=10)
b"1234567890"
>>> unpack(b"1234567890", memory_greedy, as_field=True)
b"1234567890"
Parameters:

length – The length of the memory to pack or unpack. It can be: - An integer specifying the number of bytes to handle. - A callable that dynamically returns the number of bytes based on the context. - Ellipsis (), indicating the length is unspecified and the entire stream should be read.

Changed in version 2.4.0: Removed encoding argument

pack_single(obj: memoryview | bytes, context: _ContextLike) None[source]#

Pack a single byte object (memoryview or bytes) into the stream.

This method writes a byte object (memoryview or bytes) into the stream, ensuring that the size of the object matches the expected length defined by the Memory field. If the expected size is fixed (not Ellipsis), a validation is performed to ensure that the length of the obj matches the expected size.

Examples:

>>> memory = Memory(10)
>>> pack(b"1234567890", memory, as_field=True) # Packs exactly 10 bytes into the stream
b"1234567890"
>>> pack(b"1", memory, as_field=True)
Traceback (most recent call last):
...
ValidationError: Memory field expected 10 bytes, but got 1 bytes instead
Parameters:
  • obj – The byte object to be packed. This can be either a memoryview or a bytes object.

  • context – The current context, which provides access to the stream and any additional metadata needed for packing.

Raises:

ValidationError – If the length of the obj does not match the expected size.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single byte object (memoryview) from the stream.

This method reads bytes from the stream into a memoryview. The size of the object to be unpacked is determined by the Memory field’s length. If the length is fixed (not Ellipsis), it reads exactly that number of bytes. If the length is unspecified (i.e., Ellipsis), it reads until the end of the stream.

Parameters:

context – The current context, which provides access to the stream and any additional metadata needed for unpacking.

Returns:

A memoryview object representing the unpacked byte data.

class caterpillar.py.Bytes(length: int | _ContextLambda | ellipsis)[source]#

Byte sequences.

Same class as Memory but with a type of bytes instead of memoryview.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single byte sequence (bytes) from the stream.

Parameters:

context – The current context, which provides access to the stream and other necessary metadata for unpacking.

Returns:

A bytes object representing the unpacked data from the stream.

class caterpillar.py.String(length: int | _ContextLambda | ellipsis, encoding: str | None = None)[source]#

String sequences.

Same class as Memory but with a type of str instead of memoryview.

Parameters:
  • length – The length of the string to pack or unpack. It can be: - An integer specifying the number of bytes (e.g., 10). - A callable that dynamically returns the number of bytes based on the context (e.g., lambda ctx: ctx[“length”]). - Ellipsis (), meaning the entire available stream should be read, regardless of size.

  • encoding – The encoding to use for converting bytes to a string during unpacking. If not specified, defaults to None. If specified, the string will be decoded using this encoding (e.g., utf-8).

pack_single(obj: str, context: _ContextLike) None[source]#

Packs a single string into the stream.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single string from the stream.

Parameters:

context – The current context.

Returns:

A str representing the unpacked string, decoded from bytes using the specified encoding.

class caterpillar.py.Prefixed(prefix: _StructLike, struct: _StructLike | None = None, encoding: str | None = None)[source]#

A specialized field for handling data with a prefix (typically indicating length or size).

This class is used when you want to prefix a data structure with a size or other identifying information. The prefix is typically packed first, followed by the actual data. The field allows for handling both prefixed data with a structure and simple byte sequences, depending on the presence of the struct argument. However, the returned prefix value must be an integer.

Example usage:

>>> prefixed = Prefixed(uint32, Bytes(4))
>>> pack(b"abcd", prefixed, as_field=True)
b"\x00\x00\x00\x04abcd"
>>> unpack(prefixed, b"\x00\x00\x00\x04abcd", as_field=True)
b"abcd"

The prefix is packed and unpacked independently and is used to determine the size of the following data.

Please note that this class will have a huge impact on the resulting packing and unpacking time and will increase it significantly.

Parameters:
  • prefix – The struct that defines the prefix (e.g., a length field).

  • struct – The struct that defines the data to follow the prefix (e.g., Bytes or another field).

Added in version 2.4.0: Added support for arbitrary structs

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single object into the stream, with the prefix indicating the size.

This method first packs the length of the data (the prefix), and then writes the actual data.

Parameters:
  • obj – The object to pack (should be a byte sequence).

  • context – The current context.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single object from the stream, using the prefix to determine the size.

This method first unpacks the prefix (which indicates the size), then reads the data from the stream based on that size. If a struct is provided, the data is then passed through the specified structure for further unpacking.

Parameters:

context – The current context.

Returns:

The unpacked object, which is either raw bytes or the data structure.

class caterpillar.py.CString(length: int | _ContextLambda | None | ellipsis = None, encoding: str | None = None, pad: str | int | None = None)[source]#

C-style strings (null-terminated or padded).

This class is designed for handling strings that are padded to a fixed length, typically with zero-padding or any custom padding character. It is useful for encoding and decoding data that follows the C-style string conventions, where strings are often represented by a fixed length, and padding (e.g., null bytes) is used to fill the remaining space.

Example usage:

>>> cstring = CString(10, encoding='utf-8') # encoding is optional
>>> pack(cstring, "Hello, World!")
b"Hello, World\x00"
>>> unpack(cstring, b"Hello, World\x00")
'Hello, World!'

This class also supports direct getitem access to create a list:

>>> cstrings = CString[10] # array of ten strings (variable size)
Parameters:
  • length – The fixed length of the C-string or a callable that determines the length based on the context. If None or Ellipsis, the string will be unpacked until the padding character is found.

  • encoding – The encoding to use for converting the byte data to a string. Defaults to utf-8. If None, the default encoding is used.

  • pad – The padding character to use (usually 0 for null padding). If a string is provided, it must be a single character. If not specified, defaults to 0 (null byte).

pack_single(obj: str, context: _ContextLike) None[source]#

Pack a single string into the stream with padding.

This method encodes the string into bytes and pads it to the fixed length, if applicable. If the length is dynamic or unspecified, padding is added until the total length is achieved.

Parameters:
  • obj – The string to pack into the stream.

  • context – The current context.

Raises:

ValidationError – If the string is too long for the fixed length.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single C-style string from the stream.

This method reads bytes from the stream until a padding character is found. If the length is fixed, it will unpack exactly that number of bytes. If length is unspecified, it unpacks until the padding character is encountered.

Parameters:

context – The current context, which provides access to the stream and other necessary metadata.

Returns:

The unpacked string, stripped of padding, decoded with the specified encoding.

class caterpillar.py.ConstString(value: str, encoding: str | None = None)[source]#

A specialized constant field for handling fixed string values.

This class is used to define a field that always holds a constant string value. The value is validated during both encoding and decoding to ensure that the expected constant string is preserved. The string can optionally be encoded in a specific encoding.

Additionally, this class provides a type converter that can be used to convert a string annotation to a ConstString field.

>>> @struct
... class MyStruct:
...     value: "const str" # <-- will be converted to ConstString

Note that the type declaration above won’t work if you enable annotation evaluation.

Examples:

>>> # Define a constant string value to enforce during encoding/decoding
>>> const_str = ConstString("Hello, World!")
>>> pack(None, const_str, as_field=True)
b"Hello, World!"
>>> unpack(const_str, b"Hello, World!", as_field=True)
"Hello, World!"
Parameters:
  • value – The constant string value to be encoded/decoded.

  • encoding – The encoding to use for the string (default is UTF-8). If None, the default system encoding is used.

class caterpillar.py.ConstBytes(value: bytes)[source]#

A constant field for handling fixed bytes values.

This class is used to define a field that always holds a constant bytes value. The value is validated during both encoding and decoding to ensure that the expected constant byte sequence is preserved.

This class provides a type converter that can be used to convert a bytes annotation to a ConstBytes field.

>>> @struct
... class MyStruct:
...     value: b"const bytes" # <-- will be converted to ConstBytes
Parameters:

value – The constant bytes value to be encoded/decoded.

Special Structs#

py.Pass = <Pass>#

See source code for details

class caterpillar.py.Aligned(struct: _StructLike, alignment: int | _ContextLambda, after: bool = False, before: bool = False, filler: int | str | None = None)[source]#

Alignment of a struct (before or after)

This class ensures that the associated struct is properly aligned according to the specified alignment. It allows for padding before or after the field, ensuring that the field starts or ends at a memory address that is a multiple of the alignment.

Example usage:

>>> @struct
... class Format:
...     a: Aligned(int16, alignment=4, after=True)
...     b: uint8
...
>>> unpack(Format, b"\x00\x01\xFF\xFF\x01")
Traceback (most recent call last):
...
ValueError: Expected 2 bytes of padding (value=0), got 0
>>> unpack(Format, b"\x00\x01\x00\x00\x01")
Format(a=256, b=1)

This example shows a Format structure where: - a is an aligned integer (with 4-byte alignment) and padding is applied after the field. - b is an unsigned byte (uint8), which follows a after the padding.

Parameters:
  • struct – The structure that is to be aligned.

  • alignment – The alignment value in bytes, which must be a power of 2. This can be an integer or a context lambda for dynamic alignment.

  • after – If True, padding is applied after the structure (align after).

  • before – If True, padding is applied before the structure (align before).

  • filler – The byte value to use for padding. It can be an integer or a string (default is zero-padding). If no filler is provided, b”" will be used as the padding byte.

Raises:
  • ValueError – If neither before nor after is specified, if the filler is not a single byte, or if the padding does not match the expected value.

  • DynamicSizeError – If dynamic alignment is used and the size cannot be determined.

Added in version 2.4.0.

unpack_alignment(context: _ContextLike)[source]#

Unpack padding for the alignment, verifying that the correct amount of padding is present.

Parameters:

context – The current context.

Raises:

ValueError – If the padding does not match the expected value.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single aligned field from the stream.

This method ensures that padding is applied before or after the field as needed based on the before and after parameters.

Parameters:

context – The current context.

Returns:

The unpacked structure, properly aligned.

pack_alignment(context: _ContextLike)[source]#

Apply padding for the alignment before or after the structure, depending on the before and after settings.

Parameters:

context – The current context.

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single aligned field into the stream, applying padding if necessary.

Parameters:
  • obj – The structure to pack.

  • context – The current context.

caterpillar.py.align(alignment: int | _ContextLambda) _ContextLambda[source]#

Create a context lambda to calculate the alignment padding required at the current stream position.

This function generates a lambda that can be used to compute the amount of padding required to ensure that the next structure in the stream is aligned to the specified alignment.

The alignment value can either be a fixed integer (representing the alignment in bytes) or a context lambda that computes the alignment dynamically based on the current context.

Example usage:

>>> @struct
... class Format:
...     a: uint8
...     b: padding[align(4)]
...
>>> unpack(Format, b"\x01\x00\x00\x00")
Format(a=1, b=None)
Parameters:

alignment – The alignment value in bytes, which must be a power of 2. This can be either an integer or a context lambda.

Returns:

A context lambda function that returns the number of bytes to align the next structure.

Added in version 2.4.0.

class caterpillar.py.Computed(value: str | bytes | Any | _ContextLambda)[source]#

A specialized field for representing computed or dynamically calculated values.

This class is used to define a field that holds a computed value. The value can either be a constant or a function (lambda) that computes the value dynamically based on the context during packing or unpacking.

The computed value is not directly stored; instead, it is evaluated using the provided lambda function or constant value during encoding and decoding.

Examples:

>>> # Define a computed field with a constant value
>>> computed = Computed(42)
>>> unpack(computed, b"\x00\x01", as_field=True)
42
>>> pack(None, computed, as_field=True)
b"" # won't affect the stream
Parameters:

value – A constant value or a lambda function that computes the value based on the context.

pack_single(obj: Any, context: _ContextLike) None[source]#

No packing is needed for computed fields.

Parameters:
  • obj – The object to pack.

  • context – The current context.

unpack_single(context: _ContextLike) None[source]#

No unpacking is needed for computed fields.

Parameters:

context – The current context.

class caterpillar.py.Transformer(struct: _StructLike)[source]#

A class that acts as a transformer for encoding and decoding data using a wrapped _StructLike object.

encode(obj: Any, context: _ContextLike) Any[source]#

Encode data using the wrapped _StructLike object.

Parameters:
  • obj – The original data to be encoded.

  • context – The current context.

Returns:

The encoded data.

decode(parsed: Any, context: _ContextLike) Any[source]#

Decode data using the wrapped _StructLike object.

Parameters:
  • parsed – The parsed data to be decoded.

  • context – The current context.

Returns:

The decoded data.

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single value into the stream using encoding.

Parameters:
  • obj – The original data to be encoded and packed.

  • context – The current context.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single value from the stream and decode it.

Parameters:

context – The current context.

Returns:

The decoded data.

class caterpillar.py.Enum(model: type, struct: ~caterpillar.abc._StructLike, default: ~caterpillar.abc._EnumLike | ~typing.Any | None = <object object>)[source]#

A specialized Transformer for encoding and decoding enumeration values.

This class is used for transforming between enumeration values and their corresponding encoded representations (typically integers). It provides encoding and decoding methods to ensure that enum values are serialized and deserialized correctly. Additionally, it supports a default value in case an invalid or unrecognized value is encountered during decoding.

Example usage:

>>> from enum import Enum as PyEnum
>>> class Color(PyEnum):
...     RED = 1
...     GREEN = 2
...     BLUE = 3
...
>>> cp_enum = Enum(Color, uint8)
>>> pack(Color.RED, cp_enum, as_field=True)
b"\x01"
>>> unpack(cp_enum, b"\x01", as_field=True)
Color.RED
Parameters:
  • model – The enumeration model (an object with _member_map_ and _value2member_map_ attributes).

  • struct – The _StructLike object to be wrapped.

  • default – The default value to return if decoding encounters an unrecognized value. Default is INVALID_DEFAULT.

encode(obj: Any, context: _ContextLike) Any[source]#

Encode an enumeration value into its corresponding encoded representation.

Parameters:
  • obj – The original enumeration value to encode (e.g., Color.RED).

  • context – The current context.

Returns:

The encoded value (usually an integer representing the enum).

Raises:

ValidationError – If the input value is not a valid enum type.

Example: >>> cp_enum.encode(Color.GREEN, context) 2 # (the integer value of Color.GREEN)

decode(parsed: Any, context: _ContextLike) Any[source]#

Decode an encoded value (typically an integer) back to its corresponding enumeration value.

Parameters:
  • parsed – The parsed value (usually an integer).

  • context – The current context.

Returns:

The corresponding enumeration value.

Raises:

InvalidValueError – If the parsed value cannot be mapped to a valid enum.

Example: >>> cp_enum.decode(1, context) Color.RED >>> unpack(1, cp_enum, as_field=True) Color.RED

class caterpillar.py.Const(value: str | bytes | Any, struct: _StructLike)[source]#

A specialized Transformer that enforces a constant value during encoding and decoding.

This class ensures that the encoded value is always the same constant, and when decoding, it checks if the value matches the expected constant. If the value doesn’t match, a ValidationError is raised.

Example usage:

>>> # Define a constant value to enforce during encoding/decoding
>>> const_value = 42
>>> struct = SomeStruct() # must parse 'const_value`
>>> field = Const(const_value, struct)
>>> pack(None, field)
b"\x2a"
>>> unpack(field, b"\x2a")
42
Parameters:
  • value – The constant value to be enforced during encoding and decoding.

  • struct – The _StructLike object to be wrapped.

encode(obj: Any, context: _ContextLike) Any[source]#

Encode data using the constant value. This method will always return the constant value, regardless of the input. Therefore, None can be passed as the obj parameter.

Parameters:
  • obj – The original data to be encoded (ignored in this transformer).

  • context – The current context (optional, not used in this implementation).

Returns:

The constant value.

Example:
>>> constant_value = 42
>>> transformer = Const(constant_value, SomeStruct())
>>> transformer.encode(None, context) # context is optional
42
decode(parsed: Any, context: _ContextLike) Any[source]#

Decode data and ensure it matches the constant value. If the parsed value doesn’t match, a ValidationError is raised.

Parameters:
  • parsed – The parsed data to be decoded (must match the constant value).

  • context – The current context (optional, not used in this implementation).

Returns:

The constant value if parsed matches the expected constant.

Raises:

ValidationError – If the parsed value does not match the constant value.

Example: >>> constant_value = 42 >>> field = Const(constant_value, SomeStruct()) >>> unpack(field, b”x2a”) 42 >>> unpack(field, b”x24”) Traceback (most recent call last): … ValidationError: Expected 42, got 36

class caterpillar.py.Lazy(struct: Callable[[], _StructLike])[source]#

A lazy field struct that defers the creation of the underlying struct until it is needed.

This class allows the definition of a field where the underlying struct is not created until the field is actually accessed. This can help with optimization in scenarios where certain fields may not always be used.

The underlying struct is defined by a callable that returns an instance of a struct. The struct_fn function is invoked to generate the struct when the field is accessed.

Example usage:

>>> @struct
... class Format:
...     a: Lazy(lambda: SecondFormat)  # Lazy instantiation of the struct
...     b: uint8
...
>>> @struct
... class SecondFormat:
...     a: uint8
...
>>> unpack(Format, b"\x01\x02\xFF")
Format(a=SecondFormat(a=1), b=255)
Parameters:

struct – A callable that returns the underlying struct, which will be lazily created when the field is accessed.

property struct: _StructLike#

Get the underlying struct by invoking the callable.

This method ensures that the struct is only created once, and it is cached for subsequent use.

Returns:

The underlying struct.

Return type:

_StructLike

pack_single(obj: Any, context: _ContextLike) None[source]#

Pack a single value using the Lazy struct by delegating to the underlying struct.

Parameters:
  • obj – The value to pack.

  • context – The context for packing.

unpack_single(context: _ContextLike) Any[source]#

Unpack a single value using the Lazy struct by delegating to the underlying struct.

Parameters:

context – The context for unpacking.

Returns:

The unpacked value.

caterpillar.py.Uuid[source]#

alias of <Uuid>