# pamqp.decode

Functions for decoding data of various types including field tables and arrays

pamqp.decode.by_type(value: bytes, data_type: str, offset: int = 0) → Tuple[int, bool | bytes | bytearray | Decimal | List[FieldValue] | Dict[str, FieldValue] | float | int | None | str | datetime]

  Decodes values using the specified type

  Parameters:

    - value – The binary value to decode

    - data_type – The data type name of the value

    - offset – The starting position of the data in the byte stream

  Return type:

    `tuple` (`int`, `pamqp.common.FieldValue`)

  Raises:

    ValueError – when the data type is unknown

pamqp.decode.bit(value: bytes, position: int) → Tuple[int, bool]

  Decode a bit value, returning bytes consumed and the value.

  Parameters:

    - value – The binary value to decode

    - position – The position in the byte of the bit value

  Return type:

    `tuple` (`int`, `bool`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.boolean(value: bytes) → Tuple[int, bool]

  Decode a boolean value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `bool`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.byte_array(value: bytes) → Tuple[int, bytearray]

  Decode a byte_array value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `bytearray`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.decimal(value: bytes) → Tuple[int, Decimal]

  Decode a decimal value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `decimal.Decimal`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.double(value: bytes) → Tuple[int, float]

  Decode a double value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `float`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.floating_point(value: bytes) → Tuple[int, float]

  Decode a floating point value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `float`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.long_int(value: bytes) → Tuple[int, int]

  Decode a long integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.long_uint(value: bytes) → Tuple[int, int]

  Decode an unsigned long integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.long_long_int(value: bytes) → Tuple[int, int]

  Decode a long-long integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.long_str(value: bytes) → Tuple[int, str | bytes]

  Decode a string value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `str`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.octet(value: bytes) → Tuple[int, int]

  Decode an octet value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.short_int(value: bytes) → Tuple[int, int]

  Decode a short integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.short_uint(value: bytes) → Tuple[int, int]

  Decode an unsigned short integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.short_short_int(value: bytes) → Tuple[int, int]

  Decode a short-short integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.short_short_uint(value: bytes) → Tuple[int, int]

  Decode a unsigned short-short integer value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `int`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.short_str(value: bytes) → Tuple[int, str]

  Decode a string value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `str`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.timestamp(value: bytes) → Tuple[int, datetime]

  Decode a timestamp value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `datetime.datetime`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.embedded_value(value: bytes) → Tuple[int, bool | bytes | bytearray | Decimal | List[FieldValue] | Dict[str, FieldValue] | float | int | None | str | datetime]

  Dynamically decode a value based upon the starting byte

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `pamqp.common.FieldValue`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.field_array(value: bytes) → Tuple[int, List[FieldValue]]

  Decode a field array value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `pamqp.common.FieldArray`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.field_table(value: bytes) → Tuple[int, Dict[str, FieldValue]]

  Decode a field array value, returning bytes consumed and the value.

  Parameters:

    value – The binary value to decode

  Return type:

    `tuple` (`int`, `pamqp.common.FieldTable`)

  Raises:

    ValueError – when the binary data can not be unpacked

pamqp.decode.void(_: bytes) → Tuple[int, None]

  Return a void, no data to decode

  Parameters:

    _ – The empty bytes object to ignore

  Return type:

    `tuple` (`int`, `None`)