# pamqp.encode

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

pamqp.encode.DEPRECATED_RABBITMQ_SUPPORT = False

  Toggle to support older versions of RabbitMQ.

pamqp.encode.support_deprecated_rabbitmq(enabled: bool = True) → None

  Toggle the data types available in field-tables

  If called with True, than RabbitMQ versions, the field-table integer types will not support the full AMQP spec.

  Parameters:

    enabled – Specify if deprecated RabbitMQ versions are supported

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

  Takes a value of any type and tries to encode it with the specified encoder.

  Parameters:

    - value (`pamqp.common.FieldValue`) – The value to encode

    - data_type – The data type name to use for encoding

  Raises:

    TypeError – when the `data_type` is unknown

pamqp.encode.bit(value: int, byte: int, position: int) → int

  Encode a bit value

  Parameters:

    - value – Value to encode

    - byte – The byte to apply the value to

    - position – The position in the byte to set the bit on

pamqp.encode.boolean(value: bool) → bytes

  Encode a boolean value

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.byte_array(value: bytearray) → bytes

  Encode a byte array value

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.decimal(value: Decimal) → bytes

  Encode a decimal.Decimal value

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.double(value: float) → bytes

  Encode a floating point value as a double

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.floating_point(value: float) → bytes

  Encode a floating point value

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.long_int(value: int) → bytes

  Encode a long integer

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

pamqp.encode.long_uint(value: int) → bytes

  Encode a long unsigned integer

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

pamqp.encode.long_long_int(value: int) → bytes

  Encode a long-long int

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

pamqp.encode.long_string(value: str) → bytes

  Encode a “long string”

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.octet(value: int) → bytes

  Encode an octet value

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.short_int(value: int) → bytes

  Encode a short integer

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

pamqp.encode.short_uint(value: int) → bytes

  Encode an unsigned short integer

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

pamqp.encode.short_string(value: str) → bytes

  Encode a string

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.timestamp(value: datetime | struct_time) → bytes

  Encode a datetime.datetime object or time.struct_time

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.field_array(value: List[FieldValue]) → bytes

  Encode a field array from a list of values

  Parameters:

    value (`pamqp.common.FieldArray`) – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.field_table(value: Dict[str, FieldValue]) → bytes

  Encode a field table from a dict

  Parameters:

    value (`pamqp.common.FieldTable`) – Value to encode

  Raises:

    TypeError – when the value is not the correct type

pamqp.encode.table_integer(value: int) → bytes

  Determines the best type of numeric type to encode value as, preferring the smallest data size first.

  Parameters:

    value – Value to encode

  Raises:

    TypeError – when the value is not the correct type or outside the acceptable range for the data type

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

  Takes a value of any type and tries to encode it with the proper encoder

  Parameters:

    value (`pamqp.common.FieldArray` or `pamqp.common.FieldTable` or `pamqp.common.FieldValue`) – Value to encode

  Raises:

    TypeError – when the type of the value is not supported