pamqp.encode

AMQP Data Encoder

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.bit(value, byte, position)[source]

Encode a bit value

Parameters:
  • value (int) – Value to decode
  • byte (int) – The byte to apply the value to
  • position (int) – The position in the byte to set the bit on
Return type:

tuple of bytes used and a bool value

pamqp.encode.boolean(value)[source]

Encode a boolean value.

Parameters:value (bool) – Value to encode
Return type:bytes
pamqp.encode.by_type(value, data_type)[source]

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

Parameters:
  • value (any) – Value to encode
  • data_type (str) – type of data to encode
Return type:

bytes

Raises:

TypeError

pamqp.encode.byte_array(value)[source]

Encode a bytearray

Parameters:value (bytearray) – Value to encode
Return type:bytes
pamqp.encode.decimal(value)[source]

Encode a decimal.Decimal value.

Parameters:value (decimal.Decimal) – Value to encode
Return type:bytes
pamqp.encode.double(value)[source]

Encode a floating point value as a double

Parameters:value (float) – Value to encode
Return type:str
pamqp.encode.encode_table_value(value)[source]

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

Parameters:value (any) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.field_array(value)[source]

Encode a field array from a dictionary.

Parameters:value (list) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.field_table(value)[source]

Encode a field table from a dictionary.

Parameters:or None value (dict) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.floating_point(value)[source]

Encode a floating point value.

Parameters:value (float) – Value to encode
Return type:bytes
pamqp.encode.long_int(value)[source]

Encode a long integer.

Parameters:value (int) – Value to encode
Return type:bytes
pamqp.encode.long_long_int(value)[source]

Encode a long-long int.

Parameters:or int value (long) – Value to encode
Return type:bytes
pamqp.encode.long_string(value)[source]

Encode a “long string” which the specific defines as any non-null data. We will auto-convert str and unicode to bytes but ignore bytes objects and place them opaquely.

Parameters:value (bytes or str or unicode) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.long_uint(value)[source]

Encode a long integer.

Parameters:value (int) – Value to encode
Return type:bytes
pamqp.encode.octet(value)[source]

Encode an octet value.

Parameters:value – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.short_int(value)[source]

Encode a short integer.

Parameters:value (int) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.short_string(value)[source]

Encode a string.

Parameters:value (bytes or str or unicode) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.short_uint(value)[source]

Encode an unsigned short integer.

Parameters:value (int) – Value to encode
Return type:bytes
Raises:TypeError
pamqp.encode.support_deprecated_rabbitmq()[source]

Invoke to restrict the data types available in field-tables that are sent to RabbitMQ.

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
Return type:bytes
Raises:TypeError
pamqp.encode.timestamp(value)[source]

Encode a datetime.datetime object or time.struct_time.

Parameters:value (datetime.datetime, time.struct_time, integer) – Value to encode
Return type:bytes
Raises:TypeError