amqp_framing.c 102 KB

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