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 [source]
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: Union[bool, bytearray, decimal.Decimal, List[FieldValue], Dict[str, FieldValue], float, int, None, str, datetime.datetime], data_type: str) bytes [source]
Takes a value of any type and tries to encode it with the specified encoder.
- Parameters
value (
pamqp.common.FieldValue
) – The value to encodedata_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 [source]
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 [source]
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 [source]
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.Decimal) bytes [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
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 [source]
Encode a string
- Parameters
value – Value to encode
- Raises
TypeError – when the value is not the correct type
- pamqp.encode.timestamp(value: Union[datetime.datetime, time.struct_time]) bytes [source]
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 [source]
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 [source]
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 [source]
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: Union[List[FieldValue], Dict[str, FieldValue], bool, bytearray, decimal.Decimal, float, int, None, str, datetime.datetime]) bytes [source]
Takes a value of any type and tries to encode it with the proper encoder
- Parameters
value (
pamqp.common.FieldArray
orpamqp.common.FieldTable
orpamqp.common.FieldValue
) – Value to encode- Raises
TypeError – when the type of the value is not supported