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=True)[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 (bool
) – Specify if deprecated RabbitMQ versions are supported
- Return type
None
-
pamqp.encode.
by_type
(value, data_type)[source] Takes a value of any type and tries to encode it with the specified encoder.
- Parameters
-
- Raises
TypeError – when the data_type
is unknown
- Return type
bytes
-
pamqp.encode.
bit
(value, byte, position)[source] Encode a bit value
- Parameters
value (int
) – Value to encode
byte (int
) – The byte to apply the value to
position (int
) – The position in the byte to set the bit on
- Return type
int
-
pamqp.encode.
boolean
(value)[source] Encode a boolean value
- Parameters
value (bool
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
byte_array
(value)[source] Encode a byte array value
- Parameters
value (bytearray
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
decimal
(value)[source] Encode a decimal.Decimal value
- Parameters
value (decimal.Decimal
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
double
(value)[source] Encode a floating point value as a double
- Parameters
value (float
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
floating_point
(value)[source] Encode a floating point value
- Parameters
value (float
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
long_int
(value)[source] Encode a long integer
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
long_uint
(value)[source] Encode a long unsigned integer
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
long_long_int
(value)[source] Encode a long-long int
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
long_string
(value)[source] Encode a “long string”
- Parameters
value (str
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
octet
(value)[source] Encode an octet value
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
short_int
(value)[source] Encode a short integer
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
short_uint
(value)[source] Encode an unsigned short integer
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
short_string
(value)[source] Encode a string
- Parameters
value (str
) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
timestamp
(value)[source] Encode a datetime.datetime object or time.struct_time
- Parameters
value (typing.Union
[datetime.datetime
, time.struct_time
]) – Value to encode
- Raises
TypeError – when the value is not the correct type
- Return type
bytes
-
pamqp.encode.
field_array
(value)[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
- Return type
bytes
-
pamqp.encode.
field_table
(value)[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
- Return type
bytes
-
pamqp.encode.
table_integer
(value)[source] Determines the best type of numeric type to encode value as, preferring the smallest data size first.
- Parameters
value (int
) – Value to encode
- Raises
TypeError – when the value is not the correct type or outside the acceptable range for the data type
- Return type
bytes
-
pamqp.encode.
encode_table_value
(value)[source] 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
- Return type
bytes