root/src/modules/librabbitmq/amqp_framing.c

Revision 1e8ae2b61ace7f9ef47a4f5c190bd2df06b04588, 99.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

initial import of a failover-aware AMQP client courtesy of Circonus

  • Property mode set to 100644
Line 
1 #include <stdlib.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <errno.h>
5 #include <arpa/inet.h> /* ntohl, htonl, ntohs, htons */
6
7 #include "amqp.h"
8 #include "amqp_framing.h"
9 #include "amqp_private.h"
10
11 char const *amqp_method_name(amqp_method_number_t methodNumber) {
12   switch (methodNumber) {
13     case AMQP_CONNECTION_START_METHOD: return "AMQP_CONNECTION_START_METHOD";
14     case AMQP_CONNECTION_START_OK_METHOD: return "AMQP_CONNECTION_START_OK_METHOD";
15     case AMQP_CONNECTION_SECURE_METHOD: return "AMQP_CONNECTION_SECURE_METHOD";
16     case AMQP_CONNECTION_SECURE_OK_METHOD: return "AMQP_CONNECTION_SECURE_OK_METHOD";
17     case AMQP_CONNECTION_TUNE_METHOD: return "AMQP_CONNECTION_TUNE_METHOD";
18     case AMQP_CONNECTION_TUNE_OK_METHOD: return "AMQP_CONNECTION_TUNE_OK_METHOD";
19     case AMQP_CONNECTION_OPEN_METHOD: return "AMQP_CONNECTION_OPEN_METHOD";
20     case AMQP_CONNECTION_OPEN_OK_METHOD: return "AMQP_CONNECTION_OPEN_OK_METHOD";
21     case AMQP_CONNECTION_REDIRECT_METHOD: return "AMQP_CONNECTION_REDIRECT_METHOD";
22     case AMQP_CONNECTION_CLOSE_METHOD: return "AMQP_CONNECTION_CLOSE_METHOD";
23     case AMQP_CONNECTION_CLOSE_OK_METHOD: return "AMQP_CONNECTION_CLOSE_OK_METHOD";
24     case AMQP_CHANNEL_OPEN_METHOD: return "AMQP_CHANNEL_OPEN_METHOD";
25     case AMQP_CHANNEL_OPEN_OK_METHOD: return "AMQP_CHANNEL_OPEN_OK_METHOD";
26     case AMQP_CHANNEL_FLOW_METHOD: return "AMQP_CHANNEL_FLOW_METHOD";
27     case AMQP_CHANNEL_FLOW_OK_METHOD: return "AMQP_CHANNEL_FLOW_OK_METHOD";
28     case AMQP_CHANNEL_ALERT_METHOD: return "AMQP_CHANNEL_ALERT_METHOD";
29     case AMQP_CHANNEL_CLOSE_METHOD: return "AMQP_CHANNEL_CLOSE_METHOD";
30     case AMQP_CHANNEL_CLOSE_OK_METHOD: return "AMQP_CHANNEL_CLOSE_OK_METHOD";
31     case AMQP_ACCESS_REQUEST_METHOD: return "AMQP_ACCESS_REQUEST_METHOD";
32     case AMQP_ACCESS_REQUEST_OK_METHOD: return "AMQP_ACCESS_REQUEST_OK_METHOD";
33     case AMQP_EXCHANGE_DECLARE_METHOD: return "AMQP_EXCHANGE_DECLARE_METHOD";
34     case AMQP_EXCHANGE_DECLARE_OK_METHOD: return "AMQP_EXCHANGE_DECLARE_OK_METHOD";
35     case AMQP_EXCHANGE_DELETE_METHOD: return "AMQP_EXCHANGE_DELETE_METHOD";
36     case AMQP_EXCHANGE_DELETE_OK_METHOD: return "AMQP_EXCHANGE_DELETE_OK_METHOD";
37     case AMQP_QUEUE_DECLARE_METHOD: return "AMQP_QUEUE_DECLARE_METHOD";
38     case AMQP_QUEUE_DECLARE_OK_METHOD: return "AMQP_QUEUE_DECLARE_OK_METHOD";
39     case AMQP_QUEUE_BIND_METHOD: return "AMQP_QUEUE_BIND_METHOD";
40     case AMQP_QUEUE_BIND_OK_METHOD: return "AMQP_QUEUE_BIND_OK_METHOD";
41     case AMQP_QUEUE_PURGE_METHOD: return "AMQP_QUEUE_PURGE_METHOD";
42     case AMQP_QUEUE_PURGE_OK_METHOD: return "AMQP_QUEUE_PURGE_OK_METHOD";
43     case AMQP_QUEUE_DELETE_METHOD: return "AMQP_QUEUE_DELETE_METHOD";
44     case AMQP_QUEUE_DELETE_OK_METHOD: return "AMQP_QUEUE_DELETE_OK_METHOD";
45     case AMQP_QUEUE_UNBIND_METHOD: return "AMQP_QUEUE_UNBIND_METHOD";
46     case AMQP_QUEUE_UNBIND_OK_METHOD: return "AMQP_QUEUE_UNBIND_OK_METHOD";
47     case AMQP_BASIC_QOS_METHOD: return "AMQP_BASIC_QOS_METHOD";
48     case AMQP_BASIC_QOS_OK_METHOD: return "AMQP_BASIC_QOS_OK_METHOD";
49     case AMQP_BASIC_CONSUME_METHOD: return "AMQP_BASIC_CONSUME_METHOD";
50     case AMQP_BASIC_CONSUME_OK_METHOD: return "AMQP_BASIC_CONSUME_OK_METHOD";
51     case AMQP_BASIC_CANCEL_METHOD: return "AMQP_BASIC_CANCEL_METHOD";
52     case AMQP_BASIC_CANCEL_OK_METHOD: return "AMQP_BASIC_CANCEL_OK_METHOD";
53     case AMQP_BASIC_PUBLISH_METHOD: return "AMQP_BASIC_PUBLISH_METHOD";
54     case AMQP_BASIC_RETURN_METHOD: return "AMQP_BASIC_RETURN_METHOD";
55     case AMQP_BASIC_DELIVER_METHOD: return "AMQP_BASIC_DELIVER_METHOD";
56     case AMQP_BASIC_GET_METHOD: return "AMQP_BASIC_GET_METHOD";
57     case AMQP_BASIC_GET_OK_METHOD: return "AMQP_BASIC_GET_OK_METHOD";
58     case AMQP_BASIC_GET_EMPTY_METHOD: return "AMQP_BASIC_GET_EMPTY_METHOD";
59     case AMQP_BASIC_ACK_METHOD: return "AMQP_BASIC_ACK_METHOD";
60     case AMQP_BASIC_REJECT_METHOD: return "AMQP_BASIC_REJECT_METHOD";
61     case AMQP_BASIC_RECOVER_METHOD: return "AMQP_BASIC_RECOVER_METHOD";
62     case AMQP_FILE_QOS_METHOD: return "AMQP_FILE_QOS_METHOD";
63     case AMQP_FILE_QOS_OK_METHOD: return "AMQP_FILE_QOS_OK_METHOD";
64     case AMQP_FILE_CONSUME_METHOD: return "AMQP_FILE_CONSUME_METHOD";
65     case AMQP_FILE_CONSUME_OK_METHOD: return "AMQP_FILE_CONSUME_OK_METHOD";
66     case AMQP_FILE_CANCEL_METHOD: return "AMQP_FILE_CANCEL_METHOD";
67     case AMQP_FILE_CANCEL_OK_METHOD: return "AMQP_FILE_CANCEL_OK_METHOD";
68     case AMQP_FILE_OPEN_METHOD: return "AMQP_FILE_OPEN_METHOD";
69     case AMQP_FILE_OPEN_OK_METHOD: return "AMQP_FILE_OPEN_OK_METHOD";
70     case AMQP_FILE_STAGE_METHOD: return "AMQP_FILE_STAGE_METHOD";
71     case AMQP_FILE_PUBLISH_METHOD: return "AMQP_FILE_PUBLISH_METHOD";
72     case AMQP_FILE_RETURN_METHOD: return "AMQP_FILE_RETURN_METHOD";
73     case AMQP_FILE_DELIVER_METHOD: return "AMQP_FILE_DELIVER_METHOD";
74     case AMQP_FILE_ACK_METHOD: return "AMQP_FILE_ACK_METHOD";
75     case AMQP_FILE_REJECT_METHOD: return "AMQP_FILE_REJECT_METHOD";
76     case AMQP_STREAM_QOS_METHOD: return "AMQP_STREAM_QOS_METHOD";
77     case AMQP_STREAM_QOS_OK_METHOD: return "AMQP_STREAM_QOS_OK_METHOD";
78     case AMQP_STREAM_CONSUME_METHOD: return "AMQP_STREAM_CONSUME_METHOD";
79     case AMQP_STREAM_CONSUME_OK_METHOD: return "AMQP_STREAM_CONSUME_OK_METHOD";
80     case AMQP_STREAM_CANCEL_METHOD: return "AMQP_STREAM_CANCEL_METHOD";
81     case AMQP_STREAM_CANCEL_OK_METHOD: return "AMQP_STREAM_CANCEL_OK_METHOD";
82     case AMQP_STREAM_PUBLISH_METHOD: return "AMQP_STREAM_PUBLISH_METHOD";
83     case AMQP_STREAM_RETURN_METHOD: return "AMQP_STREAM_RETURN_METHOD";
84     case AMQP_STREAM_DELIVER_METHOD: return "AMQP_STREAM_DELIVER_METHOD";
85     case AMQP_TX_SELECT_METHOD: return "AMQP_TX_SELECT_METHOD";
86     case AMQP_TX_SELECT_OK_METHOD: return "AMQP_TX_SELECT_OK_METHOD";
87     case AMQP_TX_COMMIT_METHOD: return "AMQP_TX_COMMIT_METHOD";
88     case AMQP_TX_COMMIT_OK_METHOD: return "AMQP_TX_COMMIT_OK_METHOD";
89     case AMQP_TX_ROLLBACK_METHOD: return "AMQP_TX_ROLLBACK_METHOD";
90     case AMQP_TX_ROLLBACK_OK_METHOD: return "AMQP_TX_ROLLBACK_OK_METHOD";
91     case AMQP_DTX_SELECT_METHOD: return "AMQP_DTX_SELECT_METHOD";
92     case AMQP_DTX_SELECT_OK_METHOD: return "AMQP_DTX_SELECT_OK_METHOD";
93     case AMQP_DTX_START_METHOD: return "AMQP_DTX_START_METHOD";
94     case AMQP_DTX_START_OK_METHOD: return "AMQP_DTX_START_OK_METHOD";
95     case AMQP_TUNNEL_REQUEST_METHOD: return "AMQP_TUNNEL_REQUEST_METHOD";
96     case AMQP_TEST_INTEGER_METHOD: return "AMQP_TEST_INTEGER_METHOD";
97     case AMQP_TEST_INTEGER_OK_METHOD: return "AMQP_TEST_INTEGER_OK_METHOD";
98     case AMQP_TEST_STRING_METHOD: return "AMQP_TEST_STRING_METHOD";
99     case AMQP_TEST_STRING_OK_METHOD: return "AMQP_TEST_STRING_OK_METHOD";
100     case AMQP_TEST_TABLE_METHOD: return "AMQP_TEST_TABLE_METHOD";
101     case AMQP_TEST_TABLE_OK_METHOD: return "AMQP_TEST_TABLE_OK_METHOD";
102     case AMQP_TEST_CONTENT_METHOD: return "AMQP_TEST_CONTENT_METHOD";
103     case AMQP_TEST_CONTENT_OK_METHOD: return "AMQP_TEST_CONTENT_OK_METHOD";
104     default: return NULL;
105   }
106 }
107
108 amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber) {
109   switch (methodNumber) {
110     case AMQP_BASIC_PUBLISH_METHOD: return 1;
111     case AMQP_BASIC_RETURN_METHOD: return 1;
112     case AMQP_BASIC_DELIVER_METHOD: return 1;
113     case AMQP_BASIC_GET_OK_METHOD: return 1;
114     case AMQP_FILE_STAGE_METHOD: return 1;
115     case AMQP_FILE_RETURN_METHOD: return 1;
116     case AMQP_STREAM_PUBLISH_METHOD: return 1;
117     case AMQP_STREAM_RETURN_METHOD: return 1;
118     case AMQP_STREAM_DELIVER_METHOD: return 1;
119     case AMQP_TUNNEL_REQUEST_METHOD: return 1;
120     case AMQP_TEST_CONTENT_METHOD: return 1;
121     case AMQP_TEST_CONTENT_OK_METHOD: return 1;
122     default: return 0;
123   }
124 }
125
126 int amqp_decode_method(amqp_method_number_t methodNumber,
127                        amqp_pool_t *pool,
128                        amqp_bytes_t encoded,
129                        void **decoded)
130 {
131   int offset = 0;
132   int table_result;
133   uint8_t bit_buffer;
134
135   switch (methodNumber) {
136     case AMQP_CONNECTION_START_METHOD: {
137       amqp_connection_start_t *m = (amqp_connection_start_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_start_t));
138       m->version_major = D_8(encoded, offset);
139       offset++;
140       m->version_minor = D_8(encoded, offset);
141       offset++;
142       table_result = amqp_decode_table(encoded, pool, &(m->server_properties), &offset);
143       AMQP_CHECK_RESULT(table_result);
144       m->mechanisms.len = D_32(encoded, offset);
145       offset += 4;
146       m->mechanisms.bytes = D_BYTES(encoded, offset, m->mechanisms.len);
147       offset += m->mechanisms.len;
148       m->locales.len = D_32(encoded, offset);
149       offset += 4;
150       m->locales.bytes = D_BYTES(encoded, offset, m->locales.len);
151       offset += m->locales.len;
152       *decoded = m;
153       return 0;
154     }
155     case AMQP_CONNECTION_START_OK_METHOD: {
156       amqp_connection_start_ok_t *m = (amqp_connection_start_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_start_ok_t));
157       table_result = amqp_decode_table(encoded, pool, &(m->client_properties), &offset);
158       AMQP_CHECK_RESULT(table_result);
159       m->mechanism.len = D_8(encoded, offset);
160       offset++;
161       m->mechanism.bytes = D_BYTES(encoded, offset, m->mechanism.len);
162       offset += m->mechanism.len;
163       m->response.len = D_32(encoded, offset);
164       offset += 4;
165       m->response.bytes = D_BYTES(encoded, offset, m->response.len);
166       offset += m->response.len;
167       m->locale.len = D_8(encoded, offset);
168       offset++;
169       m->locale.bytes = D_BYTES(encoded, offset, m->locale.len);
170       offset += m->locale.len;
171       *decoded = m;
172       return 0;
173     }
174     case AMQP_CONNECTION_SECURE_METHOD: {
175       amqp_connection_secure_t *m = (amqp_connection_secure_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_secure_t));
176       m->challenge.len = D_32(encoded, offset);
177       offset += 4;
178       m->challenge.bytes = D_BYTES(encoded, offset, m->challenge.len);
179       offset += m->challenge.len;
180       *decoded = m;
181       return 0;
182     }
183     case AMQP_CONNECTION_SECURE_OK_METHOD: {
184       amqp_connection_secure_ok_t *m = (amqp_connection_secure_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_secure_ok_t));
185       m->response.len = D_32(encoded, offset);
186       offset += 4;
187       m->response.bytes = D_BYTES(encoded, offset, m->response.len);
188       offset += m->response.len;
189       *decoded = m;
190       return 0;
191     }
192     case AMQP_CONNECTION_TUNE_METHOD: {
193       amqp_connection_tune_t *m = (amqp_connection_tune_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_tune_t));
194       m->channel_max = D_16(encoded, offset);
195       offset += 2;
196       m->frame_max = D_32(encoded, offset);
197       offset += 4;
198       m->heartbeat = D_16(encoded, offset);
199       offset += 2;
200       *decoded = m;
201       return 0;
202     }
203     case AMQP_CONNECTION_TUNE_OK_METHOD: {
204       amqp_connection_tune_ok_t *m = (amqp_connection_tune_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_tune_ok_t));
205       m->channel_max = D_16(encoded, offset);
206       offset += 2;
207       m->frame_max = D_32(encoded, offset);
208       offset += 4;
209       m->heartbeat = D_16(encoded, offset);
210       offset += 2;
211       *decoded = m;
212       return 0;
213     }
214     case AMQP_CONNECTION_OPEN_METHOD: {
215       amqp_connection_open_t *m = (amqp_connection_open_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_open_t));
216       m->virtual_host.len = D_8(encoded, offset);
217       offset++;
218       m->virtual_host.bytes = D_BYTES(encoded, offset, m->virtual_host.len);
219       offset += m->virtual_host.len;
220       m->capabilities.len = D_8(encoded, offset);
221       offset++;
222       m->capabilities.bytes = D_BYTES(encoded, offset, m->capabilities.len);
223       offset += m->capabilities.len;
224       bit_buffer = D_8(encoded, offset);
225       offset++;
226       m->insist = (bit_buffer & (1 << 0)) ? 1 : 0;
227       *decoded = m;
228       return 0;
229     }
230     case AMQP_CONNECTION_OPEN_OK_METHOD: {
231       amqp_connection_open_ok_t *m = (amqp_connection_open_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_open_ok_t));
232       m->known_hosts.len = D_8(encoded, offset);
233       offset++;
234       m->known_hosts.bytes = D_BYTES(encoded, offset, m->known_hosts.len);
235       offset += m->known_hosts.len;
236       *decoded = m;
237       return 0;
238     }
239     case AMQP_CONNECTION_REDIRECT_METHOD: {
240       amqp_connection_redirect_t *m = (amqp_connection_redirect_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_redirect_t));
241       m->host.len = D_8(encoded, offset);
242       offset++;
243       m->host.bytes = D_BYTES(encoded, offset, m->host.len);
244       offset += m->host.len;
245       m->known_hosts.len = D_8(encoded, offset);
246       offset++;
247       m->known_hosts.bytes = D_BYTES(encoded, offset, m->known_hosts.len);
248       offset += m->known_hosts.len;
249       *decoded = m;
250       return 0;
251     }
252     case AMQP_CONNECTION_CLOSE_METHOD: {
253       amqp_connection_close_t *m = (amqp_connection_close_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_close_t));
254       m->reply_code = D_16(encoded, offset);
255       offset += 2;
256       m->reply_text.len = D_8(encoded, offset);
257       offset++;
258       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
259       offset += m->reply_text.len;
260       m->class_id = D_16(encoded, offset);
261       offset += 2;
262       m->method_id = D_16(encoded, offset);
263       offset += 2;
264       *decoded = m;
265       return 0;
266     }
267     case AMQP_CONNECTION_CLOSE_OK_METHOD: {
268       amqp_connection_close_ok_t *m = (amqp_connection_close_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_close_ok_t));
269       *decoded = m;
270       return 0;
271     }
272     case AMQP_CHANNEL_OPEN_METHOD: {
273       amqp_channel_open_t *m = (amqp_channel_open_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_open_t));
274       m->out_of_band.len = D_8(encoded, offset);
275       offset++;
276       m->out_of_band.bytes = D_BYTES(encoded, offset, m->out_of_band.len);
277       offset += m->out_of_band.len;
278       *decoded = m;
279       return 0;
280     }
281     case AMQP_CHANNEL_OPEN_OK_METHOD: {
282       amqp_channel_open_ok_t *m = (amqp_channel_open_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_open_ok_t));
283       *decoded = m;
284       return 0;
285     }
286     case AMQP_CHANNEL_FLOW_METHOD: {
287       amqp_channel_flow_t *m = (amqp_channel_flow_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_flow_t));
288       bit_buffer = D_8(encoded, offset);
289       offset++;
290       m->active = (bit_buffer & (1 << 0)) ? 1 : 0;
291       *decoded = m;
292       return 0;
293     }
294     case AMQP_CHANNEL_FLOW_OK_METHOD: {
295       amqp_channel_flow_ok_t *m = (amqp_channel_flow_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_flow_ok_t));
296       bit_buffer = D_8(encoded, offset);
297       offset++;
298       m->active = (bit_buffer & (1 << 0)) ? 1 : 0;
299       *decoded = m;
300       return 0;
301     }
302     case AMQP_CHANNEL_ALERT_METHOD: {
303       amqp_channel_alert_t *m = (amqp_channel_alert_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_alert_t));
304       m->reply_code = D_16(encoded, offset);
305       offset += 2;
306       m->reply_text.len = D_8(encoded, offset);
307       offset++;
308       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
309       offset += m->reply_text.len;
310       table_result = amqp_decode_table(encoded, pool, &(m->details), &offset);
311       AMQP_CHECK_RESULT(table_result);
312       *decoded = m;
313       return 0;
314     }
315     case AMQP_CHANNEL_CLOSE_METHOD: {
316       amqp_channel_close_t *m = (amqp_channel_close_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_close_t));
317       m->reply_code = D_16(encoded, offset);
318       offset += 2;
319       m->reply_text.len = D_8(encoded, offset);
320       offset++;
321       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
322       offset += m->reply_text.len;
323       m->class_id = D_16(encoded, offset);
324       offset += 2;
325       m->method_id = D_16(encoded, offset);
326       offset += 2;
327       *decoded = m;
328       return 0;
329     }
330     case AMQP_CHANNEL_CLOSE_OK_METHOD: {
331       amqp_channel_close_ok_t *m = (amqp_channel_close_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_close_ok_t));
332       *decoded = m;
333       return 0;
334     }
335     case AMQP_ACCESS_REQUEST_METHOD: {
336       amqp_access_request_t *m = (amqp_access_request_t *) amqp_pool_alloc(pool, sizeof(amqp_access_request_t));
337       m->realm.len = D_8(encoded, offset);
338       offset++;
339       m->realm.bytes = D_BYTES(encoded, offset, m->realm.len);
340       offset += m->realm.len;
341       bit_buffer = D_8(encoded, offset);
342       offset++;
343       m->exclusive = (bit_buffer & (1 << 0)) ? 1 : 0;
344       m->passive = (bit_buffer & (1 << 1)) ? 1 : 0;
345       m->active = (bit_buffer & (1 << 2)) ? 1 : 0;
346       m->write = (bit_buffer & (1 << 3)) ? 1 : 0;
347       m->read = (bit_buffer & (1 << 4)) ? 1 : 0;
348       *decoded = m;
349       return 0;
350     }
351     case AMQP_ACCESS_REQUEST_OK_METHOD: {
352       amqp_access_request_ok_t *m = (amqp_access_request_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_access_request_ok_t));
353       m->ticket = D_16(encoded, offset);
354       offset += 2;
355       *decoded = m;
356       return 0;
357     }
358     case AMQP_EXCHANGE_DECLARE_METHOD: {
359       amqp_exchange_declare_t *m = (amqp_exchange_declare_t *) amqp_pool_alloc(pool, sizeof(amqp_exchange_declare_t));
360       m->ticket = D_16(encoded, offset);
361       offset += 2;
362       m->exchange.len = D_8(encoded, offset);
363       offset++;
364       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
365       offset += m->exchange.len;
366       m->type.len = D_8(encoded, offset);
367       offset++;
368       m->type.bytes = D_BYTES(encoded, offset, m->type.len);
369       offset += m->type.len;
370       bit_buffer = D_8(encoded, offset);
371       offset++;
372       m->passive = (bit_buffer & (1 << 0)) ? 1 : 0;
373       m->durable = (bit_buffer & (1 << 1)) ? 1 : 0;
374       m->auto_delete = (bit_buffer & (1 << 2)) ? 1 : 0;
375       m->internal = (bit_buffer & (1 << 3)) ? 1 : 0;
376       m->nowait = (bit_buffer & (1 << 4)) ? 1 : 0;
377       table_result = amqp_decode_table(encoded, pool, &(m->arguments), &offset);
378       AMQP_CHECK_RESULT(table_result);
379       *decoded = m;
380       return 0;
381     }
382     case AMQP_EXCHANGE_DECLARE_OK_METHOD: {
383       amqp_exchange_declare_ok_t *m = (amqp_exchange_declare_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_exchange_declare_ok_t));
384       *decoded = m;
385       return 0;
386     }
387     case AMQP_EXCHANGE_DELETE_METHOD: {
388       amqp_exchange_delete_t *m = (amqp_exchange_delete_t *) amqp_pool_alloc(pool, sizeof(amqp_exchange_delete_t));
389       m->ticket = D_16(encoded, offset);
390       offset += 2;
391       m->exchange.len = D_8(encoded, offset);
392       offset++;
393       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
394       offset += m->exchange.len;
395       bit_buffer = D_8(encoded, offset);
396       offset++;
397       m->if_unused = (bit_buffer & (1 << 0)) ? 1 : 0;
398       m->nowait = (bit_buffer & (1 << 1)) ? 1 : 0;
399       *decoded = m;
400       return 0;
401     }
402     case AMQP_EXCHANGE_DELETE_OK_METHOD: {
403       amqp_exchange_delete_ok_t *m = (amqp_exchange_delete_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_exchange_delete_ok_t));
404       *decoded = m;
405       return 0;
406     }
407     case AMQP_QUEUE_DECLARE_METHOD: {
408       amqp_queue_declare_t *m = (amqp_queue_declare_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_declare_t));
409       m->ticket = D_16(encoded, offset);
410       offset += 2;
411       m->queue.len = D_8(encoded, offset);
412       offset++;
413       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
414       offset += m->queue.len;
415       bit_buffer = D_8(encoded, offset);
416       offset++;
417       m->passive = (bit_buffer & (1 << 0)) ? 1 : 0;
418       m->durable = (bit_buffer & (1 << 1)) ? 1 : 0;
419       m->exclusive = (bit_buffer & (1 << 2)) ? 1 : 0;
420       m->auto_delete = (bit_buffer & (1 << 3)) ? 1 : 0;
421       m->nowait = (bit_buffer & (1 << 4)) ? 1 : 0;
422       table_result = amqp_decode_table(encoded, pool, &(m->arguments), &offset);
423       AMQP_CHECK_RESULT(table_result);
424       *decoded = m;
425       return 0;
426     }
427     case AMQP_QUEUE_DECLARE_OK_METHOD: {
428       amqp_queue_declare_ok_t *m = (amqp_queue_declare_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_declare_ok_t));
429       m->queue.len = D_8(encoded, offset);
430       offset++;
431       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
432       offset += m->queue.len;
433       m->message_count = D_32(encoded, offset);
434       offset += 4;
435       m->consumer_count = D_32(encoded, offset);
436       offset += 4;
437       *decoded = m;
438       return 0;
439     }
440     case AMQP_QUEUE_BIND_METHOD: {
441       amqp_queue_bind_t *m = (amqp_queue_bind_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_bind_t));
442       m->ticket = D_16(encoded, offset);
443       offset += 2;
444       m->queue.len = D_8(encoded, offset);
445       offset++;
446       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
447       offset += m->queue.len;
448       m->exchange.len = D_8(encoded, offset);
449       offset++;
450       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
451       offset += m->exchange.len;
452       m->routing_key.len = D_8(encoded, offset);
453       offset++;
454       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
455       offset += m->routing_key.len;
456       bit_buffer = D_8(encoded, offset);
457       offset++;
458       m->nowait = (bit_buffer & (1 << 0)) ? 1 : 0;
459       table_result = amqp_decode_table(encoded, pool, &(m->arguments), &offset);
460       AMQP_CHECK_RESULT(table_result);
461       *decoded = m;
462       return 0;
463     }
464     case AMQP_QUEUE_BIND_OK_METHOD: {
465       amqp_queue_bind_ok_t *m = (amqp_queue_bind_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_bind_ok_t));
466       *decoded = m;
467       return 0;
468     }
469     case AMQP_QUEUE_PURGE_METHOD: {
470       amqp_queue_purge_t *m = (amqp_queue_purge_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_purge_t));
471       m->ticket = D_16(encoded, offset);
472       offset += 2;
473       m->queue.len = D_8(encoded, offset);
474       offset++;
475       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
476       offset += m->queue.len;
477       bit_buffer = D_8(encoded, offset);
478       offset++;
479       m->nowait = (bit_buffer & (1 << 0)) ? 1 : 0;
480       *decoded = m;
481       return 0;
482     }
483     case AMQP_QUEUE_PURGE_OK_METHOD: {
484       amqp_queue_purge_ok_t *m = (amqp_queue_purge_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_purge_ok_t));
485       m->message_count = D_32(encoded, offset);
486       offset += 4;
487       *decoded = m;
488       return 0;
489     }
490     case AMQP_QUEUE_DELETE_METHOD: {
491       amqp_queue_delete_t *m = (amqp_queue_delete_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_delete_t));
492       m->ticket = D_16(encoded, offset);
493       offset += 2;
494       m->queue.len = D_8(encoded, offset);
495       offset++;
496       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
497       offset += m->queue.len;
498       bit_buffer = D_8(encoded, offset);
499       offset++;
500       m->if_unused = (bit_buffer & (1 << 0)) ? 1 : 0;
501       m->if_empty = (bit_buffer & (1 << 1)) ? 1 : 0;
502       m->nowait = (bit_buffer & (1 << 2)) ? 1 : 0;
503       *decoded = m;
504       return 0;
505     }
506     case AMQP_QUEUE_DELETE_OK_METHOD: {
507       amqp_queue_delete_ok_t *m = (amqp_queue_delete_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_delete_ok_t));
508       m->message_count = D_32(encoded, offset);
509       offset += 4;
510       *decoded = m;
511       return 0;
512     }
513     case AMQP_QUEUE_UNBIND_METHOD: {
514       amqp_queue_unbind_t *m = (amqp_queue_unbind_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_unbind_t));
515       m->ticket = D_16(encoded, offset);
516       offset += 2;
517       m->queue.len = D_8(encoded, offset);
518       offset++;
519       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
520       offset += m->queue.len;
521       m->exchange.len = D_8(encoded, offset);
522       offset++;
523       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
524       offset += m->exchange.len;
525       m->routing_key.len = D_8(encoded, offset);
526       offset++;
527       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
528       offset += m->routing_key.len;
529       table_result = amqp_decode_table(encoded, pool, &(m->arguments), &offset);
530       AMQP_CHECK_RESULT(table_result);
531       *decoded = m;
532       return 0;
533     }
534     case AMQP_QUEUE_UNBIND_OK_METHOD: {
535       amqp_queue_unbind_ok_t *m = (amqp_queue_unbind_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_unbind_ok_t));
536       *decoded = m;
537       return 0;
538     }
539     case AMQP_BASIC_QOS_METHOD: {
540       amqp_basic_qos_t *m = (amqp_basic_qos_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_qos_t));
541       m->prefetch_size = D_32(encoded, offset);
542       offset += 4;
543       m->prefetch_count = D_16(encoded, offset);
544       offset += 2;
545       bit_buffer = D_8(encoded, offset);
546       offset++;
547       m->global = (bit_buffer & (1 << 0)) ? 1 : 0;
548       *decoded = m;
549       return 0;
550     }
551     case AMQP_BASIC_QOS_OK_METHOD: {
552       amqp_basic_qos_ok_t *m = (amqp_basic_qos_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_qos_ok_t));
553       *decoded = m;
554       return 0;
555     }
556     case AMQP_BASIC_CONSUME_METHOD: {
557       amqp_basic_consume_t *m = (amqp_basic_consume_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_consume_t));
558       m->ticket = D_16(encoded, offset);
559       offset += 2;
560       m->queue.len = D_8(encoded, offset);
561       offset++;
562       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
563       offset += m->queue.len;
564       m->consumer_tag.len = D_8(encoded, offset);
565       offset++;
566       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
567       offset += m->consumer_tag.len;
568       bit_buffer = D_8(encoded, offset);
569       offset++;
570       m->no_local = (bit_buffer & (1 << 0)) ? 1 : 0;
571       m->no_ack = (bit_buffer & (1 << 1)) ? 1 : 0;
572       m->exclusive = (bit_buffer & (1 << 2)) ? 1 : 0;
573       m->nowait = (bit_buffer & (1 << 3)) ? 1 : 0;
574       *decoded = m;
575       return 0;
576     }
577     case AMQP_BASIC_CONSUME_OK_METHOD: {
578       amqp_basic_consume_ok_t *m = (amqp_basic_consume_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_consume_ok_t));
579       m->consumer_tag.len = D_8(encoded, offset);
580       offset++;
581       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
582       offset += m->consumer_tag.len;
583       *decoded = m;
584       return 0;
585     }
586     case AMQP_BASIC_CANCEL_METHOD: {
587       amqp_basic_cancel_t *m = (amqp_basic_cancel_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_cancel_t));
588       m->consumer_tag.len = D_8(encoded, offset);
589       offset++;
590       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
591       offset += m->consumer_tag.len;
592       bit_buffer = D_8(encoded, offset);
593       offset++;
594       m->nowait = (bit_buffer & (1 << 0)) ? 1 : 0;
595       *decoded = m;
596       return 0;
597     }
598     case AMQP_BASIC_CANCEL_OK_METHOD: {
599       amqp_basic_cancel_ok_t *m = (amqp_basic_cancel_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_cancel_ok_t));
600       m->consumer_tag.len = D_8(encoded, offset);
601       offset++;
602       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
603       offset += m->consumer_tag.len;
604       *decoded = m;
605       return 0;
606     }
607     case AMQP_BASIC_PUBLISH_METHOD: {
608       amqp_basic_publish_t *m = (amqp_basic_publish_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_publish_t));
609       m->ticket = D_16(encoded, offset);
610       offset += 2;
611       m->exchange.len = D_8(encoded, offset);
612       offset++;
613       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
614       offset += m->exchange.len;
615       m->routing_key.len = D_8(encoded, offset);
616       offset++;
617       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
618       offset += m->routing_key.len;
619       bit_buffer = D_8(encoded, offset);
620       offset++;
621       m->mandatory = (bit_buffer & (1 << 0)) ? 1 : 0;
622       m->immediate = (bit_buffer & (1 << 1)) ? 1 : 0;
623       *decoded = m;
624       return 0;
625     }
626     case AMQP_BASIC_RETURN_METHOD: {
627       amqp_basic_return_t *m = (amqp_basic_return_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_return_t));
628       m->reply_code = D_16(encoded, offset);
629       offset += 2;
630       m->reply_text.len = D_8(encoded, offset);
631       offset++;
632       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
633       offset += m->reply_text.len;
634       m->exchange.len = D_8(encoded, offset);
635       offset++;
636       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
637       offset += m->exchange.len;
638       m->routing_key.len = D_8(encoded, offset);
639       offset++;
640       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
641       offset += m->routing_key.len;
642       *decoded = m;
643       return 0;
644     }
645     case AMQP_BASIC_DELIVER_METHOD: {
646       amqp_basic_deliver_t *m = (amqp_basic_deliver_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_deliver_t));
647       m->consumer_tag.len = D_8(encoded, offset);
648       offset++;
649       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
650       offset += m->consumer_tag.len;
651       m->delivery_tag = D_64(encoded, offset);
652       offset += 8;
653       bit_buffer = D_8(encoded, offset);
654       offset++;
655       m->redelivered = (bit_buffer & (1 << 0)) ? 1 : 0;
656       m->exchange.len = D_8(encoded, offset);
657       offset++;
658       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
659       offset += m->exchange.len;
660       m->routing_key.len = D_8(encoded, offset);
661       offset++;
662       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
663       offset += m->routing_key.len;
664       *decoded = m;
665       return 0;
666     }
667     case AMQP_BASIC_GET_METHOD: {
668       amqp_basic_get_t *m = (amqp_basic_get_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_get_t));
669       m->ticket = D_16(encoded, offset);
670       offset += 2;
671       m->queue.len = D_8(encoded, offset);
672       offset++;
673       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
674       offset += m->queue.len;
675       bit_buffer = D_8(encoded, offset);
676       offset++;
677       m->no_ack = (bit_buffer & (1 << 0)) ? 1 : 0;
678       *decoded = m;
679       return 0;
680     }
681     case AMQP_BASIC_GET_OK_METHOD: {
682       amqp_basic_get_ok_t *m = (amqp_basic_get_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_get_ok_t));
683       m->delivery_tag = D_64(encoded, offset);
684       offset += 8;
685       bit_buffer = D_8(encoded, offset);
686       offset++;
687       m->redelivered = (bit_buffer & (1 << 0)) ? 1 : 0;
688       m->exchange.len = D_8(encoded, offset);
689       offset++;
690       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
691       offset += m->exchange.len;
692       m->routing_key.len = D_8(encoded, offset);
693       offset++;
694       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
695       offset += m->routing_key.len;
696       m->message_count = D_32(encoded, offset);
697       offset += 4;
698       *decoded = m;
699       return 0;
700     }
701     case AMQP_BASIC_GET_EMPTY_METHOD: {
702       amqp_basic_get_empty_t *m = (amqp_basic_get_empty_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_get_empty_t));
703       m->cluster_id.len = D_8(encoded, offset);
704       offset++;
705       m->cluster_id.bytes = D_BYTES(encoded, offset, m->cluster_id.len);
706       offset += m->cluster_id.len;
707       *decoded = m;
708       return 0;
709     }
710     case AMQP_BASIC_ACK_METHOD: {
711       amqp_basic_ack_t *m = (amqp_basic_ack_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_ack_t));
712       m->delivery_tag = D_64(encoded, offset);
713       offset += 8;
714       bit_buffer = D_8(encoded, offset);
715       offset++;
716       m->multiple = (bit_buffer & (1 << 0)) ? 1 : 0;
717       *decoded = m;
718       return 0;
719     }
720     case AMQP_BASIC_REJECT_METHOD: {
721       amqp_basic_reject_t *m = (amqp_basic_reject_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_reject_t));
722       m->delivery_tag = D_64(encoded, offset);
723       offset += 8;
724       bit_buffer = D_8(encoded, offset);
725       offset++;
726       m->requeue = (bit_buffer & (1 << 0)) ? 1 : 0;
727       *decoded = m;
728       return 0;
729     }
730     case AMQP_BASIC_RECOVER_METHOD: {
731       amqp_basic_recover_t *m = (amqp_basic_recover_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_recover_t));
732       bit_buffer = D_8(encoded, offset);
733       offset++;
734       m->requeue = (bit_buffer & (1 << 0)) ? 1 : 0;
735       *decoded = m;
736       return 0;
737     }
738     case AMQP_FILE_QOS_METHOD: {
739       amqp_file_qos_t *m = (amqp_file_qos_t *) amqp_pool_alloc(pool, sizeof(amqp_file_qos_t));
740       m->prefetch_size = D_32(encoded, offset);
741       offset += 4;
742       m->prefetch_count = D_16(encoded, offset);
743       offset += 2;
744       bit_buffer = D_8(encoded, offset);
745       offset++;
746       m->global = (bit_buffer & (1 << 0)) ? 1 : 0;
747       *decoded = m;
748       return 0;
749     }
750     case AMQP_FILE_QOS_OK_METHOD: {
751       amqp_file_qos_ok_t *m = (amqp_file_qos_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_file_qos_ok_t));
752       *decoded = m;
753       return 0;
754     }
755     case AMQP_FILE_CONSUME_METHOD: {
756       amqp_file_consume_t *m = (amqp_file_consume_t *) amqp_pool_alloc(pool, sizeof(amqp_file_consume_t));
757       m->ticket = D_16(encoded, offset);
758       offset += 2;
759       m->queue.len = D_8(encoded, offset);
760       offset++;
761       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
762       offset += m->queue.len;
763       m->consumer_tag.len = D_8(encoded, offset);
764       offset++;
765       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
766       offset += m->consumer_tag.len;
767       bit_buffer = D_8(encoded, offset);
768       offset++;
769       m->no_local = (bit_buffer & (1 << 0)) ? 1 : 0;
770       m->no_ack = (bit_buffer & (1 << 1)) ? 1 : 0;
771       m->exclusive = (bit_buffer & (1 << 2)) ? 1 : 0;
772       m->nowait = (bit_buffer & (1 << 3)) ? 1 : 0;
773       *decoded = m;
774       return 0;
775     }
776     case AMQP_FILE_CONSUME_OK_METHOD: {
777       amqp_file_consume_ok_t *m = (amqp_file_consume_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_file_consume_ok_t));
778       m->consumer_tag.len = D_8(encoded, offset);
779       offset++;
780       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
781       offset += m->consumer_tag.len;
782       *decoded = m;
783       return 0;
784     }
785     case AMQP_FILE_CANCEL_METHOD: {
786       amqp_file_cancel_t *m = (amqp_file_cancel_t *) amqp_pool_alloc(pool, sizeof(amqp_file_cancel_t));
787       m->consumer_tag.len = D_8(encoded, offset);
788       offset++;
789       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
790       offset += m->consumer_tag.len;
791       bit_buffer = D_8(encoded, offset);
792       offset++;
793       m->nowait = (bit_buffer & (1 << 0)) ? 1 : 0;
794       *decoded = m;
795       return 0;
796     }
797     case AMQP_FILE_CANCEL_OK_METHOD: {
798       amqp_file_cancel_ok_t *m = (amqp_file_cancel_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_file_cancel_ok_t));
799       m->consumer_tag.len = D_8(encoded, offset);
800       offset++;
801       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
802       offset += m->consumer_tag.len;
803       *decoded = m;
804       return 0;
805     }
806     case AMQP_FILE_OPEN_METHOD: {
807       amqp_file_open_t *m = (amqp_file_open_t *) amqp_pool_alloc(pool, sizeof(amqp_file_open_t));
808       m->identifier.len = D_8(encoded, offset);
809       offset++;
810       m->identifier.bytes = D_BYTES(encoded, offset, m->identifier.len);
811       offset += m->identifier.len;
812       m->content_size = D_64(encoded, offset);
813       offset += 8;
814       *decoded = m;
815       return 0;
816     }
817     case AMQP_FILE_OPEN_OK_METHOD: {
818       amqp_file_open_ok_t *m = (amqp_file_open_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_file_open_ok_t));
819       m->staged_size = D_64(encoded, offset);
820       offset += 8;
821       *decoded = m;
822       return 0;
823     }
824     case AMQP_FILE_STAGE_METHOD: {
825       amqp_file_stage_t *m = (amqp_file_stage_t *) amqp_pool_alloc(pool, sizeof(amqp_file_stage_t));
826       *decoded = m;
827       return 0;
828     }
829     case AMQP_FILE_PUBLISH_METHOD: {
830       amqp_file_publish_t *m = (amqp_file_publish_t *) amqp_pool_alloc(pool, sizeof(amqp_file_publish_t));
831       m->ticket = D_16(encoded, offset);
832       offset += 2;
833       m->exchange.len = D_8(encoded, offset);
834       offset++;
835       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
836       offset += m->exchange.len;
837       m->routing_key.len = D_8(encoded, offset);
838       offset++;
839       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
840       offset += m->routing_key.len;
841       bit_buffer = D_8(encoded, offset);
842       offset++;
843       m->mandatory = (bit_buffer & (1 << 0)) ? 1 : 0;
844       m->immediate = (bit_buffer & (1 << 1)) ? 1 : 0;
845       m->identifier.len = D_8(encoded, offset);
846       offset++;
847       m->identifier.bytes = D_BYTES(encoded, offset, m->identifier.len);
848       offset += m->identifier.len;
849       *decoded = m;
850       return 0;
851     }
852     case AMQP_FILE_RETURN_METHOD: {
853       amqp_file_return_t *m = (amqp_file_return_t *) amqp_pool_alloc(pool, sizeof(amqp_file_return_t));
854       m->reply_code = D_16(encoded, offset);
855       offset += 2;
856       m->reply_text.len = D_8(encoded, offset);
857       offset++;
858       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
859       offset += m->reply_text.len;
860       m->exchange.len = D_8(encoded, offset);
861       offset++;
862       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
863       offset += m->exchange.len;
864       m->routing_key.len = D_8(encoded, offset);
865       offset++;
866       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
867       offset += m->routing_key.len;
868       *decoded = m;
869       return 0;
870     }
871     case AMQP_FILE_DELIVER_METHOD: {
872       amqp_file_deliver_t *m = (amqp_file_deliver_t *) amqp_pool_alloc(pool, sizeof(amqp_file_deliver_t));
873       m->consumer_tag.len = D_8(encoded, offset);
874       offset++;
875       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
876       offset += m->consumer_tag.len;
877       m->delivery_tag = D_64(encoded, offset);
878       offset += 8;
879       bit_buffer = D_8(encoded, offset);
880       offset++;
881       m->redelivered = (bit_buffer & (1 << 0)) ? 1 : 0;
882       m->exchange.len = D_8(encoded, offset);
883       offset++;
884       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
885       offset += m->exchange.len;
886       m->routing_key.len = D_8(encoded, offset);
887       offset++;
888       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
889       offset += m->routing_key.len;
890       m->identifier.len = D_8(encoded, offset);
891       offset++;
892       m->identifier.bytes = D_BYTES(encoded, offset, m->identifier.len);
893       offset += m->identifier.len;
894       *decoded = m;
895       return 0;
896     }
897     case AMQP_FILE_ACK_METHOD: {
898       amqp_file_ack_t *m = (amqp_file_ack_t *) amqp_pool_alloc(pool, sizeof(amqp_file_ack_t));
899       m->delivery_tag = D_64(encoded, offset);
900       offset += 8;
901       bit_buffer = D_8(encoded, offset);
902       offset++;
903       m->multiple = (bit_buffer & (1 << 0)) ? 1 : 0;
904       *decoded = m;
905       return 0;
906     }
907     case AMQP_FILE_REJECT_METHOD: {
908       amqp_file_reject_t *m = (amqp_file_reject_t *) amqp_pool_alloc(pool, sizeof(amqp_file_reject_t));
909       m->delivery_tag = D_64(encoded, offset);
910       offset += 8;
911       bit_buffer = D_8(encoded, offset);
912       offset++;
913       m->requeue = (bit_buffer & (1 << 0)) ? 1 : 0;
914       *decoded = m;
915       return 0;
916     }
917     case AMQP_STREAM_QOS_METHOD: {
918       amqp_stream_qos_t *m = (amqp_stream_qos_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_qos_t));
919       m->prefetch_size = D_32(encoded, offset);
920       offset += 4;
921       m->prefetch_count = D_16(encoded, offset);
922       offset += 2;
923       m->consume_rate = D_32(encoded, offset);
924       offset += 4;
925       bit_buffer = D_8(encoded, offset);
926       offset++;
927       m->global = (bit_buffer & (1 << 0)) ? 1 : 0;
928       *decoded = m;
929       return 0;
930     }
931     case AMQP_STREAM_QOS_OK_METHOD: {
932       amqp_stream_qos_ok_t *m = (amqp_stream_qos_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_qos_ok_t));
933       *decoded = m;
934       return 0;
935     }
936     case AMQP_STREAM_CONSUME_METHOD: {
937       amqp_stream_consume_t *m = (amqp_stream_consume_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_consume_t));
938       m->ticket = D_16(encoded, offset);
939       offset += 2;
940       m->queue.len = D_8(encoded, offset);
941       offset++;
942       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
943       offset += m->queue.len;
944       m->consumer_tag.len = D_8(encoded, offset);
945       offset++;
946       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
947       offset += m->consumer_tag.len;
948       bit_buffer = D_8(encoded, offset);
949       offset++;
950       m->no_local = (bit_buffer & (1 << 0)) ? 1 : 0;
951       m->exclusive = (bit_buffer & (1 << 1)) ? 1 : 0;
952       m->nowait = (bit_buffer & (1 << 2)) ? 1 : 0;
953       *decoded = m;
954       return 0;
955     }
956     case AMQP_STREAM_CONSUME_OK_METHOD: {
957       amqp_stream_consume_ok_t *m = (amqp_stream_consume_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_consume_ok_t));
958       m->consumer_tag.len = D_8(encoded, offset);
959       offset++;
960       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
961       offset += m->consumer_tag.len;
962       *decoded = m;
963       return 0;
964     }
965     case AMQP_STREAM_CANCEL_METHOD: {
966       amqp_stream_cancel_t *m = (amqp_stream_cancel_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_cancel_t));
967       m->consumer_tag.len = D_8(encoded, offset);
968       offset++;
969       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
970       offset += m->consumer_tag.len;
971       bit_buffer = D_8(encoded, offset);
972       offset++;
973       m->nowait = (bit_buffer & (1 << 0)) ? 1 : 0;
974       *decoded = m;
975       return 0;
976     }
977     case AMQP_STREAM_CANCEL_OK_METHOD: {
978       amqp_stream_cancel_ok_t *m = (amqp_stream_cancel_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_cancel_ok_t));
979       m->consumer_tag.len = D_8(encoded, offset);
980       offset++;
981       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
982       offset += m->consumer_tag.len;
983       *decoded = m;
984       return 0;
985     }
986     case AMQP_STREAM_PUBLISH_METHOD: {
987       amqp_stream_publish_t *m = (amqp_stream_publish_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_publish_t));
988       m->ticket = D_16(encoded, offset);
989       offset += 2;
990       m->exchange.len = D_8(encoded, offset);
991       offset++;
992       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
993       offset += m->exchange.len;
994       m->routing_key.len = D_8(encoded, offset);
995       offset++;
996       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
997       offset += m->routing_key.len;
998       bit_buffer = D_8(encoded, offset);
999       offset++;
1000       m->mandatory = (bit_buffer & (1 << 0)) ? 1 : 0;
1001       m->immediate = (bit_buffer & (1 << 1)) ? 1 : 0;
1002       *decoded = m;
1003       return 0;
1004     }
1005     case AMQP_STREAM_RETURN_METHOD: {
1006       amqp_stream_return_t *m = (amqp_stream_return_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_return_t));
1007       m->reply_code = D_16(encoded, offset);
1008       offset += 2;
1009       m->reply_text.len = D_8(encoded, offset);
1010       offset++;
1011       m->reply_text.bytes = D_BYTES(encoded, offset, m->reply_text.len);
1012       offset += m->reply_text.len;
1013       m->exchange.len = D_8(encoded, offset);
1014       offset++;
1015       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
1016       offset += m->exchange.len;
1017       m->routing_key.len = D_8(encoded, offset);
1018       offset++;
1019       m->routing_key.bytes = D_BYTES(encoded, offset, m->routing_key.len);
1020       offset += m->routing_key.len;
1021       *decoded = m;
1022       return 0;
1023     }
1024     case AMQP_STREAM_DELIVER_METHOD: {
1025       amqp_stream_deliver_t *m = (amqp_stream_deliver_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_deliver_t));
1026       m->consumer_tag.len = D_8(encoded, offset);
1027       offset++;
1028       m->consumer_tag.bytes = D_BYTES(encoded, offset, m->consumer_tag.len);
1029       offset += m->consumer_tag.len;
1030       m->delivery_tag = D_64(encoded, offset);
1031       offset += 8;
1032       m->exchange.len = D_8(encoded, offset);
1033       offset++;
1034       m->exchange.bytes = D_BYTES(encoded, offset, m->exchange.len);
1035       offset += m->exchange.len;
1036       m->queue.len = D_8(encoded, offset);
1037       offset++;
1038       m->queue.bytes = D_BYTES(encoded, offset, m->queue.len);
1039       offset += m->queue.len;
1040       *decoded = m;
1041       return 0;
1042     }
1043     case AMQP_TX_SELECT_METHOD: {
1044       amqp_tx_select_t *m = (amqp_tx_select_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_select_t));
1045       *decoded = m;
1046       return 0;
1047     }
1048     case AMQP_TX_SELECT_OK_METHOD: {
1049       amqp_tx_select_ok_t *m = (amqp_tx_select_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_select_ok_t));
1050       *decoded = m;
1051       return 0;
1052     }
1053     case AMQP_TX_COMMIT_METHOD: {
1054       amqp_tx_commit_t *m = (amqp_tx_commit_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_commit_t));
1055       *decoded = m;
1056       return 0;
1057     }
1058     case AMQP_TX_COMMIT_OK_METHOD: {
1059       amqp_tx_commit_ok_t *m = (amqp_tx_commit_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_commit_ok_t));
1060       *decoded = m;
1061       return 0;
1062     }
1063     case AMQP_TX_ROLLBACK_METHOD: {
1064       amqp_tx_rollback_t *m = (amqp_tx_rollback_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_rollback_t));
1065       *decoded = m;
1066       return 0;
1067     }
1068     case AMQP_TX_ROLLBACK_OK_METHOD: {
1069       amqp_tx_rollback_ok_t *m = (amqp_tx_rollback_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_rollback_ok_t));
1070       *decoded = m;
1071       return 0;
1072     }
1073     case AMQP_DTX_SELECT_METHOD: {
1074       amqp_dtx_select_t *m = (amqp_dtx_select_t *) amqp_pool_alloc(pool, sizeof(amqp_dtx_select_t));
1075       *decoded = m;
1076       return 0;
1077     }
1078     case AMQP_DTX_SELECT_OK_METHOD: {
1079       amqp_dtx_select_ok_t *m = (amqp_dtx_select_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_dtx_select_ok_t));
1080       *decoded = m;
1081       return 0;
1082     }
1083     case AMQP_DTX_START_METHOD: {
1084       amqp_dtx_start_t *m = (amqp_dtx_start_t *) amqp_pool_alloc(pool, sizeof(amqp_dtx_start_t));
1085       m->dtx_identifier.len = D_8(encoded, offset);
1086       offset++;
1087       m->dtx_identifier.bytes = D_BYTES(encoded, offset, m->dtx_identifier.len);
1088       offset += m->dtx_identifier.len;
1089       *decoded = m;
1090       return 0;
1091     }
1092     case AMQP_DTX_START_OK_METHOD: {
1093       amqp_dtx_start_ok_t *m = (amqp_dtx_start_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_dtx_start_ok_t));
1094       *decoded = m;
1095       return 0;
1096     }
1097     case AMQP_TUNNEL_REQUEST_METHOD: {
1098       amqp_tunnel_request_t *m = (amqp_tunnel_request_t *) amqp_pool_alloc(pool, sizeof(amqp_tunnel_request_t));
1099       table_result = amqp_decode_table(encoded, pool, &(m->meta_data), &offset);
1100       AMQP_CHECK_RESULT(table_result);
1101       *decoded = m;
1102       return 0;
1103     }
1104     case AMQP_TEST_INTEGER_METHOD: {
1105       amqp_test_integer_t *m = (amqp_test_integer_t *) amqp_pool_alloc(pool, sizeof(amqp_test_integer_t));
1106       m->integer_1 = D_8(encoded, offset);
1107       offset++;
1108       m->integer_2 = D_16(encoded, offset);
1109       offset += 2;
1110       m->integer_3 = D_32(encoded, offset);
1111       offset += 4;
1112       m->integer_4 = D_64(encoded, offset);
1113       offset += 8;
1114       m->operation = D_8(encoded, offset);
1115       offset++;
1116       *decoded = m;
1117       return 0;
1118     }
1119     case AMQP_TEST_INTEGER_OK_METHOD: {
1120       amqp_test_integer_ok_t *m = (amqp_test_integer_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_test_integer_ok_t));
1121       m->result = D_64(encoded, offset);
1122       offset += 8;
1123       *decoded = m;
1124       return 0;
1125     }
1126     case AMQP_TEST_STRING_METHOD: {
1127       amqp_test_string_t *m = (amqp_test_string_t *) amqp_pool_alloc(pool, sizeof(amqp_test_string_t));
1128       m->string_1.len = D_8(encoded, offset);
1129       offset++;
1130       m->string_1.bytes = D_BYTES(encoded, offset, m->string_1.len);
1131       offset += m->string_1.len;
1132       m->string_2.len = D_32(encoded, offset);
1133       offset += 4;
1134       m->string_2.bytes = D_BYTES(encoded, offset, m->string_2.len);
1135       offset += m->string_2.len;
1136       m->operation = D_8(encoded, offset);
1137       offset++;
1138       *decoded = m;
1139       return 0;
1140     }
1141     case AMQP_TEST_STRING_OK_METHOD: {
1142       amqp_test_string_ok_t *m = (amqp_test_string_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_test_string_ok_t));
1143       m->result.len = D_32(encoded, offset);
1144       offset += 4;
1145       m->result.bytes = D_BYTES(encoded, offset, m->result.len);
1146       offset += m->result.len;
1147       *decoded = m;
1148       return 0;
1149     }
1150     case AMQP_TEST_TABLE_METHOD: {
1151       amqp_test_table_t *m = (amqp_test_table_t *) amqp_pool_alloc(pool, sizeof(amqp_test_table_t));
1152       table_result = amqp_decode_table(encoded, pool, &(m->table), &offset);
1153       AMQP_CHECK_RESULT(table_result);
1154       m->integer_op = D_8(encoded, offset);
1155       offset++;
1156       m->string_op = D_8(encoded, offset);
1157       offset++;
1158       *decoded = m;
1159       return 0;
1160     }
1161     case AMQP_TEST_TABLE_OK_METHOD: {
1162       amqp_test_table_ok_t *m = (amqp_test_table_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_test_table_ok_t));
1163       m->integer_result = D_64(encoded, offset);
1164       offset += 8;
1165       m->string_result.len = D_32(encoded, offset);
1166       offset += 4;
1167       m->string_result.bytes = D_BYTES(encoded, offset, m->string_result.len);
1168       offset += m->string_result.len;
1169       *decoded = m;
1170       return 0;
1171     }
1172     case AMQP_TEST_CONTENT_METHOD: {
1173       amqp_test_content_t *m = (amqp_test_content_t *) amqp_pool_alloc(pool, sizeof(amqp_test_content_t));
1174       *decoded = m;
1175       return 0;
1176     }
1177     case AMQP_TEST_CONTENT_OK_METHOD: {
1178       amqp_test_content_ok_t *m = (amqp_test_content_ok_t *) amqp_pool_alloc(pool, sizeof(amqp_test_content_ok_t));
1179       m->content_checksum = D_32(encoded, offset);
1180       offset += 4;
1181       *decoded = m;
1182       return 0;
1183     }
1184     default: return -ENOENT;
1185   }
1186 }
1187
1188 int amqp_decode_properties(uint16_t class_id,
1189                            amqp_pool_t *pool,
1190                            amqp_bytes_t encoded,
1191                            void **decoded)
1192 {
1193   int offset = 0;
1194   int table_result;
1195
1196   amqp_flags_t flags = 0;
1197   int flagword_index = 0;
1198   amqp_flags_t partial_flags;
1199
1200   do {
1201     partial_flags = D_16(encoded, offset);
1202     offset += 2;
1203     flags |= (partial_flags << (flagword_index * 16));
1204     flagword_index++;
1205   } while (partial_flags & 1);
1206
1207   switch (class_id) {
1208     case 10: {
1209       amqp_connection_properties_t *p = (amqp_connection_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_connection_properties_t));
1210       p->_flags = flags;
1211       *decoded = p;
1212       return 0;
1213     }
1214     case 20: {
1215       amqp_channel_properties_t *p = (amqp_channel_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_channel_properties_t));
1216       p->_flags = flags;
1217       *decoded = p;
1218       return 0;
1219     }
1220     case 30: {
1221       amqp_access_properties_t *p = (amqp_access_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_access_properties_t));
1222       p->_flags = flags;
1223       *decoded = p;
1224       return 0;
1225     }
1226     case 40: {
1227       amqp_exchange_properties_t *p = (amqp_exchange_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_exchange_properties_t));
1228       p->_flags = flags;
1229       *decoded = p;
1230       return 0;
1231     }
1232     case 50: {
1233       amqp_queue_properties_t *p = (amqp_queue_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_queue_properties_t));
1234       p->_flags = flags;
1235       *decoded = p;
1236       return 0;
1237     }
1238     case 60: {
1239       amqp_basic_properties_t *p = (amqp_basic_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_basic_properties_t));
1240       p->_flags = flags;
1241       if (flags & AMQP_BASIC_CONTENT_TYPE_FLAG) {
1242         p->content_type.len = D_8(encoded, offset);
1243         offset++;
1244         p->content_type.bytes = D_BYTES(encoded, offset, p->content_type.len);
1245         offset += p->content_type.len;
1246       }
1247       if (flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) {
1248         p->content_encoding.len = D_8(encoded, offset);
1249         offset++;
1250         p->content_encoding.bytes = D_BYTES(encoded, offset, p->content_encoding.len);
1251         offset += p->content_encoding.len;
1252       }
1253       if (flags & AMQP_BASIC_HEADERS_FLAG) {
1254         table_result = amqp_decode_table(encoded, pool, &(p->headers), &offset);
1255         AMQP_CHECK_RESULT(table_result);
1256       }
1257       if (flags & AMQP_BASIC_DELIVERY_MODE_FLAG) {
1258         p->delivery_mode = D_8(encoded, offset);
1259         offset++;
1260       }
1261       if (flags & AMQP_BASIC_PRIORITY_FLAG) {
1262         p->priority = D_8(encoded, offset);
1263         offset++;
1264       }
1265       if (flags & AMQP_BASIC_CORRELATION_ID_FLAG) {
1266         p->correlation_id.len = D_8(encoded, offset);
1267         offset++;
1268         p->correlation_id.bytes = D_BYTES(encoded, offset, p->correlation_id.len);
1269         offset += p->correlation_id.len;
1270       }
1271       if (flags & AMQP_BASIC_REPLY_TO_FLAG) {
1272         p->reply_to.len = D_8(encoded, offset);
1273         offset++;
1274         p->reply_to.bytes = D_BYTES(encoded, offset, p->reply_to.len);
1275         offset += p->reply_to.len;
1276       }
1277       if (flags & AMQP_BASIC_EXPIRATION_FLAG) {
1278         p->expiration.len = D_8(encoded, offset);
1279         offset++;
1280         p->expiration.bytes = D_BYTES(encoded, offset, p->expiration.len);
1281         offset += p->expiration.len;
1282       }
1283       if (flags & AMQP_BASIC_MESSAGE_ID_FLAG) {
1284         p->message_id.len = D_8(encoded, offset);
1285         offset++;
1286         p->message_id.bytes = D_BYTES(encoded, offset, p->message_id.len);
1287         offset += p->message_id.len;
1288       }
1289       if (flags & AMQP_BASIC_TIMESTAMP_FLAG) {
1290         p->timestamp = D_64(encoded, offset);
1291         offset += 8;
1292       }
1293       if (flags & AMQP_BASIC_TYPE_FLAG) {
1294         p->type.len = D_8(encoded, offset);
1295         offset++;
1296         p->type.bytes = D_BYTES(encoded, offset, p->type.len);
1297         offset += p->type.len;
1298       }
1299       if (flags & AMQP_BASIC_USER_ID_FLAG) {
1300         p->user_id.len = D_8(encoded, offset);
1301         offset++;
1302         p->user_id.bytes = D_BYTES(encoded, offset, p->user_id.len);
1303         offset += p->user_id.len;
1304       }
1305       if (flags & AMQP_BASIC_APP_ID_FLAG) {
1306         p->app_id.len = D_8(encoded, offset);
1307         offset++;
1308         p->app_id.bytes = D_BYTES(encoded, offset, p->app_id.len);
1309         offset += p->app_id.len;
1310       }
1311       if (flags & AMQP_BASIC_CLUSTER_ID_FLAG) {
1312         p->cluster_id.len = D_8(encoded, offset);
1313         offset++;
1314         p->cluster_id.bytes = D_BYTES(encoded, offset, p->cluster_id.len);
1315         offset += p->cluster_id.len;
1316       }
1317       *decoded = p;
1318       return 0;
1319     }
1320     case 70: {
1321       amqp_file_properties_t *p = (amqp_file_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_file_properties_t));
1322       p->_flags = flags;
1323       if (flags & AMQP_FILE_CONTENT_TYPE_FLAG) {
1324         p->content_type.len = D_8(encoded, offset);
1325         offset++;
1326         p->content_type.bytes = D_BYTES(encoded, offset, p->content_type.len);
1327         offset += p->content_type.len;
1328       }
1329       if (flags & AMQP_FILE_CONTENT_ENCODING_FLAG) {
1330         p->content_encoding.len = D_8(encoded, offset);
1331         offset++;
1332         p->content_encoding.bytes = D_BYTES(encoded, offset, p->content_encoding.len);
1333         offset += p->content_encoding.len;
1334       }
1335       if (flags & AMQP_FILE_HEADERS_FLAG) {
1336         table_result = amqp_decode_table(encoded, pool, &(p->headers), &offset);
1337         AMQP_CHECK_RESULT(table_result);
1338       }
1339       if (flags & AMQP_FILE_PRIORITY_FLAG) {
1340         p->priority = D_8(encoded, offset);
1341         offset++;
1342       }
1343       if (flags & AMQP_FILE_REPLY_TO_FLAG) {
1344         p->reply_to.len = D_8(encoded, offset);
1345         offset++;
1346         p->reply_to.bytes = D_BYTES(encoded, offset, p->reply_to.len);
1347         offset += p->reply_to.len;
1348       }
1349       if (flags & AMQP_FILE_MESSAGE_ID_FLAG) {
1350         p->message_id.len = D_8(encoded, offset);
1351         offset++;
1352         p->message_id.bytes = D_BYTES(encoded, offset, p->message_id.len);
1353         offset += p->message_id.len;
1354       }
1355       if (flags & AMQP_FILE_FILENAME_FLAG) {
1356         p->filename.len = D_8(encoded, offset);
1357         offset++;
1358         p->filename.bytes = D_BYTES(encoded, offset, p->filename.len);
1359         offset += p->filename.len;
1360       }
1361       if (flags & AMQP_FILE_TIMESTAMP_FLAG) {
1362         p->timestamp = D_64(encoded, offset);
1363         offset += 8;
1364       }
1365       if (flags & AMQP_FILE_CLUSTER_ID_FLAG) {
1366         p->cluster_id.len = D_8(encoded, offset);
1367         offset++;
1368         p->cluster_id.bytes = D_BYTES(encoded, offset, p->cluster_id.len);
1369         offset += p->cluster_id.len;
1370       }
1371       *decoded = p;
1372       return 0;
1373     }
1374     case 80: {
1375       amqp_stream_properties_t *p = (amqp_stream_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_stream_properties_t));
1376       p->_flags = flags;
1377       if (flags & AMQP_STREAM_CONTENT_TYPE_FLAG) {
1378         p->content_type.len = D_8(encoded, offset);
1379         offset++;
1380         p->content_type.bytes = D_BYTES(encoded, offset, p->content_type.len);
1381         offset += p->content_type.len;
1382       }
1383       if (flags & AMQP_STREAM_CONTENT_ENCODING_FLAG) {
1384         p->content_encoding.len = D_8(encoded, offset);
1385         offset++;
1386         p->content_encoding.bytes = D_BYTES(encoded, offset, p->content_encoding.len);
1387         offset += p->content_encoding.len;
1388       }
1389       if (flags & AMQP_STREAM_HEADERS_FLAG) {
1390         table_result = amqp_decode_table(encoded, pool, &(p->headers), &offset);
1391         AMQP_CHECK_RESULT(table_result);
1392       }
1393       if (flags & AMQP_STREAM_PRIORITY_FLAG) {
1394         p->priority = D_8(encoded, offset);
1395         offset++;
1396       }
1397       if (flags & AMQP_STREAM_TIMESTAMP_FLAG) {
1398         p->timestamp = D_64(encoded, offset);
1399         offset += 8;
1400       }
1401       *decoded = p;
1402       return 0;
1403     }
1404     case 90: {
1405       amqp_tx_properties_t *p = (amqp_tx_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_tx_properties_t));
1406       p->_flags = flags;
1407       *decoded = p;
1408       return 0;
1409     }
1410     case 100: {
1411       amqp_dtx_properties_t *p = (amqp_dtx_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_dtx_properties_t));
1412       p->_flags = flags;
1413       *decoded = p;
1414       return 0;
1415     }
1416     case 110: {
1417       amqp_tunnel_properties_t *p = (amqp_tunnel_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_tunnel_properties_t));
1418       p->_flags = flags;
1419       if (flags & AMQP_TUNNEL_HEADERS_FLAG) {
1420         table_result = amqp_decode_table(encoded, pool, &(p->headers), &offset);
1421         AMQP_CHECK_RESULT(table_result);
1422       }
1423       if (flags & AMQP_TUNNEL_PROXY_NAME_FLAG) {
1424         p->proxy_name.len = D_8(encoded, offset);
1425         offset++;
1426         p->proxy_name.bytes = D_BYTES(encoded, offset, p->proxy_name.len);
1427         offset += p->proxy_name.len;
1428       }
1429       if (flags & AMQP_TUNNEL_DATA_NAME_FLAG) {
1430         p->data_name.len = D_8(encoded, offset);
1431         offset++;
1432         p->data_name.bytes = D_BYTES(encoded, offset, p->data_name.len);
1433         offset += p->data_name.len;
1434       }
1435       if (flags & AMQP_TUNNEL_DURABLE_FLAG) {
1436         p->durable = D_8(encoded, offset);
1437         offset++;
1438       }
1439       if (flags & AMQP_TUNNEL_BROADCAST_FLAG) {
1440         p->broadcast = D_8(encoded, offset);
1441         offset++;
1442       }
1443       *decoded = p;
1444       return 0;
1445     }
1446     case 120: {
1447       amqp_test_properties_t *p = (amqp_test_properties_t *) amqp_pool_alloc(pool, sizeof(amqp_test_properties_t));
1448       p->_flags = flags;
1449       *decoded = p;
1450       return 0;
1451     }
1452     default: return -ENOENT;
1453   }
1454 }
1455
1456 int amqp_encode_method(amqp_method_number_t methodNumber,
1457                        void *decoded,
1458                        amqp_bytes_t encoded)
1459 {
1460   int offset = 0;
1461   int table_result;
1462   uint8_t bit_buffer;
1463
1464   switch (methodNumber) {
1465     case AMQP_CONNECTION_START_METHOD: {
1466       amqp_connection_start_t *m = (amqp_connection_start_t *) decoded;
1467       E_8(encoded, offset, m->version_major);
1468       offset++;
1469       E_8(encoded, offset, m->version_minor);
1470       offset++;
1471       table_result = amqp_encode_table(encoded, &(m->server_properties), &offset);
1472       if (table_result < 0) return table_result;
1473       E_32(encoded, offset, m->mechanisms.len);
1474       offset += 4;
1475       E_BYTES(encoded, offset, m->mechanisms.len, m->mechanisms.bytes);
1476       offset += m->mechanisms.len;
1477       E_32(encoded, offset, m->locales.len);
1478       offset += 4;
1479       E_BYTES(encoded, offset, m->locales.len, m->locales.bytes);
1480       offset += m->locales.len;
1481       return offset;
1482     }
1483     case AMQP_CONNECTION_START_OK_METHOD: {
1484       amqp_connection_start_ok_t *m = (amqp_connection_start_ok_t *) decoded;
1485       table_result = amqp_encode_table(encoded, &(m->client_properties), &offset);
1486       if (table_result < 0) return table_result;
1487       E_8(encoded, offset, m->mechanism.len);
1488       offset++;
1489       E_BYTES(encoded, offset, m->mechanism.len, m->mechanism.bytes);
1490       offset += m->mechanism.len;
1491       E_32(encoded, offset, m->response.len);
1492       offset += 4;
1493       E_BYTES(encoded, offset, m->response.len, m->response.bytes);
1494       offset += m->response.len;
1495       E_8(encoded, offset, m->locale.len);
1496       offset++;
1497       E_BYTES(encoded, offset, m->locale.len, m->locale.bytes);
1498       offset += m->locale.len;
1499       return offset;
1500     }
1501     case AMQP_CONNECTION_SECURE_METHOD: {
1502       amqp_connection_secure_t *m = (amqp_connection_secure_t *) decoded;
1503       E_32(encoded, offset, m->challenge.len);
1504       offset += 4;
1505       E_BYTES(encoded, offset, m->challenge.len, m->challenge.bytes);
1506       offset += m->challenge.len;
1507       return offset;
1508     }
1509     case AMQP_CONNECTION_SECURE_OK_METHOD: {
1510       amqp_connection_secure_ok_t *m = (amqp_connection_secure_ok_t *) decoded;
1511       E_32(encoded, offset, m->response.len);
1512       offset += 4;
1513       E_BYTES(encoded, offset, m->response.len, m->response.bytes);
1514       offset += m->response.len;
1515       return offset;
1516     }
1517     case AMQP_CONNECTION_TUNE_METHOD: {
1518       amqp_connection_tune_t *m = (amqp_connection_tune_t *) decoded;
1519       E_16(encoded, offset, m->channel_max);
1520       offset += 2;
1521       E_32(encoded, offset, m->frame_max);
1522       offset += 4;
1523       E_16(encoded, offset, m->heartbeat);
1524       offset += 2;
1525       return offset;
1526     }
1527     case AMQP_CONNECTION_TUNE_OK_METHOD: {
1528       amqp_connection_tune_ok_t *m = (amqp_connection_tune_ok_t *) decoded;
1529       E_16(encoded, offset, m->channel_max);
1530       offset += 2;
1531       E_32(encoded, offset, m->frame_max);
1532       offset += 4;
1533       E_16(encoded, offset, m->heartbeat);
1534       offset += 2;
1535       return offset;
1536     }
1537     case AMQP_CONNECTION_OPEN_METHOD: {
1538       amqp_connection_open_t *m = (amqp_connection_open_t *) decoded;
1539       E_8(encoded, offset, m->virtual_host.len);
1540       offset++;
1541       E_BYTES(encoded, offset, m->virtual_host.len, m->virtual_host.bytes);
1542       offset += m->virtual_host.len;
1543       E_8(encoded, offset, m->capabilities.len);
1544       offset++;
1545       E_BYTES(encoded, offset, m->capabilities.len, m->capabilities.bytes);
1546       offset += m->capabilities.len;
1547       bit_buffer = 0;
1548       if (m->insist) { bit_buffer |= (1 << 0); }
1549       E_8(encoded, offset, bit_buffer);
1550       offset++;
1551       return offset;
1552     }
1553     case AMQP_CONNECTION_OPEN_OK_METHOD: {
1554       amqp_connection_open_ok_t *m = (amqp_connection_open_ok_t *) decoded;
1555       E_8(encoded, offset, m->known_hosts.len);
1556       offset++;
1557       E_BYTES(encoded, offset, m->known_hosts.len, m->known_hosts.bytes);
1558       offset += m->known_hosts.len;
1559       return offset;
1560     }
1561     case AMQP_CONNECTION_REDIRECT_METHOD: {
1562       amqp_connection_redirect_t *m = (amqp_connection_redirect_t *) decoded;
1563       E_8(encoded, offset, m->host.len);
1564       offset++;
1565       E_BYTES(encoded, offset, m->host.len, m->host.bytes);
1566       offset += m->host.len;
1567       E_8(encoded, offset, m->known_hosts.len);
1568       offset++;
1569       E_BYTES(encoded, offset, m->known_hosts.len, m->known_hosts.bytes);
1570       offset += m->known_hosts.len;
1571       return offset;
1572     }
1573     case AMQP_CONNECTION_CLOSE_METHOD: {
1574       amqp_connection_close_t *m = (amqp_connection_close_t *) decoded;
1575       E_16(encoded, offset, m->reply_code);
1576       offset += 2;
1577       E_8(encoded, offset, m->reply_text.len);
1578       offset++;
1579       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
1580       offset += m->reply_text.len;
1581       E_16(encoded, offset, m->class_id);
1582       offset += 2;
1583       E_16(encoded, offset, m->method_id);
1584       offset += 2;
1585       return offset;
1586     }
1587     case AMQP_CONNECTION_CLOSE_OK_METHOD: {
1588       return offset;
1589     }
1590     case AMQP_CHANNEL_OPEN_METHOD: {
1591       amqp_channel_open_t *m = (amqp_channel_open_t *) decoded;
1592       E_8(encoded, offset, m->out_of_band.len);
1593       offset++;
1594       E_BYTES(encoded, offset, m->out_of_band.len, m->out_of_band.bytes);
1595       offset += m->out_of_band.len;
1596       return offset;
1597     }
1598     case AMQP_CHANNEL_OPEN_OK_METHOD: {
1599       return offset;
1600     }
1601     case AMQP_CHANNEL_FLOW_METHOD: {
1602       amqp_channel_flow_t *m = (amqp_channel_flow_t *) decoded;
1603       bit_buffer = 0;
1604       if (m->active) { bit_buffer |= (1 << 0); }
1605       E_8(encoded, offset, bit_buffer);
1606       offset++;
1607       return offset;
1608     }
1609     case AMQP_CHANNEL_FLOW_OK_METHOD: {
1610       amqp_channel_flow_ok_t *m = (amqp_channel_flow_ok_t *) decoded;
1611       bit_buffer = 0;
1612       if (m->active) { bit_buffer |= (1 << 0); }
1613       E_8(encoded, offset, bit_buffer);
1614       offset++;
1615       return offset;
1616     }
1617     case AMQP_CHANNEL_ALERT_METHOD: {
1618       amqp_channel_alert_t *m = (amqp_channel_alert_t *) decoded;
1619       E_16(encoded, offset, m->reply_code);
1620       offset += 2;
1621       E_8(encoded, offset, m->reply_text.len);
1622       offset++;
1623       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
1624       offset += m->reply_text.len;
1625       table_result = amqp_encode_table(encoded, &(m->details), &offset);
1626       if (table_result < 0) return table_result;
1627       return offset;
1628     }
1629     case AMQP_CHANNEL_CLOSE_METHOD: {
1630       amqp_channel_close_t *m = (amqp_channel_close_t *) decoded;
1631       E_16(encoded, offset, m->reply_code);
1632       offset += 2;
1633       E_8(encoded, offset, m->reply_text.len);
1634       offset++;
1635       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
1636       offset += m->reply_text.len;
1637       E_16(encoded, offset, m->class_id);
1638       offset += 2;
1639       E_16(encoded, offset, m->method_id);
1640       offset += 2;
1641       return offset;
1642     }
1643     case AMQP_CHANNEL_CLOSE_OK_METHOD: {
1644       return offset;
1645     }
1646     case AMQP_ACCESS_REQUEST_METHOD: {
1647       amqp_access_request_t *m = (amqp_access_request_t *) decoded;
1648       E_8(encoded, offset, m->realm.len);
1649       offset++;
1650       E_BYTES(encoded, offset, m->realm.len, m->realm.bytes);
1651       offset += m->realm.len;
1652       bit_buffer = 0;
1653       if (m->exclusive) { bit_buffer |= (1 << 0); }
1654       if (m->passive) { bit_buffer |= (1 << 1); }
1655       if (m->active) { bit_buffer |= (1 << 2); }
1656       if (m->write) { bit_buffer |= (1 << 3); }
1657       if (m->read) { bit_buffer |= (1 << 4); }
1658       E_8(encoded, offset, bit_buffer);
1659       offset++;
1660       return offset;
1661     }
1662     case AMQP_ACCESS_REQUEST_OK_METHOD: {
1663       amqp_access_request_ok_t *m = (amqp_access_request_ok_t *) decoded;
1664       E_16(encoded, offset, m->ticket);
1665       offset += 2;
1666       return offset;
1667     }
1668     case AMQP_EXCHANGE_DECLARE_METHOD: {
1669       amqp_exchange_declare_t *m = (amqp_exchange_declare_t *) decoded;
1670       E_16(encoded, offset, m->ticket);
1671       offset += 2;
1672       E_8(encoded, offset, m->exchange.len);
1673       offset++;
1674       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1675       offset += m->exchange.len;
1676       E_8(encoded, offset, m->type.len);
1677       offset++;
1678       E_BYTES(encoded, offset, m->type.len, m->type.bytes);
1679       offset += m->type.len;
1680       bit_buffer = 0;
1681       if (m->passive) { bit_buffer |= (1 << 0); }
1682       if (m->durable) { bit_buffer |= (1 << 1); }
1683       if (m->auto_delete) { bit_buffer |= (1 << 2); }
1684       if (m->internal) { bit_buffer |= (1 << 3); }
1685       if (m->nowait) { bit_buffer |= (1 << 4); }
1686       E_8(encoded, offset, bit_buffer);
1687       offset++;
1688       table_result = amqp_encode_table(encoded, &(m->arguments), &offset);
1689       if (table_result < 0) return table_result;
1690       return offset;
1691     }
1692     case AMQP_EXCHANGE_DECLARE_OK_METHOD: {
1693       return offset;
1694     }
1695     case AMQP_EXCHANGE_DELETE_METHOD: {
1696       amqp_exchange_delete_t *m = (amqp_exchange_delete_t *) decoded;
1697       E_16(encoded, offset, m->ticket);
1698       offset += 2;
1699       E_8(encoded, offset, m->exchange.len);
1700       offset++;
1701       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1702       offset += m->exchange.len;
1703       bit_buffer = 0;
1704       if (m->if_unused) { bit_buffer |= (1 << 0); }
1705       if (m->nowait) { bit_buffer |= (1 << 1); }
1706       E_8(encoded, offset, bit_buffer);
1707       offset++;
1708       return offset;
1709     }
1710     case AMQP_EXCHANGE_DELETE_OK_METHOD: {
1711       return offset;
1712     }
1713     case AMQP_QUEUE_DECLARE_METHOD: {
1714       amqp_queue_declare_t *m = (amqp_queue_declare_t *) decoded;
1715       E_16(encoded, offset, m->ticket);
1716       offset += 2;
1717       E_8(encoded, offset, m->queue.len);
1718       offset++;
1719       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1720       offset += m->queue.len;
1721       bit_buffer = 0;
1722       if (m->passive) { bit_buffer |= (1 << 0); }
1723       if (m->durable) { bit_buffer |= (1 << 1); }
1724       if (m->exclusive) { bit_buffer |= (1 << 2); }
1725       if (m->auto_delete) { bit_buffer |= (1 << 3); }
1726       if (m->nowait) { bit_buffer |= (1 << 4); }
1727       E_8(encoded, offset, bit_buffer);
1728       offset++;
1729       table_result = amqp_encode_table(encoded, &(m->arguments), &offset);
1730       if (table_result < 0) return table_result;
1731       return offset;
1732     }
1733     case AMQP_QUEUE_DECLARE_OK_METHOD: {
1734       amqp_queue_declare_ok_t *m = (amqp_queue_declare_ok_t *) decoded;
1735       E_8(encoded, offset, m->queue.len);
1736       offset++;
1737       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1738       offset += m->queue.len;
1739       E_32(encoded, offset, m->message_count);
1740       offset += 4;
1741       E_32(encoded, offset, m->consumer_count);
1742       offset += 4;
1743       return offset;
1744     }
1745     case AMQP_QUEUE_BIND_METHOD: {
1746       amqp_queue_bind_t *m = (amqp_queue_bind_t *) decoded;
1747       E_16(encoded, offset, m->ticket);
1748       offset += 2;
1749       E_8(encoded, offset, m->queue.len);
1750       offset++;
1751       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1752       offset += m->queue.len;
1753       E_8(encoded, offset, m->exchange.len);
1754       offset++;
1755       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1756       offset += m->exchange.len;
1757       E_8(encoded, offset, m->routing_key.len);
1758       offset++;
1759       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1760       offset += m->routing_key.len;
1761       bit_buffer = 0;
1762       if (m->nowait) { bit_buffer |= (1 << 0); }
1763       E_8(encoded, offset, bit_buffer);
1764       offset++;
1765       table_result = amqp_encode_table(encoded, &(m->arguments), &offset);
1766       if (table_result < 0) return table_result;
1767       return offset;
1768     }
1769     case AMQP_QUEUE_BIND_OK_METHOD: {
1770       return offset;
1771     }
1772     case AMQP_QUEUE_PURGE_METHOD: {
1773       amqp_queue_purge_t *m = (amqp_queue_purge_t *) decoded;
1774       E_16(encoded, offset, m->ticket);
1775       offset += 2;
1776       E_8(encoded, offset, m->queue.len);
1777       offset++;
1778       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1779       offset += m->queue.len;
1780       bit_buffer = 0;
1781       if (m->nowait) { bit_buffer |= (1 << 0); }
1782       E_8(encoded, offset, bit_buffer);
1783       offset++;
1784       return offset;
1785     }
1786     case AMQP_QUEUE_PURGE_OK_METHOD: {
1787       amqp_queue_purge_ok_t *m = (amqp_queue_purge_ok_t *) decoded;
1788       E_32(encoded, offset, m->message_count);
1789       offset += 4;
1790       return offset;
1791     }
1792     case AMQP_QUEUE_DELETE_METHOD: {
1793       amqp_queue_delete_t *m = (amqp_queue_delete_t *) decoded;
1794       E_16(encoded, offset, m->ticket);
1795       offset += 2;
1796       E_8(encoded, offset, m->queue.len);
1797       offset++;
1798       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1799       offset += m->queue.len;
1800       bit_buffer = 0;
1801       if (m->if_unused) { bit_buffer |= (1 << 0); }
1802       if (m->if_empty) { bit_buffer |= (1 << 1); }
1803       if (m->nowait) { bit_buffer |= (1 << 2); }
1804       E_8(encoded, offset, bit_buffer);
1805       offset++;
1806       return offset;
1807     }
1808     case AMQP_QUEUE_DELETE_OK_METHOD: {
1809       amqp_queue_delete_ok_t *m = (amqp_queue_delete_ok_t *) decoded;
1810       E_32(encoded, offset, m->message_count);
1811       offset += 4;
1812       return offset;
1813     }
1814     case AMQP_QUEUE_UNBIND_METHOD: {
1815       amqp_queue_unbind_t *m = (amqp_queue_unbind_t *) decoded;
1816       E_16(encoded, offset, m->ticket);
1817       offset += 2;
1818       E_8(encoded, offset, m->queue.len);
1819       offset++;
1820       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1821       offset += m->queue.len;
1822       E_8(encoded, offset, m->exchange.len);
1823       offset++;
1824       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1825       offset += m->exchange.len;
1826       E_8(encoded, offset, m->routing_key.len);
1827       offset++;
1828       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1829       offset += m->routing_key.len;
1830       table_result = amqp_encode_table(encoded, &(m->arguments), &offset);
1831       if (table_result < 0) return table_result;
1832       return offset;
1833     }
1834     case AMQP_QUEUE_UNBIND_OK_METHOD: {
1835       return offset;
1836     }
1837     case AMQP_BASIC_QOS_METHOD: {
1838       amqp_basic_qos_t *m = (amqp_basic_qos_t *) decoded;
1839       E_32(encoded, offset, m->prefetch_size);
1840       offset += 4;
1841       E_16(encoded, offset, m->prefetch_count);
1842       offset += 2;
1843       bit_buffer = 0;
1844       if (m->global) { bit_buffer |= (1 << 0); }
1845       E_8(encoded, offset, bit_buffer);
1846       offset++;
1847       return offset;
1848     }
1849     case AMQP_BASIC_QOS_OK_METHOD: {
1850       return offset;
1851     }
1852     case AMQP_BASIC_CONSUME_METHOD: {
1853       amqp_basic_consume_t *m = (amqp_basic_consume_t *) decoded;
1854       E_16(encoded, offset, m->ticket);
1855       offset += 2;
1856       E_8(encoded, offset, m->queue.len);
1857       offset++;
1858       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1859       offset += m->queue.len;
1860       E_8(encoded, offset, m->consumer_tag.len);
1861       offset++;
1862       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
1863       offset += m->consumer_tag.len;
1864       bit_buffer = 0;
1865       if (m->no_local) { bit_buffer |= (1 << 0); }
1866       if (m->no_ack) { bit_buffer |= (1 << 1); }
1867       if (m->exclusive) { bit_buffer |= (1 << 2); }
1868       if (m->nowait) { bit_buffer |= (1 << 3); }
1869       E_8(encoded, offset, bit_buffer);
1870       offset++;
1871       return offset;
1872     }
1873     case AMQP_BASIC_CONSUME_OK_METHOD: {
1874       amqp_basic_consume_ok_t *m = (amqp_basic_consume_ok_t *) decoded;
1875       E_8(encoded, offset, m->consumer_tag.len);
1876       offset++;
1877       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
1878       offset += m->consumer_tag.len;
1879       return offset;
1880     }
1881     case AMQP_BASIC_CANCEL_METHOD: {
1882       amqp_basic_cancel_t *m = (amqp_basic_cancel_t *) decoded;
1883       E_8(encoded, offset, m->consumer_tag.len);
1884       offset++;
1885       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
1886       offset += m->consumer_tag.len;
1887       bit_buffer = 0;
1888       if (m->nowait) { bit_buffer |= (1 << 0); }
1889       E_8(encoded, offset, bit_buffer);
1890       offset++;
1891       return offset;
1892     }
1893     case AMQP_BASIC_CANCEL_OK_METHOD: {
1894       amqp_basic_cancel_ok_t *m = (amqp_basic_cancel_ok_t *) decoded;
1895       E_8(encoded, offset, m->consumer_tag.len);
1896       offset++;
1897       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
1898       offset += m->consumer_tag.len;
1899       return offset;
1900     }
1901     case AMQP_BASIC_PUBLISH_METHOD: {
1902       amqp_basic_publish_t *m = (amqp_basic_publish_t *) decoded;
1903       E_16(encoded, offset, m->ticket);
1904       offset += 2;
1905       E_8(encoded, offset, m->exchange.len);
1906       offset++;
1907       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1908       offset += m->exchange.len;
1909       E_8(encoded, offset, m->routing_key.len);
1910       offset++;
1911       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1912       offset += m->routing_key.len;
1913       bit_buffer = 0;
1914       if (m->mandatory) { bit_buffer |= (1 << 0); }
1915       if (m->immediate) { bit_buffer |= (1 << 1); }
1916       E_8(encoded, offset, bit_buffer);
1917       offset++;
1918       return offset;
1919     }
1920     case AMQP_BASIC_RETURN_METHOD: {
1921       amqp_basic_return_t *m = (amqp_basic_return_t *) decoded;
1922       E_16(encoded, offset, m->reply_code);
1923       offset += 2;
1924       E_8(encoded, offset, m->reply_text.len);
1925       offset++;
1926       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
1927       offset += m->reply_text.len;
1928       E_8(encoded, offset, m->exchange.len);
1929       offset++;
1930       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1931       offset += m->exchange.len;
1932       E_8(encoded, offset, m->routing_key.len);
1933       offset++;
1934       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1935       offset += m->routing_key.len;
1936       return offset;
1937     }
1938     case AMQP_BASIC_DELIVER_METHOD: {
1939       amqp_basic_deliver_t *m = (amqp_basic_deliver_t *) decoded;
1940       E_8(encoded, offset, m->consumer_tag.len);
1941       offset++;
1942       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
1943       offset += m->consumer_tag.len;
1944       E_64(encoded, offset, m->delivery_tag);
1945       offset += 8;
1946       bit_buffer = 0;
1947       if (m->redelivered) { bit_buffer |= (1 << 0); }
1948       E_8(encoded, offset, bit_buffer);
1949       offset++;
1950       E_8(encoded, offset, m->exchange.len);
1951       offset++;
1952       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1953       offset += m->exchange.len;
1954       E_8(encoded, offset, m->routing_key.len);
1955       offset++;
1956       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1957       offset += m->routing_key.len;
1958       return offset;
1959     }
1960     case AMQP_BASIC_GET_METHOD: {
1961       amqp_basic_get_t *m = (amqp_basic_get_t *) decoded;
1962       E_16(encoded, offset, m->ticket);
1963       offset += 2;
1964       E_8(encoded, offset, m->queue.len);
1965       offset++;
1966       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
1967       offset += m->queue.len;
1968       bit_buffer = 0;
1969       if (m->no_ack) { bit_buffer |= (1 << 0); }
1970       E_8(encoded, offset, bit_buffer);
1971       offset++;
1972       return offset;
1973     }
1974     case AMQP_BASIC_GET_OK_METHOD: {
1975       amqp_basic_get_ok_t *m = (amqp_basic_get_ok_t *) decoded;
1976       E_64(encoded, offset, m->delivery_tag);
1977       offset += 8;
1978       bit_buffer = 0;
1979       if (m->redelivered) { bit_buffer |= (1 << 0); }
1980       E_8(encoded, offset, bit_buffer);
1981       offset++;
1982       E_8(encoded, offset, m->exchange.len);
1983       offset++;
1984       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
1985       offset += m->exchange.len;
1986       E_8(encoded, offset, m->routing_key.len);
1987       offset++;
1988       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
1989       offset += m->routing_key.len;
1990       E_32(encoded, offset, m->message_count);
1991       offset += 4;
1992       return offset;
1993     }
1994     case AMQP_BASIC_GET_EMPTY_METHOD: {
1995       amqp_basic_get_empty_t *m = (amqp_basic_get_empty_t *) decoded;
1996       E_8(encoded, offset, m->cluster_id.len);
1997       offset++;
1998       E_BYTES(encoded, offset, m->cluster_id.len, m->cluster_id.bytes);
1999       offset += m->cluster_id.len;
2000       return offset;
2001     }
2002     case AMQP_BASIC_ACK_METHOD: {
2003       amqp_basic_ack_t *m = (amqp_basic_ack_t *) decoded;
2004       E_64(encoded, offset, m->delivery_tag);
2005       offset += 8;
2006       bit_buffer = 0;
2007       if (m->multiple) { bit_buffer |= (1 << 0); }
2008       E_8(encoded, offset, bit_buffer);
2009       offset++;
2010       return offset;
2011     }
2012     case AMQP_BASIC_REJECT_METHOD: {
2013       amqp_basic_reject_t *m = (amqp_basic_reject_t *) decoded;
2014       E_64(encoded, offset, m->delivery_tag);
2015       offset += 8;
2016       bit_buffer = 0;
2017       if (m->requeue) { bit_buffer |= (1 << 0); }
2018       E_8(encoded, offset, bit_buffer);
2019       offset++;
2020       return offset;
2021     }
2022     case AMQP_BASIC_RECOVER_METHOD: {
2023       amqp_basic_recover_t *m = (amqp_basic_recover_t *) decoded;
2024       bit_buffer = 0;
2025       if (m->requeue) { bit_buffer |= (1 << 0); }
2026       E_8(encoded, offset, bit_buffer);
2027       offset++;
2028       return offset;
2029     }
2030     case AMQP_FILE_QOS_METHOD: {
2031       amqp_file_qos_t *m = (amqp_file_qos_t *) decoded;
2032       E_32(encoded, offset, m->prefetch_size);
2033       offset += 4;
2034       E_16(encoded, offset, m->prefetch_count);
2035       offset += 2;
2036       bit_buffer = 0;
2037       if (m->global) { bit_buffer |= (1 << 0); }
2038       E_8(encoded, offset, bit_buffer);
2039       offset++;
2040       return offset;
2041     }
2042     case AMQP_FILE_QOS_OK_METHOD: {
2043       return offset;
2044     }
2045     case AMQP_FILE_CONSUME_METHOD: {
2046       amqp_file_consume_t *m = (amqp_file_consume_t *) decoded;
2047       E_16(encoded, offset, m->ticket);
2048       offset += 2;
2049       E_8(encoded, offset, m->queue.len);
2050       offset++;
2051       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
2052       offset += m->queue.len;
2053       E_8(encoded, offset, m->consumer_tag.len);
2054       offset++;
2055       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2056       offset += m->consumer_tag.len;
2057       bit_buffer = 0;
2058       if (m->no_local) { bit_buffer |= (1 << 0); }
2059       if (m->no_ack) { bit_buffer |= (1 << 1); }
2060       if (m->exclusive) { bit_buffer |= (1 << 2); }
2061       if (m->nowait) { bit_buffer |= (1 << 3); }
2062       E_8(encoded, offset, bit_buffer);
2063       offset++;
2064       return offset;
2065     }
2066     case AMQP_FILE_CONSUME_OK_METHOD: {
2067       amqp_file_consume_ok_t *m = (amqp_file_consume_ok_t *) decoded;
2068       E_8(encoded, offset, m->consumer_tag.len);
2069       offset++;
2070       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2071       offset += m->consumer_tag.len;
2072       return offset;
2073     }
2074     case AMQP_FILE_CANCEL_METHOD: {
2075       amqp_file_cancel_t *m = (amqp_file_cancel_t *) decoded;
2076       E_8(encoded, offset, m->consumer_tag.len);
2077       offset++;
2078       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2079       offset += m->consumer_tag.len;
2080       bit_buffer = 0;
2081       if (m->nowait) { bit_buffer |= (1 << 0); }
2082       E_8(encoded, offset, bit_buffer);
2083       offset++;
2084       return offset;
2085     }
2086     case AMQP_FILE_CANCEL_OK_METHOD: {
2087       amqp_file_cancel_ok_t *m = (amqp_file_cancel_ok_t *) decoded;
2088       E_8(encoded, offset, m->consumer_tag.len);
2089       offset++;
2090       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2091       offset += m->consumer_tag.len;
2092       return offset;
2093     }
2094     case AMQP_FILE_OPEN_METHOD: {
2095       amqp_file_open_t *m = (amqp_file_open_t *) decoded;
2096       E_8(encoded, offset, m->identifier.len);
2097       offset++;
2098       E_BYTES(encoded, offset, m->identifier.len, m->identifier.bytes);
2099       offset += m->identifier.len;
2100       E_64(encoded, offset, m->content_size);
2101       offset += 8;
2102       return offset;
2103     }
2104     case AMQP_FILE_OPEN_OK_METHOD: {
2105       amqp_file_open_ok_t *m = (amqp_file_open_ok_t *) decoded;
2106       E_64(encoded, offset, m->staged_size);
2107       offset += 8;
2108       return offset;
2109     }
2110     case AMQP_FILE_STAGE_METHOD: {
2111       return offset;
2112     }
2113     case AMQP_FILE_PUBLISH_METHOD: {
2114       amqp_file_publish_t *m = (amqp_file_publish_t *) decoded;
2115       E_16(encoded, offset, m->ticket);
2116       offset += 2;
2117       E_8(encoded, offset, m->exchange.len);
2118       offset++;
2119       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2120       offset += m->exchange.len;
2121       E_8(encoded, offset, m->routing_key.len);
2122       offset++;
2123       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
2124       offset += m->routing_key.len;
2125       bit_buffer = 0;
2126       if (m->mandatory) { bit_buffer |= (1 << 0); }
2127       if (m->immediate) { bit_buffer |= (1 << 1); }
2128       E_8(encoded, offset, bit_buffer);
2129       offset++;
2130       E_8(encoded, offset, m->identifier.len);
2131       offset++;
2132       E_BYTES(encoded, offset, m->identifier.len, m->identifier.bytes);
2133       offset += m->identifier.len;
2134       return offset;
2135     }
2136     case AMQP_FILE_RETURN_METHOD: {
2137       amqp_file_return_t *m = (amqp_file_return_t *) decoded;
2138       E_16(encoded, offset, m->reply_code);
2139       offset += 2;
2140       E_8(encoded, offset, m->reply_text.len);
2141       offset++;
2142       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
2143       offset += m->reply_text.len;
2144       E_8(encoded, offset, m->exchange.len);
2145       offset++;
2146       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2147       offset += m->exchange.len;
2148       E_8(encoded, offset, m->routing_key.len);
2149       offset++;
2150       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
2151       offset += m->routing_key.len;
2152       return offset;
2153     }
2154     case AMQP_FILE_DELIVER_METHOD: {
2155       amqp_file_deliver_t *m = (amqp_file_deliver_t *) decoded;
2156       E_8(encoded, offset, m->consumer_tag.len);
2157       offset++;
2158       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2159       offset += m->consumer_tag.len;
2160       E_64(encoded, offset, m->delivery_tag);
2161       offset += 8;
2162       bit_buffer = 0;
2163       if (m->redelivered) { bit_buffer |= (1 << 0); }
2164       E_8(encoded, offset, bit_buffer);
2165       offset++;
2166       E_8(encoded, offset, m->exchange.len);
2167       offset++;
2168       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2169       offset += m->exchange.len;
2170       E_8(encoded, offset, m->routing_key.len);
2171       offset++;
2172       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
2173       offset += m->routing_key.len;
2174       E_8(encoded, offset, m->identifier.len);
2175       offset++;
2176       E_BYTES(encoded, offset, m->identifier.len, m->identifier.bytes);
2177       offset += m->identifier.len;
2178       return offset;
2179     }
2180     case AMQP_FILE_ACK_METHOD: {
2181       amqp_file_ack_t *m = (amqp_file_ack_t *) decoded;
2182       E_64(encoded, offset, m->delivery_tag);
2183       offset += 8;
2184       bit_buffer = 0;
2185       if (m->multiple) { bit_buffer |= (1 << 0); }
2186       E_8(encoded, offset, bit_buffer);
2187       offset++;
2188       return offset;
2189     }
2190     case AMQP_FILE_REJECT_METHOD: {
2191       amqp_file_reject_t *m = (amqp_file_reject_t *) decoded;
2192       E_64(encoded, offset, m->delivery_tag);
2193       offset += 8;
2194       bit_buffer = 0;
2195       if (m->requeue) { bit_buffer |= (1 << 0); }
2196       E_8(encoded, offset, bit_buffer);
2197       offset++;
2198       return offset;
2199     }
2200     case AMQP_STREAM_QOS_METHOD: {
2201       amqp_stream_qos_t *m = (amqp_stream_qos_t *) decoded;
2202       E_32(encoded, offset, m->prefetch_size);
2203       offset += 4;
2204       E_16(encoded, offset, m->prefetch_count);
2205       offset += 2;
2206       E_32(encoded, offset, m->consume_rate);
2207       offset += 4;
2208       bit_buffer = 0;
2209       if (m->global) { bit_buffer |= (1 << 0); }
2210       E_8(encoded, offset, bit_buffer);
2211       offset++;
2212       return offset;
2213     }
2214     case AMQP_STREAM_QOS_OK_METHOD: {
2215       return offset;
2216     }
2217     case AMQP_STREAM_CONSUME_METHOD: {
2218       amqp_stream_consume_t *m = (amqp_stream_consume_t *) decoded;
2219       E_16(encoded, offset, m->ticket);
2220       offset += 2;
2221       E_8(encoded, offset, m->queue.len);
2222       offset++;
2223       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
2224       offset += m->queue.len;
2225       E_8(encoded, offset, m->consumer_tag.len);
2226       offset++;
2227       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2228       offset += m->consumer_tag.len;
2229       bit_buffer = 0;
2230       if (m->no_local) { bit_buffer |= (1 << 0); }
2231       if (m->exclusive) { bit_buffer |= (1 << 1); }
2232       if (m->nowait) { bit_buffer |= (1 << 2); }
2233       E_8(encoded, offset, bit_buffer);
2234       offset++;
2235       return offset;
2236     }
2237     case AMQP_STREAM_CONSUME_OK_METHOD: {
2238       amqp_stream_consume_ok_t *m = (amqp_stream_consume_ok_t *) decoded;
2239       E_8(encoded, offset, m->consumer_tag.len);
2240       offset++;
2241       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2242       offset += m->consumer_tag.len;
2243       return offset;
2244     }
2245     case AMQP_STREAM_CANCEL_METHOD: {
2246       amqp_stream_cancel_t *m = (amqp_stream_cancel_t *) decoded;
2247       E_8(encoded, offset, m->consumer_tag.len);
2248       offset++;
2249       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2250       offset += m->consumer_tag.len;
2251       bit_buffer = 0;
2252       if (m->nowait) { bit_buffer |= (1 << 0); }
2253       E_8(encoded, offset, bit_buffer);
2254       offset++;
2255       return offset;
2256     }
2257     case AMQP_STREAM_CANCEL_OK_METHOD: {
2258       amqp_stream_cancel_ok_t *m = (amqp_stream_cancel_ok_t *) decoded;
2259       E_8(encoded, offset, m->consumer_tag.len);
2260       offset++;
2261       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2262       offset += m->consumer_tag.len;
2263       return offset;
2264     }
2265     case AMQP_STREAM_PUBLISH_METHOD: {
2266       amqp_stream_publish_t *m = (amqp_stream_publish_t *) decoded;
2267       E_16(encoded, offset, m->ticket);
2268       offset += 2;
2269       E_8(encoded, offset, m->exchange.len);
2270       offset++;
2271       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2272       offset += m->exchange.len;
2273       E_8(encoded, offset, m->routing_key.len);
2274       offset++;
2275       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
2276       offset += m->routing_key.len;
2277       bit_buffer = 0;
2278       if (m->mandatory) { bit_buffer |= (1 << 0); }
2279       if (m->immediate) { bit_buffer |= (1 << 1); }
2280       E_8(encoded, offset, bit_buffer);
2281       offset++;
2282       return offset;
2283     }
2284     case AMQP_STREAM_RETURN_METHOD: {
2285       amqp_stream_return_t *m = (amqp_stream_return_t *) decoded;
2286       E_16(encoded, offset, m->reply_code);
2287       offset += 2;
2288       E_8(encoded, offset, m->reply_text.len);
2289       offset++;
2290       E_BYTES(encoded, offset, m->reply_text.len, m->reply_text.bytes);
2291       offset += m->reply_text.len;
2292       E_8(encoded, offset, m->exchange.len);
2293       offset++;
2294       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2295       offset += m->exchange.len;
2296       E_8(encoded, offset, m->routing_key.len);
2297       offset++;
2298       E_BYTES(encoded, offset, m->routing_key.len, m->routing_key.bytes);
2299       offset += m->routing_key.len;
2300       return offset;
2301     }
2302     case AMQP_STREAM_DELIVER_METHOD: {
2303       amqp_stream_deliver_t *m = (amqp_stream_deliver_t *) decoded;
2304       E_8(encoded, offset, m->consumer_tag.len);
2305       offset++;
2306       E_BYTES(encoded, offset, m->consumer_tag.len, m->consumer_tag.bytes);
2307       offset += m->consumer_tag.len;
2308       E_64(encoded, offset, m->delivery_tag);
2309       offset += 8;
2310       E_8(encoded, offset, m->exchange.len);
2311       offset++;
2312       E_BYTES(encoded, offset, m->exchange.len, m->exchange.bytes);
2313       offset += m->exchange.len;
2314       E_8(encoded, offset, m->queue.len);
2315       offset++;
2316       E_BYTES(encoded, offset, m->queue.len, m->queue.bytes);
2317       offset += m->queue.len;
2318       return offset;
2319     }
2320     case AMQP_TX_SELECT_METHOD: {
2321       return offset;
2322     }
2323     case AMQP_TX_SELECT_OK_METHOD: {
2324       return offset;
2325     }
2326     case AMQP_TX_COMMIT_METHOD: {
2327       return offset;
2328     }
2329     case AMQP_TX_COMMIT_OK_METHOD: {
2330       return offset;
2331     }
2332     case AMQP_TX_ROLLBACK_METHOD: {
2333       return offset;
2334     }
2335     case AMQP_TX_ROLLBACK_OK_METHOD: {
2336       return offset;
2337     }
2338     case AMQP_DTX_SELECT_METHOD: {
2339       return offset;
2340     }
2341     case AMQP_DTX_SELECT_OK_METHOD: {
2342       return offset;
2343     }
2344     case AMQP_DTX_START_METHOD: {
2345       amqp_dtx_start_t *m = (amqp_dtx_start_t *) decoded;
2346       E_8(encoded, offset, m->dtx_identifier.len);
2347       offset++;
2348       E_BYTES(encoded, offset, m->dtx_identifier.len, m->dtx_identifier.bytes);
2349       offset += m->dtx_identifier.len;
2350       return offset;
2351     }
2352     case AMQP_DTX_START_OK_METHOD: {
2353       return offset;
2354     }
2355     case AMQP_TUNNEL_REQUEST_METHOD: {
2356       amqp_tunnel_request_t *m = (amqp_tunnel_request_t *) decoded;
2357       table_result = amqp_encode_table(encoded, &(m->meta_data), &offset);
2358       if (table_result < 0) return table_result;
2359       return offset;
2360     }
2361     case AMQP_TEST_INTEGER_METHOD: {
2362       amqp_test_integer_t *m = (amqp_test_integer_t *) decoded;
2363       E_8(encoded, offset, m->integer_1);
2364       offset++;
2365       E_16(encoded, offset, m->integer_2);
2366       offset += 2;
2367       E_32(encoded, offset, m->integer_3);
2368       offset += 4;
2369       E_64(encoded, offset, m->integer_4);
2370       offset += 8;
2371       E_8(encoded, offset, m->operation);
2372       offset++;
2373       return offset;
2374     }
2375     case AMQP_TEST_INTEGER_OK_METHOD: {
2376       amqp_test_integer_ok_t *m = (amqp_test_integer_ok_t *) decoded;
2377       E_64(encoded, offset, m->result);
2378       offset += 8;
2379       return offset;
2380     }
2381     case AMQP_TEST_STRING_METHOD: {
2382       amqp_test_string_t *m = (amqp_test_string_t *) decoded;
2383       E_8(encoded, offset, m->string_1.len);
2384       offset++;
2385       E_BYTES(encoded, offset, m->string_1.len, m->string_1.bytes);
2386       offset += m->string_1.len;
2387       E_32(encoded, offset, m->string_2.len);
2388       offset += 4;
2389       E_BYTES(encoded, offset, m->string_2.len, m->string_2.bytes);
2390       offset += m->string_2.len;
2391       E_8(encoded, offset, m->operation);
2392       offset++;
2393       return offset;
2394     }
2395     case AMQP_TEST_STRING_OK_METHOD: {
2396       amqp_test_string_ok_t *m = (amqp_test_string_ok_t *) decoded;
2397       E_32(encoded, offset, m->result.len);
2398       offset += 4;
2399       E_BYTES(encoded, offset, m->result.len, m->result.bytes);
2400       offset += m->result.len;
2401       return offset;
2402     }
2403     case AMQP_TEST_TABLE_METHOD: {
2404       amqp_test_table_t *m = (amqp_test_table_t *) decoded;
2405       table_result = amqp_encode_table(encoded, &(m->table), &offset);
2406       if (table_result < 0) return table_result;
2407       E_8(encoded, offset, m->integer_op);
2408       offset++;
2409       E_8(encoded, offset, m->string_op);
2410       offset++;
2411       return offset;
2412     }
2413     case AMQP_TEST_TABLE_OK_METHOD: {
2414       amqp_test_table_ok_t *m = (amqp_test_table_ok_t *) decoded;
2415       E_64(encoded, offset, m->integer_result);
2416       offset += 8;
2417       E_32(encoded, offset, m->string_result.len);
2418       offset += 4;
2419       E_BYTES(encoded, offset, m->string_result.len, m->string_result.bytes);
2420       offset += m->string_result.len;
2421       return offset;
2422     }
2423     case AMQP_TEST_CONTENT_METHOD: {
2424       return offset;
2425     }
2426     case AMQP_TEST_CONTENT_OK_METHOD: {
2427       amqp_test_content_ok_t *m = (amqp_test_content_ok_t *) decoded;
2428       E_32(encoded, offset, m->content_checksum);
2429       offset += 4;
2430       return offset;
2431     }
2432     default: return -ENOENT;
2433   }
2434 }
2435
2436 int amqp_encode_properties(uint16_t class_id,
2437                            void *decoded,
2438                            amqp_bytes_t encoded)
2439 {
2440   int offset = 0;
2441   int table_result;
2442
2443   /* Cheat, and get the flags out generically, relying on the
2444      similarity of structure between classes */
2445   amqp_flags_t flags = * (amqp_flags_t *) decoded; /* cheating! */
2446
2447   {
2448     /* We take a copy of flags to avoid destroying it, as it is used
2449        in the autogenerated code below. */
2450     amqp_flags_t remaining_flags = flags;
2451     do {
2452       amqp_flags_t remainder = remaining_flags >> 16;
2453       uint16_t partial_flags = remaining_flags & 0xFFFE;
2454       if (remainder != 0) { partial_flags |= 1; }
2455       E_16(encoded, offset, partial_flags);
2456       offset += 2;
2457       remaining_flags = remainder;
2458     } while (remaining_flags != 0);
2459   }
2460  
2461   switch (class_id) {
2462     case 10: {
2463       return offset;
2464     }
2465     case 20: {
2466       return offset;
2467     }
2468     case 30: {
2469       return offset;
2470     }
2471     case 40: {
2472       return offset;
2473     }
2474     case 50: {
2475       return offset;
2476     }
2477     case 60: {
2478       amqp_basic_properties_t *p = (amqp_basic_properties_t *) decoded;
2479       if (flags & AMQP_BASIC_CONTENT_TYPE_FLAG) {
2480         E_8(encoded, offset, p->content_type.len);
2481         offset++;
2482         E_BYTES(encoded, offset, p->content_type.len, p->content_type.bytes);
2483         offset += p->content_type.len;
2484       }
2485       if (flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) {
2486         E_8(encoded, offset, p->content_encoding.len);
2487         offset++;
2488         E_BYTES(encoded, offset, p->content_encoding.len, p->content_encoding.bytes);
2489         offset += p->content_encoding.len;
2490       }
2491       if (flags & AMQP_BASIC_HEADERS_FLAG) {
2492         table_result = amqp_encode_table(encoded, &(p->headers), &offset);
2493         if (table_result < 0) return table_result;
2494       }
2495       if (flags & AMQP_BASIC_DELIVERY_MODE_FLAG) {
2496         E_8(encoded, offset, p->delivery_mode);
2497         offset++;
2498       }
2499       if (flags & AMQP_BASIC_PRIORITY_FLAG) {
2500         E_8(encoded, offset, p->priority);
2501         offset++;
2502       }
2503       if (flags & AMQP_BASIC_CORRELATION_ID_FLAG) {
2504         E_8(encoded, offset, p->correlation_id.len);
2505         offset++;
2506         E_BYTES(encoded, offset, p->correlation_id.len, p->correlation_id.bytes);
2507         offset += p->correlation_id.len;
2508       }
2509       if (flags & AMQP_BASIC_REPLY_TO_FLAG) {
2510         E_8(encoded, offset, p->reply_to.len);
2511         offset++;
2512         E_BYTES(encoded, offset, p->reply_to.len, p->reply_to.bytes);
2513         offset += p->reply_to.len;
2514       }
2515       if (flags & AMQP_BASIC_EXPIRATION_FLAG) {
2516         E_8(encoded, offset, p->expiration.len);
2517         offset++;
2518         E_BYTES(encoded, offset, p->expiration.len, p->expiration.bytes);
2519         offset += p->expiration.len;
2520       }
2521       if (flags & AMQP_BASIC_MESSAGE_ID_FLAG) {
2522         E_8(encoded, offset, p->message_id.len);
2523         offset++;
2524         E_BYTES(encoded, offset, p->message_id.len, p->message_id.bytes);
2525         offset += p->message_id.len;
2526       }
2527       if (flags & AMQP_BASIC_TIMESTAMP_FLAG) {
2528         E_64(encoded, offset, p->timestamp);
2529         offset += 8;
2530       }
2531       if (flags & AMQP_BASIC_TYPE_FLAG) {
2532         E_8(encoded, offset, p->type.len);
2533         offset++;
2534         E_BYTES(encoded, offset, p->type.len, p->type.bytes);
2535         offset += p->type.len;
2536       }
2537       if (flags & AMQP_BASIC_USER_ID_FLAG) {
2538         E_8(encoded, offset, p->user_id.len);
2539         offset++;
2540         E_BYTES(encoded, offset, p->user_id.len, p->user_id.bytes);
2541         offset += p->user_id.len;
2542       }
2543       if (flags & AMQP_BASIC_APP_ID_FLAG) {
2544         E_8(encoded, offset, p->app_id.len);
2545         offset++;
2546         E_BYTES(encoded, offset, p->app_id.len, p->app_id.bytes);
2547         offset += p->app_id.len;
2548       }
2549       if (flags & AMQP_BASIC_CLUSTER_ID_FLAG) {
2550         E_8(encoded, offset, p->cluster_id.len);
2551         offset++;
2552         E_BYTES(encoded, offset, p->cluster_id.len, p->cluster_id.bytes);
2553         offset += p->cluster_id.len;
2554       }
2555       return offset;
2556     }
2557     case 70: {
2558       amqp_file_properties_t *p = (amqp_file_properties_t *) decoded;
2559       if (flags & AMQP_FILE_CONTENT_TYPE_FLAG) {
2560         E_8(encoded, offset, p->content_type.len);
2561         offset++;
2562         E_BYTES(encoded, offset, p->content_type.len, p->content_type.bytes);
2563         offset += p->content_type.len;
2564       }
2565       if (flags & AMQP_FILE_CONTENT_ENCODING_FLAG) {
2566         E_8(encoded, offset, p->content_encoding.len);
2567         offset++;
2568         E_BYTES(encoded, offset, p->content_encoding.len, p->content_encoding.bytes);
2569         offset += p->content_encoding.len;
2570       }
2571       if (flags & AMQP_FILE_HEADERS_FLAG) {
2572         table_result = amqp_encode_table(encoded, &(p->headers), &offset);
2573         if (table_result < 0) return table_result;
2574       }
2575       if (flags & AMQP_FILE_PRIORITY_FLAG) {
2576         E_8(encoded, offset, p->priority);
2577         offset++;
2578       }
2579       if (flags & AMQP_FILE_REPLY_TO_FLAG) {
2580         E_8(encoded, offset, p->reply_to.len);
2581         offset++;
2582         E_BYTES(encoded, offset, p->reply_to.len, p->reply_to.bytes);
2583         offset += p->reply_to.len;
2584       }
2585       if (flags & AMQP_FILE_MESSAGE_ID_FLAG) {
2586         E_8(encoded, offset, p->message_id.len);
2587         offset++;
2588         E_BYTES(encoded, offset, p->message_id.len, p->message_id.bytes);
2589         offset += p->message_id.len;
2590       }
2591       if (flags & AMQP_FILE_FILENAME_FLAG) {
2592         E_8(encoded, offset, p->filename.len);
2593         offset++;
2594         E_BYTES(encoded, offset, p->filename.len, p->filename.bytes);
2595         offset += p->filename.len;
2596       }
2597       if (flags & AMQP_FILE_TIMESTAMP_FLAG) {
2598         E_64(encoded, offset, p->timestamp);
2599         offset += 8;
2600       }
2601       if (flags & AMQP_FILE_CLUSTER_ID_FLAG) {
2602         E_8(encoded, offset, p->cluster_id.len);
2603         offset++;
2604         E_BYTES(encoded, offset, p->cluster_id.len, p->cluster_id.bytes);
2605         offset += p->cluster_id.len;
2606       }
2607       return offset;
2608     }
2609     case 80: {
2610       amqp_stream_properties_t *p = (amqp_stream_properties_t *) decoded;
2611       if (flags & AMQP_STREAM_CONTENT_TYPE_FLAG) {
2612         E_8(encoded, offset, p->content_type.len);
2613         offset++;
2614         E_BYTES(encoded, offset, p->content_type.len, p->content_type.bytes);
2615         offset += p->content_type.len;
2616       }
2617       if (flags & AMQP_STREAM_CONTENT_ENCODING_FLAG) {
2618         E_8(encoded, offset, p->content_encoding.len);
2619         offset++;
2620         E_BYTES(encoded, offset, p->content_encoding.len, p->content_encoding.bytes);
2621         offset += p->content_encoding.len;
2622       }
2623       if (flags & AMQP_STREAM_HEADERS_FLAG) {
2624         table_result = amqp_encode_table(encoded, &(p->headers), &offset);
2625         if (table_result < 0) return table_result;
2626       }
2627       if (flags & AMQP_STREAM_PRIORITY_FLAG) {
2628         E_8(encoded, offset, p->priority);
2629         offset++;
2630       }
2631       if (flags & AMQP_STREAM_TIMESTAMP_FLAG) {
2632         E_64(encoded, offset, p->timestamp);
2633         offset += 8;
2634       }
2635       return offset;
2636     }
2637     case 90: {
2638       return offset;
2639     }
2640     case 100: {
2641       return offset;
2642     }
2643     case 110: {
2644       amqp_tunnel_properties_t *p = (amqp_tunnel_properties_t *) decoded;
2645       if (flags & AMQP_TUNNEL_HEADERS_FLAG) {
2646         table_result = amqp_encode_table(encoded, &(p->headers), &offset);
2647         if (table_result < 0) return table_result;
2648       }
2649       if (flags & AMQP_TUNNEL_PROXY_NAME_FLAG) {
2650         E_8(encoded, offset, p->proxy_name.len);
2651         offset++;
2652         E_BYTES(encoded, offset, p->proxy_name.len, p->proxy_name.bytes);
2653         offset += p->proxy_name.len;
2654       }
2655       if (flags & AMQP_TUNNEL_DATA_NAME_FLAG) {
2656         E_8(encoded, offset, p->data_name.len);
2657         offset++;
2658         E_BYTES(encoded, offset, p->data_name.len, p->data_name.bytes);
2659         offset += p->data_name.len;
2660       }
2661       if (flags & AMQP_TUNNEL_DURABLE_FLAG) {
2662         E_8(encoded, offset, p->durable);
2663         offset++;
2664       }
2665       if (flags & AMQP_TUNNEL_BROADCAST_FLAG) {
2666         E_8(encoded, offset, p->broadcast);
2667         offset++;
2668       }
2669       return offset;
2670     }
2671     case 120: {
2672       return offset;
2673     }
2674     default: return -ENOENT;
2675   }
2676 }
Note: See TracBrowser for help on using the browser.