pamqp.encode
pamqp.encode
Functions for encoding data of various types including field tables and arrays
DEPRECATED_RABBITMQ_SUPPORT = False
module-attribute
Toggle to support older versions of RabbitMQ.
support_deprecated_rabbitmq(enabled=True)
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:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
Specify if deprecated RabbitMQ versions are supported |
True
|
Source code in pamqp/encode.py
22 23 24 25 26 27 28 29 30 31 32 33 | |
by_type(value, data_type)
Takes a value of any type and tries to encode it with the specified encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
FieldValue
|
The value to encode |
required |
data_type
|
str
|
The data type name to use for encoding |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the :data: |
Source code in pamqp/encode.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
bit(value, byte, position)
Encode a bit value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
byte
|
int
|
The byte to apply the value to |
required |
position
|
int
|
The position in the byte to set the bit on |
required |
Source code in pamqp/encode.py
52 53 54 55 56 57 58 59 60 | |
boolean(value)
Encode a boolean value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
63 64 65 66 67 68 69 70 71 72 | |
byte_array(value)
Encode a byte array value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bytearray
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
75 76 77 78 79 80 81 82 83 84 | |
decimal(value)
Encode a decimal.Decimal value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Decimal
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
double(value)
Encode a floating point value as a double
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
112 113 114 115 116 117 118 119 120 121 | |
floating_point(value)
Encode a floating point value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
124 125 126 127 128 129 130 131 132 133 | |
long_int(value)
Encode a long integer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
136 137 138 139 140 141 142 143 144 145 146 147 148 | |
long_uint(value)
Encode a long unsigned integer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
151 152 153 154 155 156 157 158 159 160 161 162 163 | |
long_long_int(value)
Encode a long-long int
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
long_string(value)
Encode a "long string"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
184 185 186 187 188 189 190 191 | |
octet(value)
Encode an octet value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
194 195 196 197 198 199 200 201 202 203 | |
short_int(value)
Encode a short integer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
206 207 208 209 210 211 212 213 214 215 216 217 218 | |
short_uint(value)
Encode an unsigned short integer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
221 222 223 224 225 226 227 228 229 230 231 232 233 | |
short_string(value)
Encode a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
236 237 238 239 240 241 242 243 | |
timestamp(value)
Encode a datetime.datetime object or time.struct_time
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime | struct_time
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
field_array(value)
Encode a field array from a list of values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
FieldArray
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
field_table(value)
Encode a field table from a dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
FieldTable
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type |
Source code in pamqp/encode.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
table_integer(value)
Determines the best type of numeric type to encode value as, preferring the smallest data size first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the value is not the correct type or outside the acceptable range for the data type |
Source code in pamqp/encode.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
encode_table_value(value)
Takes a value of any type and tries to encode it with the proper encoder
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
FieldArray | FieldTable | FieldValue
|
Value to encode |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the type of the value is not supported |
Source code in pamqp/encode.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |