1#![allow(unused_assignments, unused_variables, unreachable_patterns)]
2use super::*;
3use crate::codec::{self, decode_format_code, decode_list_header, Decode, DecodeFormatted, Encode};
4use crate::errors::AmqpParseError;
5use bytes::{BufMut, Bytes, BytesMut};
6use bytestring::ByteString;
7use derive_more::From;
8use std::u8;
9use uuid::Uuid;
10#[derive(Clone, Debug, PartialEq, From)]
11pub enum Frame {
12 Open(Open),
13 Begin(Begin),
14 Attach(Attach),
15 Flow(Flow),
16 Transfer(Transfer),
17 Disposition(Disposition),
18 Detach(Detach),
19 End(End),
20 Close(Close),
21 Empty,
22}
23impl Frame {
24 pub fn name(&self) -> &'static str {
25 match self {
26 Frame::Open(_) => "Open",
27 Frame::Begin(_) => "Begin",
28 Frame::Attach(_) => "Attach",
29 Frame::Flow(_) => "Flow",
30 Frame::Transfer(_) => "Transfer",
31 Frame::Disposition(_) => "Disposition",
32 Frame::Detach(_) => "Detach",
33 Frame::End(_) => "End",
34 Frame::Close(_) => "Close",
35 Frame::Empty => "Empty",
36 }
37 }
38}
39impl Decode for Frame {
40 fn decode(input: &[u8]) -> Result<(&[u8], Self), AmqpParseError> {
41 if input.is_empty() {
42 Ok((input, Frame::Empty))
43 } else {
44 let (input, fmt) = decode_format_code(input)?;
45 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
46 let (input, descriptor) = Descriptor::decode(input)?;
47 match descriptor {
48 Descriptor::Ulong(16) => decode_open_inner(input).map(|(i, r)| (i, Frame::Open(r))),
49 Descriptor::Ulong(17) => {
50 decode_begin_inner(input).map(|(i, r)| (i, Frame::Begin(r)))
51 }
52 Descriptor::Ulong(18) => {
53 decode_attach_inner(input).map(|(i, r)| (i, Frame::Attach(r)))
54 }
55 Descriptor::Ulong(19) => decode_flow_inner(input).map(|(i, r)| (i, Frame::Flow(r))),
56 Descriptor::Ulong(20) => {
57 decode_transfer_inner(input).map(|(i, r)| (i, Frame::Transfer(r)))
58 }
59 Descriptor::Ulong(21) => {
60 decode_disposition_inner(input).map(|(i, r)| (i, Frame::Disposition(r)))
61 }
62 Descriptor::Ulong(22) => {
63 decode_detach_inner(input).map(|(i, r)| (i, Frame::Detach(r)))
64 }
65 Descriptor::Ulong(23) => decode_end_inner(input).map(|(i, r)| (i, Frame::End(r))),
66 Descriptor::Ulong(24) => {
67 decode_close_inner(input).map(|(i, r)| (i, Frame::Close(r)))
68 }
69 Descriptor::Symbol(ref a) if a.as_str() == "amqp:open:list" => {
70 decode_open_inner(input).map(|(i, r)| (i, Frame::Open(r)))
71 }
72 Descriptor::Symbol(ref a) if a.as_str() == "amqp:begin:list" => {
73 decode_begin_inner(input).map(|(i, r)| (i, Frame::Begin(r)))
74 }
75 Descriptor::Symbol(ref a) if a.as_str() == "amqp:attach:list" => {
76 decode_attach_inner(input).map(|(i, r)| (i, Frame::Attach(r)))
77 }
78 Descriptor::Symbol(ref a) if a.as_str() == "amqp:flow:list" => {
79 decode_flow_inner(input).map(|(i, r)| (i, Frame::Flow(r)))
80 }
81 Descriptor::Symbol(ref a) if a.as_str() == "amqp:transfer:list" => {
82 decode_transfer_inner(input).map(|(i, r)| (i, Frame::Transfer(r)))
83 }
84 Descriptor::Symbol(ref a) if a.as_str() == "amqp:disposition:list" => {
85 decode_disposition_inner(input).map(|(i, r)| (i, Frame::Disposition(r)))
86 }
87 Descriptor::Symbol(ref a) if a.as_str() == "amqp:detach:list" => {
88 decode_detach_inner(input).map(|(i, r)| (i, Frame::Detach(r)))
89 }
90 Descriptor::Symbol(ref a) if a.as_str() == "amqp:end:list" => {
91 decode_end_inner(input).map(|(i, r)| (i, Frame::End(r)))
92 }
93 Descriptor::Symbol(ref a) if a.as_str() == "amqp:close:list" => {
94 decode_close_inner(input).map(|(i, r)| (i, Frame::Close(r)))
95 }
96 _ => Err(AmqpParseError::InvalidDescriptor(descriptor)),
97 }
98 }
99 }
100}
101impl Encode for Frame {
102 fn encoded_size(&self) -> usize {
103 match *self {
104 Frame::Open(ref v) => encoded_size_open_inner(v),
105 Frame::Begin(ref v) => encoded_size_begin_inner(v),
106 Frame::Attach(ref v) => encoded_size_attach_inner(v),
107 Frame::Flow(ref v) => encoded_size_flow_inner(v),
108 Frame::Transfer(ref v) => encoded_size_transfer_inner(v),
109 Frame::Disposition(ref v) => encoded_size_disposition_inner(v),
110 Frame::Detach(ref v) => encoded_size_detach_inner(v),
111 Frame::End(ref v) => encoded_size_end_inner(v),
112 Frame::Close(ref v) => encoded_size_close_inner(v),
113 Frame::Empty => 0,
114 }
115 }
116 fn encode(&self, buf: &mut BytesMut) {
117 match *self {
118 Frame::Open(ref v) => encode_open_inner(v, buf),
119 Frame::Begin(ref v) => encode_begin_inner(v, buf),
120 Frame::Attach(ref v) => encode_attach_inner(v, buf),
121 Frame::Flow(ref v) => encode_flow_inner(v, buf),
122 Frame::Transfer(ref v) => encode_transfer_inner(v, buf),
123 Frame::Disposition(ref v) => encode_disposition_inner(v, buf),
124 Frame::Detach(ref v) => encode_detach_inner(v, buf),
125 Frame::End(ref v) => encode_end_inner(v, buf),
126 Frame::Close(ref v) => encode_close_inner(v, buf),
127 Frame::Empty => (),
128 }
129 }
130}
131#[derive(Clone, Debug, PartialEq)]
132pub enum DeliveryState {
133 Received(Received),
134 Accepted(Accepted),
135 Rejected(Rejected),
136 Released(Released),
137 Modified(Modified),
138}
139impl DecodeFormatted for DeliveryState {
140 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
141 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
142 let (input, descriptor) = Descriptor::decode(input)?;
143 match descriptor {
144 Descriptor::Ulong(35) => {
145 decode_received_inner(input).map(|(i, r)| (i, DeliveryState::Received(r)))
146 }
147 Descriptor::Ulong(36) => {
148 decode_accepted_inner(input).map(|(i, r)| (i, DeliveryState::Accepted(r)))
149 }
150 Descriptor::Ulong(37) => {
151 decode_rejected_inner(input).map(|(i, r)| (i, DeliveryState::Rejected(r)))
152 }
153 Descriptor::Ulong(38) => {
154 decode_released_inner(input).map(|(i, r)| (i, DeliveryState::Released(r)))
155 }
156 Descriptor::Ulong(39) => {
157 decode_modified_inner(input).map(|(i, r)| (i, DeliveryState::Modified(r)))
158 }
159 Descriptor::Symbol(ref a) if a.as_str() == "amqp:received:list" => {
160 decode_received_inner(input).map(|(i, r)| (i, DeliveryState::Received(r)))
161 }
162 Descriptor::Symbol(ref a) if a.as_str() == "amqp:accepted:list" => {
163 decode_accepted_inner(input).map(|(i, r)| (i, DeliveryState::Accepted(r)))
164 }
165 Descriptor::Symbol(ref a) if a.as_str() == "amqp:rejected:list" => {
166 decode_rejected_inner(input).map(|(i, r)| (i, DeliveryState::Rejected(r)))
167 }
168 Descriptor::Symbol(ref a) if a.as_str() == "amqp:released:list" => {
169 decode_released_inner(input).map(|(i, r)| (i, DeliveryState::Released(r)))
170 }
171 Descriptor::Symbol(ref a) if a.as_str() == "amqp:modified:list" => {
172 decode_modified_inner(input).map(|(i, r)| (i, DeliveryState::Modified(r)))
173 }
174 _ => Err(AmqpParseError::InvalidDescriptor(descriptor)),
175 }
176 }
177}
178impl Encode for DeliveryState {
179 fn encoded_size(&self) -> usize {
180 match *self {
181 DeliveryState::Received(ref v) => encoded_size_received_inner(v),
182 DeliveryState::Accepted(ref v) => encoded_size_accepted_inner(v),
183 DeliveryState::Rejected(ref v) => encoded_size_rejected_inner(v),
184 DeliveryState::Released(ref v) => encoded_size_released_inner(v),
185 DeliveryState::Modified(ref v) => encoded_size_modified_inner(v),
186 }
187 }
188 fn encode(&self, buf: &mut BytesMut) {
189 match *self {
190 DeliveryState::Received(ref v) => encode_received_inner(v, buf),
191 DeliveryState::Accepted(ref v) => encode_accepted_inner(v, buf),
192 DeliveryState::Rejected(ref v) => encode_rejected_inner(v, buf),
193 DeliveryState::Released(ref v) => encode_released_inner(v, buf),
194 DeliveryState::Modified(ref v) => encode_modified_inner(v, buf),
195 }
196 }
197}
198#[derive(Clone, Debug, PartialEq)]
199pub enum SaslFrameBody {
200 SaslMechanisms(SaslMechanisms),
201 SaslInit(SaslInit),
202 SaslChallenge(SaslChallenge),
203 SaslResponse(SaslResponse),
204 SaslOutcome(SaslOutcome),
205}
206impl DecodeFormatted for SaslFrameBody {
207 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
208 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
209 let (input, descriptor) = Descriptor::decode(input)?;
210 match descriptor {
211 Descriptor::Ulong(64) => decode_sasl_mechanisms_inner(input)
212 .map(|(i, r)| (i, SaslFrameBody::SaslMechanisms(r))),
213 Descriptor::Ulong(65) => {
214 decode_sasl_init_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslInit(r)))
215 }
216 Descriptor::Ulong(66) => decode_sasl_challenge_inner(input)
217 .map(|(i, r)| (i, SaslFrameBody::SaslChallenge(r))),
218 Descriptor::Ulong(67) => {
219 decode_sasl_response_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslResponse(r)))
220 }
221 Descriptor::Ulong(68) => {
222 decode_sasl_outcome_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslOutcome(r)))
223 }
224 Descriptor::Symbol(ref a) if a.as_str() == "amqp:sasl-mechanisms:list" => {
225 decode_sasl_mechanisms_inner(input)
226 .map(|(i, r)| (i, SaslFrameBody::SaslMechanisms(r)))
227 }
228 Descriptor::Symbol(ref a) if a.as_str() == "amqp:sasl-init:list" => {
229 decode_sasl_init_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslInit(r)))
230 }
231 Descriptor::Symbol(ref a) if a.as_str() == "amqp:sasl-challenge:list" => {
232 decode_sasl_challenge_inner(input)
233 .map(|(i, r)| (i, SaslFrameBody::SaslChallenge(r)))
234 }
235 Descriptor::Symbol(ref a) if a.as_str() == "amqp:sasl-response:list" => {
236 decode_sasl_response_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslResponse(r)))
237 }
238 Descriptor::Symbol(ref a) if a.as_str() == "amqp:sasl-outcome:list" => {
239 decode_sasl_outcome_inner(input).map(|(i, r)| (i, SaslFrameBody::SaslOutcome(r)))
240 }
241 _ => Err(AmqpParseError::InvalidDescriptor(descriptor)),
242 }
243 }
244}
245impl Encode for SaslFrameBody {
246 fn encoded_size(&self) -> usize {
247 match *self {
248 SaslFrameBody::SaslMechanisms(ref v) => encoded_size_sasl_mechanisms_inner(v),
249 SaslFrameBody::SaslInit(ref v) => encoded_size_sasl_init_inner(v),
250 SaslFrameBody::SaslChallenge(ref v) => encoded_size_sasl_challenge_inner(v),
251 SaslFrameBody::SaslResponse(ref v) => encoded_size_sasl_response_inner(v),
252 SaslFrameBody::SaslOutcome(ref v) => encoded_size_sasl_outcome_inner(v),
253 }
254 }
255 fn encode(&self, buf: &mut BytesMut) {
256 match *self {
257 SaslFrameBody::SaslMechanisms(ref v) => encode_sasl_mechanisms_inner(v, buf),
258 SaslFrameBody::SaslInit(ref v) => encode_sasl_init_inner(v, buf),
259 SaslFrameBody::SaslChallenge(ref v) => encode_sasl_challenge_inner(v, buf),
260 SaslFrameBody::SaslResponse(ref v) => encode_sasl_response_inner(v, buf),
261 SaslFrameBody::SaslOutcome(ref v) => encode_sasl_outcome_inner(v, buf),
262 }
263 }
264}
265#[derive(Clone, Debug, PartialEq)]
266pub enum Section {
267 Header(Header),
268 DeliveryAnnotations(DeliveryAnnotations),
269 MessageAnnotations(MessageAnnotations),
270 ApplicationProperties(ApplicationProperties),
271 Data(Data),
272 AmqpSequence(AmqpSequence),
273 AmqpValue(AmqpValue),
274 Footer(Footer),
275 Properties(Properties),
276}
277impl DecodeFormatted for Section {
278 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
279 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
280 let (input, descriptor) = Descriptor::decode(input)?;
281 match descriptor {
282 Descriptor::Ulong(112) => {
283 decode_header_inner(input).map(|(i, r)| (i, Section::Header(r)))
284 }
285 Descriptor::Ulong(113) => decode_delivery_annotations_inner(input)
286 .map(|(i, r)| (i, Section::DeliveryAnnotations(r))),
287 Descriptor::Ulong(114) => decode_message_annotations_inner(input)
288 .map(|(i, r)| (i, Section::MessageAnnotations(r))),
289 Descriptor::Ulong(116) => decode_application_properties_inner(input)
290 .map(|(i, r)| (i, Section::ApplicationProperties(r))),
291 Descriptor::Ulong(117) => decode_data_inner(input).map(|(i, r)| (i, Section::Data(r))),
292 Descriptor::Ulong(118) => {
293 decode_amqp_sequence_inner(input).map(|(i, r)| (i, Section::AmqpSequence(r)))
294 }
295 Descriptor::Ulong(119) => {
296 decode_amqp_value_inner(input).map(|(i, r)| (i, Section::AmqpValue(r)))
297 }
298 Descriptor::Ulong(120) => {
299 decode_footer_inner(input).map(|(i, r)| (i, Section::Footer(r)))
300 }
301 Descriptor::Ulong(115) => {
302 decode_properties_inner(input).map(|(i, r)| (i, Section::Properties(r)))
303 }
304 Descriptor::Symbol(ref a) if a.as_str() == "amqp:header:list" => {
305 decode_header_inner(input).map(|(i, r)| (i, Section::Header(r)))
306 }
307 Descriptor::Symbol(ref a) if a.as_str() == "amqp:delivery-annotations:map" => {
308 decode_delivery_annotations_inner(input)
309 .map(|(i, r)| (i, Section::DeliveryAnnotations(r)))
310 }
311 Descriptor::Symbol(ref a) if a.as_str() == "amqp:message-annotations:map" => {
312 decode_message_annotations_inner(input)
313 .map(|(i, r)| (i, Section::MessageAnnotations(r)))
314 }
315 Descriptor::Symbol(ref a) if a.as_str() == "amqp:application-properties:map" => {
316 decode_application_properties_inner(input)
317 .map(|(i, r)| (i, Section::ApplicationProperties(r)))
318 }
319 Descriptor::Symbol(ref a) if a.as_str() == "amqp:data:binary" => {
320 decode_data_inner(input).map(|(i, r)| (i, Section::Data(r)))
321 }
322 Descriptor::Symbol(ref a) if a.as_str() == "amqp:amqp-sequence:list" => {
323 decode_amqp_sequence_inner(input).map(|(i, r)| (i, Section::AmqpSequence(r)))
324 }
325 Descriptor::Symbol(ref a) if a.as_str() == "amqp:amqp-value:*" => {
326 decode_amqp_value_inner(input).map(|(i, r)| (i, Section::AmqpValue(r)))
327 }
328 Descriptor::Symbol(ref a) if a.as_str() == "amqp:footer:map" => {
329 decode_footer_inner(input).map(|(i, r)| (i, Section::Footer(r)))
330 }
331 Descriptor::Symbol(ref a) if a.as_str() == "amqp:properties:list" => {
332 decode_properties_inner(input).map(|(i, r)| (i, Section::Properties(r)))
333 }
334 _ => Err(AmqpParseError::InvalidDescriptor(descriptor)),
335 }
336 }
337}
338impl Encode for Section {
339 fn encoded_size(&self) -> usize {
340 match *self {
341 Section::Header(ref v) => encoded_size_header_inner(v),
342 Section::DeliveryAnnotations(ref v) => encoded_size_delivery_annotations_inner(v),
343 Section::MessageAnnotations(ref v) => encoded_size_message_annotations_inner(v),
344 Section::ApplicationProperties(ref v) => encoded_size_application_properties_inner(v),
345 Section::Data(ref v) => encoded_size_data_inner(v),
346 Section::AmqpSequence(ref v) => encoded_size_amqp_sequence_inner(v),
347 Section::AmqpValue(ref v) => encoded_size_amqp_value_inner(v),
348 Section::Footer(ref v) => encoded_size_footer_inner(v),
349 Section::Properties(ref v) => encoded_size_properties_inner(v),
350 }
351 }
352 fn encode(&self, buf: &mut BytesMut) {
353 match *self {
354 Section::Header(ref v) => encode_header_inner(v, buf),
355 Section::DeliveryAnnotations(ref v) => encode_delivery_annotations_inner(v, buf),
356 Section::MessageAnnotations(ref v) => encode_message_annotations_inner(v, buf),
357 Section::ApplicationProperties(ref v) => encode_application_properties_inner(v, buf),
358 Section::Data(ref v) => encode_data_inner(v, buf),
359 Section::AmqpSequence(ref v) => encode_amqp_sequence_inner(v, buf),
360 Section::AmqpValue(ref v) => encode_amqp_value_inner(v, buf),
361 Section::Footer(ref v) => encode_footer_inner(v, buf),
362 Section::Properties(ref v) => encode_properties_inner(v, buf),
363 }
364 }
365}
366#[derive(Clone, Debug, PartialEq)]
367pub enum Outcome {
368 Accepted(Accepted),
369 Rejected(Rejected),
370 Released(Released),
371 Modified(Modified),
372}
373impl DecodeFormatted for Outcome {
374 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
375 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
376 let (input, descriptor) = Descriptor::decode(input)?;
377 match descriptor {
378 Descriptor::Ulong(36) => {
379 decode_accepted_inner(input).map(|(i, r)| (i, Outcome::Accepted(r)))
380 }
381 Descriptor::Ulong(37) => {
382 decode_rejected_inner(input).map(|(i, r)| (i, Outcome::Rejected(r)))
383 }
384 Descriptor::Ulong(38) => {
385 decode_released_inner(input).map(|(i, r)| (i, Outcome::Released(r)))
386 }
387 Descriptor::Ulong(39) => {
388 decode_modified_inner(input).map(|(i, r)| (i, Outcome::Modified(r)))
389 }
390 Descriptor::Symbol(ref a) if a.as_str() == "amqp:accepted:list" => {
391 decode_accepted_inner(input).map(|(i, r)| (i, Outcome::Accepted(r)))
392 }
393 Descriptor::Symbol(ref a) if a.as_str() == "amqp:rejected:list" => {
394 decode_rejected_inner(input).map(|(i, r)| (i, Outcome::Rejected(r)))
395 }
396 Descriptor::Symbol(ref a) if a.as_str() == "amqp:released:list" => {
397 decode_released_inner(input).map(|(i, r)| (i, Outcome::Released(r)))
398 }
399 Descriptor::Symbol(ref a) if a.as_str() == "amqp:modified:list" => {
400 decode_modified_inner(input).map(|(i, r)| (i, Outcome::Modified(r)))
401 }
402 _ => Err(AmqpParseError::InvalidDescriptor(descriptor)),
403 }
404 }
405}
406impl Encode for Outcome {
407 fn encoded_size(&self) -> usize {
408 match *self {
409 Outcome::Accepted(ref v) => encoded_size_accepted_inner(v),
410 Outcome::Rejected(ref v) => encoded_size_rejected_inner(v),
411 Outcome::Released(ref v) => encoded_size_released_inner(v),
412 Outcome::Modified(ref v) => encoded_size_modified_inner(v),
413 }
414 }
415 fn encode(&self, buf: &mut BytesMut) {
416 match *self {
417 Outcome::Accepted(ref v) => encode_accepted_inner(v, buf),
418 Outcome::Rejected(ref v) => encode_rejected_inner(v, buf),
419 Outcome::Released(ref v) => encode_released_inner(v, buf),
420 Outcome::Modified(ref v) => encode_modified_inner(v, buf),
421 }
422 }
423}
424pub type Handle = u32;
425pub type Seconds = u32;
426pub type Milliseconds = u32;
427pub type DeliveryTag = Bytes;
428pub type SequenceNo = u32;
429pub type DeliveryNumber = SequenceNo;
430pub type TransferNumber = SequenceNo;
431pub type MessageFormat = u32;
432pub type IetfLanguageTag = Symbol;
433pub type NodeProperties = Fields;
434pub type MessageIdUlong = u64;
435pub type MessageIdUuid = Uuid;
436pub type MessageIdBinary = Bytes;
437pub type MessageIdString = ByteString;
438pub type Address = ByteString;
439#[derive(Clone, Copy, Debug, PartialEq)]
440pub enum Role {
441 Sender,
442 Receiver,
443}
444impl Role {
445 pub fn try_from(v: bool) -> Result<Self, AmqpParseError> {
446 match v {
447 false => Ok(Role::Sender),
448 true => Ok(Role::Receiver),
449 _ => Err(AmqpParseError::UnknownEnumOption("Role")),
450 }
451 }
452}
453impl DecodeFormatted for Role {
454 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
455 let (input, base) = bool::decode_with_format(input, fmt)?;
456 Ok((input, Self::try_from(base)?))
457 }
458}
459impl Encode for Role {
460 fn encoded_size(&self) -> usize {
461 match *self {
462 Role::Sender => {
463 let v: bool = false;
464 v.encoded_size()
465 }
466 Role::Receiver => {
467 let v: bool = true;
468 v.encoded_size()
469 }
470 }
471 }
472 fn encode(&self, buf: &mut BytesMut) {
473 match *self {
474 Role::Sender => {
475 let v: bool = false;
476 v.encode(buf);
477 }
478 Role::Receiver => {
479 let v: bool = true;
480 v.encode(buf);
481 }
482 }
483 }
484}
485#[derive(Clone, Copy, Debug, PartialEq)]
486pub enum SenderSettleMode {
487 Unsettled,
488 Settled,
489 Mixed,
490}
491impl SenderSettleMode {
492 pub fn try_from(v: u8) -> Result<Self, AmqpParseError> {
493 match v {
494 0 => Ok(SenderSettleMode::Unsettled),
495 1 => Ok(SenderSettleMode::Settled),
496 2 => Ok(SenderSettleMode::Mixed),
497 _ => Err(AmqpParseError::UnknownEnumOption("SenderSettleMode")),
498 }
499 }
500}
501impl DecodeFormatted for SenderSettleMode {
502 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
503 let (input, base) = u8::decode_with_format(input, fmt)?;
504 Ok((input, Self::try_from(base)?))
505 }
506}
507impl Encode for SenderSettleMode {
508 fn encoded_size(&self) -> usize {
509 match *self {
510 SenderSettleMode::Unsettled => {
511 let v: u8 = 0;
512 v.encoded_size()
513 }
514 SenderSettleMode::Settled => {
515 let v: u8 = 1;
516 v.encoded_size()
517 }
518 SenderSettleMode::Mixed => {
519 let v: u8 = 2;
520 v.encoded_size()
521 }
522 }
523 }
524 fn encode(&self, buf: &mut BytesMut) {
525 match *self {
526 SenderSettleMode::Unsettled => {
527 let v: u8 = 0;
528 v.encode(buf);
529 }
530 SenderSettleMode::Settled => {
531 let v: u8 = 1;
532 v.encode(buf);
533 }
534 SenderSettleMode::Mixed => {
535 let v: u8 = 2;
536 v.encode(buf);
537 }
538 }
539 }
540}
541#[derive(Clone, Copy, Debug, PartialEq)]
542pub enum ReceiverSettleMode {
543 First,
544 Second,
545}
546impl ReceiverSettleMode {
547 pub fn try_from(v: u8) -> Result<Self, AmqpParseError> {
548 match v {
549 0 => Ok(ReceiverSettleMode::First),
550 1 => Ok(ReceiverSettleMode::Second),
551 _ => Err(AmqpParseError::UnknownEnumOption("ReceiverSettleMode")),
552 }
553 }
554}
555impl DecodeFormatted for ReceiverSettleMode {
556 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
557 let (input, base) = u8::decode_with_format(input, fmt)?;
558 Ok((input, Self::try_from(base)?))
559 }
560}
561impl Encode for ReceiverSettleMode {
562 fn encoded_size(&self) -> usize {
563 match *self {
564 ReceiverSettleMode::First => {
565 let v: u8 = 0;
566 v.encoded_size()
567 }
568 ReceiverSettleMode::Second => {
569 let v: u8 = 1;
570 v.encoded_size()
571 }
572 }
573 }
574 fn encode(&self, buf: &mut BytesMut) {
575 match *self {
576 ReceiverSettleMode::First => {
577 let v: u8 = 0;
578 v.encode(buf);
579 }
580 ReceiverSettleMode::Second => {
581 let v: u8 = 1;
582 v.encode(buf);
583 }
584 }
585 }
586}
587#[derive(Clone, Copy, Debug, PartialEq)]
588pub enum AmqpError {
589 InternalError,
590 NotFound,
591 UnauthorizedAccess,
592 DecodeError,
593 ResourceLimitExceeded,
594 NotAllowed,
595 InvalidField,
596 NotImplemented,
597 ResourceLocked,
598 PreconditionFailed,
599 ResourceDeleted,
600 IllegalState,
601 FrameSizeTooSmall,
602}
603impl AmqpError {
604 pub fn try_from(v: &Symbol) -> Result<Self, AmqpParseError> {
605 match v.as_str() {
606 "amqp:internal-error" => Ok(AmqpError::InternalError),
607 "amqp:not-found" => Ok(AmqpError::NotFound),
608 "amqp:unauthorized-access" => Ok(AmqpError::UnauthorizedAccess),
609 "amqp:decode-error" => Ok(AmqpError::DecodeError),
610 "amqp:resource-limit-exceeded" => Ok(AmqpError::ResourceLimitExceeded),
611 "amqp:not-allowed" => Ok(AmqpError::NotAllowed),
612 "amqp:invalid-field" => Ok(AmqpError::InvalidField),
613 "amqp:not-implemented" => Ok(AmqpError::NotImplemented),
614 "amqp:resource-locked" => Ok(AmqpError::ResourceLocked),
615 "amqp:precondition-failed" => Ok(AmqpError::PreconditionFailed),
616 "amqp:resource-deleted" => Ok(AmqpError::ResourceDeleted),
617 "amqp:illegal-state" => Ok(AmqpError::IllegalState),
618 "amqp:frame-size-too-small" => Ok(AmqpError::FrameSizeTooSmall),
619 _ => Err(AmqpParseError::UnknownEnumOption("AmqpError")),
620 }
621 }
622}
623impl DecodeFormatted for AmqpError {
624 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
625 let (input, base) = Symbol::decode_with_format(input, fmt)?;
626 Ok((input, Self::try_from(&base)?))
627 }
628}
629impl Encode for AmqpError {
630 fn encoded_size(&self) -> usize {
631 match *self {
632 AmqpError::InternalError => 19 + 2,
633 AmqpError::NotFound => 14 + 2,
634 AmqpError::UnauthorizedAccess => 24 + 2,
635 AmqpError::DecodeError => 17 + 2,
636 AmqpError::ResourceLimitExceeded => 28 + 2,
637 AmqpError::NotAllowed => 16 + 2,
638 AmqpError::InvalidField => 18 + 2,
639 AmqpError::NotImplemented => 20 + 2,
640 AmqpError::ResourceLocked => 20 + 2,
641 AmqpError::PreconditionFailed => 24 + 2,
642 AmqpError::ResourceDeleted => 21 + 2,
643 AmqpError::IllegalState => 18 + 2,
644 AmqpError::FrameSizeTooSmall => 25 + 2,
645 }
646 }
647 fn encode(&self, buf: &mut BytesMut) {
648 match *self {
649 AmqpError::InternalError => StaticSymbol("amqp:internal-error").encode(buf),
650 AmqpError::NotFound => StaticSymbol("amqp:not-found").encode(buf),
651 AmqpError::UnauthorizedAccess => StaticSymbol("amqp:unauthorized-access").encode(buf),
652 AmqpError::DecodeError => StaticSymbol("amqp:decode-error").encode(buf),
653 AmqpError::ResourceLimitExceeded => {
654 StaticSymbol("amqp:resource-limit-exceeded").encode(buf)
655 }
656 AmqpError::NotAllowed => StaticSymbol("amqp:not-allowed").encode(buf),
657 AmqpError::InvalidField => StaticSymbol("amqp:invalid-field").encode(buf),
658 AmqpError::NotImplemented => StaticSymbol("amqp:not-implemented").encode(buf),
659 AmqpError::ResourceLocked => StaticSymbol("amqp:resource-locked").encode(buf),
660 AmqpError::PreconditionFailed => StaticSymbol("amqp:precondition-failed").encode(buf),
661 AmqpError::ResourceDeleted => StaticSymbol("amqp:resource-deleted").encode(buf),
662 AmqpError::IllegalState => StaticSymbol("amqp:illegal-state").encode(buf),
663 AmqpError::FrameSizeTooSmall => StaticSymbol("amqp:frame-size-too-small").encode(buf),
664 }
665 }
666}
667#[derive(Clone, Copy, Debug, PartialEq)]
668pub enum ConnectionError {
669 ConnectionForced,
670 FramingError,
671 Redirect,
672}
673impl ConnectionError {
674 pub fn try_from(v: &Symbol) -> Result<Self, AmqpParseError> {
675 match v.as_str() {
676 "amqp:connection:forced" => Ok(ConnectionError::ConnectionForced),
677 "amqp:connection:framing-error" => Ok(ConnectionError::FramingError),
678 "amqp:connection:redirect" => Ok(ConnectionError::Redirect),
679 _ => Err(AmqpParseError::UnknownEnumOption("ConnectionError")),
680 }
681 }
682}
683impl DecodeFormatted for ConnectionError {
684 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
685 let (input, base) = Symbol::decode_with_format(input, fmt)?;
686 Ok((input, Self::try_from(&base)?))
687 }
688}
689impl Encode for ConnectionError {
690 fn encoded_size(&self) -> usize {
691 match *self {
692 ConnectionError::ConnectionForced => 22 + 2,
693 ConnectionError::FramingError => 29 + 2,
694 ConnectionError::Redirect => 24 + 2,
695 }
696 }
697 fn encode(&self, buf: &mut BytesMut) {
698 match *self {
699 ConnectionError::ConnectionForced => StaticSymbol("amqp:connection:forced").encode(buf),
700 ConnectionError::FramingError => {
701 StaticSymbol("amqp:connection:framing-error").encode(buf)
702 }
703 ConnectionError::Redirect => StaticSymbol("amqp:connection:redirect").encode(buf),
704 }
705 }
706}
707#[derive(Clone, Copy, Debug, PartialEq)]
708pub enum SessionError {
709 WindowViolation,
710 ErrantLink,
711 HandleInUse,
712 UnattachedHandle,
713}
714impl SessionError {
715 pub fn try_from(v: &Symbol) -> Result<Self, AmqpParseError> {
716 match v.as_str() {
717 "amqp:session:window-violation" => Ok(SessionError::WindowViolation),
718 "amqp:session:errant-link" => Ok(SessionError::ErrantLink),
719 "amqp:session:handle-in-use" => Ok(SessionError::HandleInUse),
720 "amqp:session:unattached-handle" => Ok(SessionError::UnattachedHandle),
721 _ => Err(AmqpParseError::UnknownEnumOption("SessionError")),
722 }
723 }
724}
725impl DecodeFormatted for SessionError {
726 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
727 let (input, base) = Symbol::decode_with_format(input, fmt)?;
728 Ok((input, Self::try_from(&base)?))
729 }
730}
731impl Encode for SessionError {
732 fn encoded_size(&self) -> usize {
733 match *self {
734 SessionError::WindowViolation => 29 + 2,
735 SessionError::ErrantLink => 24 + 2,
736 SessionError::HandleInUse => 26 + 2,
737 SessionError::UnattachedHandle => 30 + 2,
738 }
739 }
740 fn encode(&self, buf: &mut BytesMut) {
741 match *self {
742 SessionError::WindowViolation => {
743 StaticSymbol("amqp:session:window-violation").encode(buf)
744 }
745 SessionError::ErrantLink => StaticSymbol("amqp:session:errant-link").encode(buf),
746 SessionError::HandleInUse => StaticSymbol("amqp:session:handle-in-use").encode(buf),
747 SessionError::UnattachedHandle => {
748 StaticSymbol("amqp:session:unattached-handle").encode(buf)
749 }
750 }
751 }
752}
753#[derive(Clone, Copy, Debug, PartialEq)]
754pub enum LinkError {
755 DetachForced,
756 TransferLimitExceeded,
757 MessageSizeExceeded,
758 Redirect,
759 Stolen,
760}
761impl LinkError {
762 pub fn try_from(v: &Symbol) -> Result<Self, AmqpParseError> {
763 match v.as_str() {
764 "amqp:link:detach-forced" => Ok(LinkError::DetachForced),
765 "amqp:link:transfer-limit-exceeded" => Ok(LinkError::TransferLimitExceeded),
766 "amqp:link:message-size-exceeded" => Ok(LinkError::MessageSizeExceeded),
767 "amqp:link:redirect" => Ok(LinkError::Redirect),
768 "amqp:link:stolen" => Ok(LinkError::Stolen),
769 _ => Err(AmqpParseError::UnknownEnumOption("LinkError")),
770 }
771 }
772}
773impl DecodeFormatted for LinkError {
774 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
775 let (input, base) = Symbol::decode_with_format(input, fmt)?;
776 Ok((input, Self::try_from(&base)?))
777 }
778}
779impl Encode for LinkError {
780 fn encoded_size(&self) -> usize {
781 match *self {
782 LinkError::DetachForced => 23 + 2,
783 LinkError::TransferLimitExceeded => 33 + 2,
784 LinkError::MessageSizeExceeded => 31 + 2,
785 LinkError::Redirect => 18 + 2,
786 LinkError::Stolen => 16 + 2,
787 }
788 }
789 fn encode(&self, buf: &mut BytesMut) {
790 match *self {
791 LinkError::DetachForced => StaticSymbol("amqp:link:detach-forced").encode(buf),
792 LinkError::TransferLimitExceeded => {
793 StaticSymbol("amqp:link:transfer-limit-exceeded").encode(buf)
794 }
795 LinkError::MessageSizeExceeded => {
796 StaticSymbol("amqp:link:message-size-exceeded").encode(buf)
797 }
798 LinkError::Redirect => StaticSymbol("amqp:link:redirect").encode(buf),
799 LinkError::Stolen => StaticSymbol("amqp:link:stolen").encode(buf),
800 }
801 }
802}
803#[derive(Clone, Copy, Debug, PartialEq)]
804pub enum SaslCode {
805 Ok,
806 Auth,
807 Sys,
808 SysPerm,
809 SysTemp,
810}
811impl SaslCode {
812 pub fn try_from(v: u8) -> Result<Self, AmqpParseError> {
813 match v {
814 0 => Ok(SaslCode::Ok),
815 1 => Ok(SaslCode::Auth),
816 2 => Ok(SaslCode::Sys),
817 3 => Ok(SaslCode::SysPerm),
818 4 => Ok(SaslCode::SysTemp),
819 _ => Err(AmqpParseError::UnknownEnumOption("SaslCode")),
820 }
821 }
822}
823impl DecodeFormatted for SaslCode {
824 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
825 let (input, base) = u8::decode_with_format(input, fmt)?;
826 Ok((input, Self::try_from(base)?))
827 }
828}
829impl Encode for SaslCode {
830 fn encoded_size(&self) -> usize {
831 match *self {
832 SaslCode::Ok => {
833 let v: u8 = 0;
834 v.encoded_size()
835 }
836 SaslCode::Auth => {
837 let v: u8 = 1;
838 v.encoded_size()
839 }
840 SaslCode::Sys => {
841 let v: u8 = 2;
842 v.encoded_size()
843 }
844 SaslCode::SysPerm => {
845 let v: u8 = 3;
846 v.encoded_size()
847 }
848 SaslCode::SysTemp => {
849 let v: u8 = 4;
850 v.encoded_size()
851 }
852 }
853 }
854 fn encode(&self, buf: &mut BytesMut) {
855 match *self {
856 SaslCode::Ok => {
857 let v: u8 = 0;
858 v.encode(buf);
859 }
860 SaslCode::Auth => {
861 let v: u8 = 1;
862 v.encode(buf);
863 }
864 SaslCode::Sys => {
865 let v: u8 = 2;
866 v.encode(buf);
867 }
868 SaslCode::SysPerm => {
869 let v: u8 = 3;
870 v.encode(buf);
871 }
872 SaslCode::SysTemp => {
873 let v: u8 = 4;
874 v.encode(buf);
875 }
876 }
877 }
878}
879#[derive(Clone, Copy, Debug, PartialEq)]
880pub enum TerminusDurability {
881 None,
882 Configuration,
883 UnsettledState,
884}
885impl TerminusDurability {
886 pub fn try_from(v: u32) -> Result<Self, AmqpParseError> {
887 match v {
888 0 => Ok(TerminusDurability::None),
889 1 => Ok(TerminusDurability::Configuration),
890 2 => Ok(TerminusDurability::UnsettledState),
891 _ => Err(AmqpParseError::UnknownEnumOption("TerminusDurability")),
892 }
893 }
894}
895impl DecodeFormatted for TerminusDurability {
896 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
897 let (input, base) = u32::decode_with_format(input, fmt)?;
898 Ok((input, Self::try_from(base)?))
899 }
900}
901impl Encode for TerminusDurability {
902 fn encoded_size(&self) -> usize {
903 match *self {
904 TerminusDurability::None => {
905 let v: u32 = 0;
906 v.encoded_size()
907 }
908 TerminusDurability::Configuration => {
909 let v: u32 = 1;
910 v.encoded_size()
911 }
912 TerminusDurability::UnsettledState => {
913 let v: u32 = 2;
914 v.encoded_size()
915 }
916 }
917 }
918 fn encode(&self, buf: &mut BytesMut) {
919 match *self {
920 TerminusDurability::None => {
921 let v: u32 = 0;
922 v.encode(buf);
923 }
924 TerminusDurability::Configuration => {
925 let v: u32 = 1;
926 v.encode(buf);
927 }
928 TerminusDurability::UnsettledState => {
929 let v: u32 = 2;
930 v.encode(buf);
931 }
932 }
933 }
934}
935#[derive(Clone, Copy, Debug, PartialEq)]
936pub enum TerminusExpiryPolicy {
937 LinkDetach,
938 SessionEnd,
939 ConnectionClose,
940 Never,
941}
942impl TerminusExpiryPolicy {
943 pub fn try_from(v: &Symbol) -> Result<Self, AmqpParseError> {
944 match v.as_str() {
945 "link-detach" => Ok(TerminusExpiryPolicy::LinkDetach),
946 "session-end" => Ok(TerminusExpiryPolicy::SessionEnd),
947 "connection-close" => Ok(TerminusExpiryPolicy::ConnectionClose),
948 "never" => Ok(TerminusExpiryPolicy::Never),
949 _ => Err(AmqpParseError::UnknownEnumOption("TerminusExpiryPolicy")),
950 }
951 }
952}
953impl DecodeFormatted for TerminusExpiryPolicy {
954 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
955 let (input, base) = Symbol::decode_with_format(input, fmt)?;
956 Ok((input, Self::try_from(&base)?))
957 }
958}
959impl Encode for TerminusExpiryPolicy {
960 fn encoded_size(&self) -> usize {
961 match *self {
962 TerminusExpiryPolicy::LinkDetach => 11 + 2,
963 TerminusExpiryPolicy::SessionEnd => 11 + 2,
964 TerminusExpiryPolicy::ConnectionClose => 16 + 2,
965 TerminusExpiryPolicy::Never => 5 + 2,
966 }
967 }
968 fn encode(&self, buf: &mut BytesMut) {
969 match *self {
970 TerminusExpiryPolicy::LinkDetach => StaticSymbol("link-detach").encode(buf),
971 TerminusExpiryPolicy::SessionEnd => StaticSymbol("session-end").encode(buf),
972 TerminusExpiryPolicy::ConnectionClose => StaticSymbol("connection-close").encode(buf),
973 TerminusExpiryPolicy::Never => StaticSymbol("never").encode(buf),
974 }
975 }
976}
977type DeliveryAnnotations = Annotations;
978fn decode_delivery_annotations_inner(
979 input: &[u8],
980) -> Result<(&[u8], DeliveryAnnotations), AmqpParseError> {
981 DeliveryAnnotations::decode(input)
982}
983fn encoded_size_delivery_annotations_inner(dr: &DeliveryAnnotations) -> usize {
984 3 + dr.encoded_size()
986}
987fn encode_delivery_annotations_inner(dr: &DeliveryAnnotations, buf: &mut BytesMut) {
988 Descriptor::Ulong(113).encode(buf);
989 dr.encode(buf);
990}
991type MessageAnnotations = Annotations;
992fn decode_message_annotations_inner(
993 input: &[u8],
994) -> Result<(&[u8], MessageAnnotations), AmqpParseError> {
995 MessageAnnotations::decode(input)
996}
997fn encoded_size_message_annotations_inner(dr: &MessageAnnotations) -> usize {
998 3 + dr.encoded_size()
1000}
1001fn encode_message_annotations_inner(dr: &MessageAnnotations, buf: &mut BytesMut) {
1002 Descriptor::Ulong(114).encode(buf);
1003 dr.encode(buf);
1004}
1005type ApplicationProperties = StringVariantMap;
1006fn decode_application_properties_inner(
1007 input: &[u8],
1008) -> Result<(&[u8], ApplicationProperties), AmqpParseError> {
1009 ApplicationProperties::decode(input)
1010}
1011fn encoded_size_application_properties_inner(dr: &ApplicationProperties) -> usize {
1012 3 + dr.encoded_size()
1014}
1015fn encode_application_properties_inner(dr: &ApplicationProperties, buf: &mut BytesMut) {
1016 Descriptor::Ulong(116).encode(buf);
1017 dr.encode(buf);
1018}
1019type Data = Bytes;
1020fn decode_data_inner(input: &[u8]) -> Result<(&[u8], Data), AmqpParseError> {
1021 Data::decode(input)
1022}
1023fn encoded_size_data_inner(dr: &Data) -> usize {
1024 3 + dr.encoded_size()
1026}
1027fn encode_data_inner(dr: &Data, buf: &mut BytesMut) {
1028 Descriptor::Ulong(117).encode(buf);
1029 dr.encode(buf);
1030}
1031type AmqpSequence = List;
1032fn decode_amqp_sequence_inner(input: &[u8]) -> Result<(&[u8], AmqpSequence), AmqpParseError> {
1033 AmqpSequence::decode(input)
1034}
1035fn encoded_size_amqp_sequence_inner(dr: &AmqpSequence) -> usize {
1036 3 + dr.encoded_size()
1038}
1039fn encode_amqp_sequence_inner(dr: &AmqpSequence, buf: &mut BytesMut) {
1040 Descriptor::Ulong(118).encode(buf);
1041 dr.encode(buf);
1042}
1043type AmqpValue = Variant;
1044fn decode_amqp_value_inner(input: &[u8]) -> Result<(&[u8], AmqpValue), AmqpParseError> {
1045 AmqpValue::decode(input)
1046}
1047fn encoded_size_amqp_value_inner(dr: &AmqpValue) -> usize {
1048 3 + dr.encoded_size()
1050}
1051fn encode_amqp_value_inner(dr: &AmqpValue, buf: &mut BytesMut) {
1052 Descriptor::Ulong(119).encode(buf);
1053 dr.encode(buf);
1054}
1055type Footer = Annotations;
1056fn decode_footer_inner(input: &[u8]) -> Result<(&[u8], Footer), AmqpParseError> {
1057 Footer::decode(input)
1058}
1059fn encoded_size_footer_inner(dr: &Footer) -> usize {
1060 3 + dr.encoded_size()
1062}
1063fn encode_footer_inner(dr: &Footer, buf: &mut BytesMut) {
1064 Descriptor::Ulong(120).encode(buf);
1065 dr.encode(buf);
1066}
1067#[derive(Clone, Debug, PartialEq)]
1068pub struct Error {
1069 pub condition: ErrorCondition,
1070 pub description: Option<ByteString>,
1071 pub info: Option<Fields>,
1072}
1073impl Error {
1074 pub fn condition(&self) -> &ErrorCondition {
1075 &self.condition
1076 }
1077 pub fn description(&self) -> Option<&ByteString> {
1078 self.description.as_ref()
1079 }
1080 pub fn info(&self) -> Option<&Fields> {
1081 self.info.as_ref()
1082 }
1083 #[allow(clippy::identity_op)]
1084 const FIELD_COUNT: usize = 0 + 1 + 1 + 1;
1085}
1086#[allow(unused_mut)]
1087fn decode_error_inner(input: &[u8]) -> Result<(&[u8], Error), AmqpParseError> {
1088 let (input, format) = decode_format_code(input)?;
1089 let (input, header) = decode_list_header(input, format)?;
1090 let size = header.size as usize;
1091 decode_check_len!(input, size);
1092 let (mut input, mut remainder) = input.split_at(size);
1093 let mut count = header.count;
1094 let condition: ErrorCondition;
1095 if count > 0 {
1096 let (in1, decoded) = ErrorCondition::decode(input)?;
1097 condition = decoded;
1098 input = in1;
1099 count -= 1;
1100 } else {
1101 return Err(AmqpParseError::RequiredFieldOmitted("condition"));
1102 }
1103 let description: Option<ByteString>;
1104 if count > 0 {
1105 let decoded = Option::<ByteString>::decode(input)?;
1106 input = decoded.0;
1107 description = decoded.1;
1108 count -= 1;
1109 } else {
1110 description = None;
1111 }
1112 let info: Option<Fields>;
1113 if count > 0 {
1114 let decoded = Option::<Fields>::decode(input)?;
1115 input = decoded.0;
1116 info = decoded.1;
1117 count -= 1;
1118 } else {
1119 info = None;
1120 }
1121 Ok((
1122 remainder,
1123 Error {
1124 condition,
1125 description,
1126 info,
1127 },
1128 ))
1129}
1130fn encoded_size_error_inner(list: &Error) -> usize {
1131 #[allow(clippy::identity_op)]
1132 let content_size = 0
1133 + list.condition.encoded_size()
1134 + list.description.encoded_size()
1135 + list.info.encoded_size();
1136 (if content_size + 1 > u8::MAX as usize {
1138 12
1139 } else {
1140 6
1141 }) + content_size
1142}
1143fn encode_error_inner(list: &Error, buf: &mut BytesMut) {
1144 Descriptor::Ulong(29).encode(buf);
1145 #[allow(clippy::identity_op)]
1146 let content_size = 0
1147 + list.condition.encoded_size()
1148 + list.description.encoded_size()
1149 + list.info.encoded_size();
1150 if content_size + 1 > u8::MAX as usize {
1151 buf.put_u8(codec::FORMATCODE_LIST32);
1152 buf.put_u32((content_size + 4) as u32); buf.put_u32(Error::FIELD_COUNT as u32);
1154 } else {
1155 buf.put_u8(codec::FORMATCODE_LIST8);
1156 buf.put_u8((content_size + 1) as u8);
1157 buf.put_u8(Error::FIELD_COUNT as u8);
1158 }
1159 list.condition.encode(buf);
1160 list.description.encode(buf);
1161 list.info.encode(buf);
1162}
1163impl DecodeFormatted for Error {
1164 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
1165 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
1166 let (input, descriptor) = Descriptor::decode(input)?;
1167 let is_match = match descriptor {
1168 Descriptor::Ulong(val) => val == 29,
1169 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:error:list",
1170 };
1171 if !is_match {
1172 Err(AmqpParseError::InvalidDescriptor(descriptor))
1173 } else {
1174 decode_error_inner(input)
1175 }
1176 }
1177}
1178impl Encode for Error {
1179 fn encoded_size(&self) -> usize {
1180 encoded_size_error_inner(self)
1181 }
1182 fn encode(&self, buf: &mut BytesMut) {
1183 encode_error_inner(self, buf)
1184 }
1185}
1186#[derive(Clone, Debug, PartialEq)]
1187pub struct Open {
1188 pub container_id: ByteString,
1189 pub hostname: Option<ByteString>,
1190 pub max_frame_size: u32,
1191 pub channel_max: u16,
1192 pub idle_time_out: Option<Milliseconds>,
1193 pub outgoing_locales: Option<IetfLanguageTags>,
1194 pub incoming_locales: Option<IetfLanguageTags>,
1195 pub offered_capabilities: Option<Symbols>,
1196 pub desired_capabilities: Option<Symbols>,
1197 pub properties: Option<Fields>,
1198}
1199impl Open {
1200 pub fn container_id(&self) -> &ByteString {
1201 &self.container_id
1202 }
1203 pub fn hostname(&self) -> Option<&ByteString> {
1204 self.hostname.as_ref()
1205 }
1206 pub fn max_frame_size(&self) -> u32 {
1207 self.max_frame_size
1208 }
1209 pub fn channel_max(&self) -> u16 {
1210 self.channel_max
1211 }
1212 pub fn idle_time_out(&self) -> Option<Milliseconds> {
1213 self.idle_time_out
1214 }
1215 pub fn outgoing_locales(&self) -> Option<&IetfLanguageTags> {
1216 self.outgoing_locales.as_ref()
1217 }
1218 pub fn incoming_locales(&self) -> Option<&IetfLanguageTags> {
1219 self.incoming_locales.as_ref()
1220 }
1221 pub fn offered_capabilities(&self) -> Option<&Symbols> {
1222 self.offered_capabilities.as_ref()
1223 }
1224 pub fn desired_capabilities(&self) -> Option<&Symbols> {
1225 self.desired_capabilities.as_ref()
1226 }
1227 pub fn properties(&self) -> Option<&Fields> {
1228 self.properties.as_ref()
1229 }
1230 #[allow(clippy::identity_op)]
1231 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
1232}
1233#[allow(unused_mut)]
1234fn decode_open_inner(input: &[u8]) -> Result<(&[u8], Open), AmqpParseError> {
1235 let (input, format) = decode_format_code(input)?;
1236 let (input, header) = decode_list_header(input, format)?;
1237 let size = header.size as usize;
1238 decode_check_len!(input, size);
1239 let (mut input, mut remainder) = input.split_at(size);
1240 let mut count = header.count;
1241 let container_id: ByteString;
1242 if count > 0 {
1243 let (in1, decoded) = ByteString::decode(input)?;
1244 container_id = decoded;
1245 input = in1;
1246 count -= 1;
1247 } else {
1248 return Err(AmqpParseError::RequiredFieldOmitted("container_id"));
1249 }
1250 let hostname: Option<ByteString>;
1251 if count > 0 {
1252 let decoded = Option::<ByteString>::decode(input)?;
1253 input = decoded.0;
1254 hostname = decoded.1;
1255 count -= 1;
1256 } else {
1257 hostname = None;
1258 }
1259 let max_frame_size: u32;
1260 if count > 0 {
1261 let (in1, decoded) = Option::<u32>::decode(input)?;
1262 max_frame_size = decoded.unwrap_or(4294967295);
1263 input = in1;
1264 count -= 1;
1265 } else {
1266 max_frame_size = 4294967295;
1267 }
1268 let channel_max: u16;
1269 if count > 0 {
1270 let (in1, decoded) = Option::<u16>::decode(input)?;
1271 channel_max = decoded.unwrap_or(65535);
1272 input = in1;
1273 count -= 1;
1274 } else {
1275 channel_max = 65535;
1276 }
1277 let idle_time_out: Option<Milliseconds>;
1278 if count > 0 {
1279 let decoded = Option::<Milliseconds>::decode(input)?;
1280 input = decoded.0;
1281 idle_time_out = decoded.1;
1282 count -= 1;
1283 } else {
1284 idle_time_out = None;
1285 }
1286 let outgoing_locales: Option<IetfLanguageTags>;
1287 if count > 0 {
1288 let decoded = Option::<IetfLanguageTags>::decode(input)?;
1289 input = decoded.0;
1290 outgoing_locales = decoded.1;
1291 count -= 1;
1292 } else {
1293 outgoing_locales = None;
1294 }
1295 let incoming_locales: Option<IetfLanguageTags>;
1296 if count > 0 {
1297 let decoded = Option::<IetfLanguageTags>::decode(input)?;
1298 input = decoded.0;
1299 incoming_locales = decoded.1;
1300 count -= 1;
1301 } else {
1302 incoming_locales = None;
1303 }
1304 let offered_capabilities: Option<Symbols>;
1305 if count > 0 {
1306 let decoded = Option::<Symbols>::decode(input)?;
1307 input = decoded.0;
1308 offered_capabilities = decoded.1;
1309 count -= 1;
1310 } else {
1311 offered_capabilities = None;
1312 }
1313 let desired_capabilities: Option<Symbols>;
1314 if count > 0 {
1315 let decoded = Option::<Symbols>::decode(input)?;
1316 input = decoded.0;
1317 desired_capabilities = decoded.1;
1318 count -= 1;
1319 } else {
1320 desired_capabilities = None;
1321 }
1322 let properties: Option<Fields>;
1323 if count > 0 {
1324 let decoded = Option::<Fields>::decode(input)?;
1325 input = decoded.0;
1326 properties = decoded.1;
1327 count -= 1;
1328 } else {
1329 properties = None;
1330 }
1331 Ok((
1332 remainder,
1333 Open {
1334 container_id,
1335 hostname,
1336 max_frame_size,
1337 channel_max,
1338 idle_time_out,
1339 outgoing_locales,
1340 incoming_locales,
1341 offered_capabilities,
1342 desired_capabilities,
1343 properties,
1344 },
1345 ))
1346}
1347fn encoded_size_open_inner(list: &Open) -> usize {
1348 #[allow(clippy::identity_op)]
1349 let content_size = 0
1350 + list.container_id.encoded_size()
1351 + list.hostname.encoded_size()
1352 + list.max_frame_size.encoded_size()
1353 + list.channel_max.encoded_size()
1354 + list.idle_time_out.encoded_size()
1355 + list.outgoing_locales.encoded_size()
1356 + list.incoming_locales.encoded_size()
1357 + list.offered_capabilities.encoded_size()
1358 + list.desired_capabilities.encoded_size()
1359 + list.properties.encoded_size();
1360 (if content_size + 1 > u8::MAX as usize {
1362 12
1363 } else {
1364 6
1365 }) + content_size
1366}
1367fn encode_open_inner(list: &Open, buf: &mut BytesMut) {
1368 Descriptor::Ulong(16).encode(buf);
1369 #[allow(clippy::identity_op)]
1370 let content_size = 0
1371 + list.container_id.encoded_size()
1372 + list.hostname.encoded_size()
1373 + list.max_frame_size.encoded_size()
1374 + list.channel_max.encoded_size()
1375 + list.idle_time_out.encoded_size()
1376 + list.outgoing_locales.encoded_size()
1377 + list.incoming_locales.encoded_size()
1378 + list.offered_capabilities.encoded_size()
1379 + list.desired_capabilities.encoded_size()
1380 + list.properties.encoded_size();
1381 if content_size + 1 > u8::MAX as usize {
1382 buf.put_u8(codec::FORMATCODE_LIST32);
1383 buf.put_u32((content_size + 4) as u32); buf.put_u32(Open::FIELD_COUNT as u32);
1385 } else {
1386 buf.put_u8(codec::FORMATCODE_LIST8);
1387 buf.put_u8((content_size + 1) as u8);
1388 buf.put_u8(Open::FIELD_COUNT as u8);
1389 }
1390 list.container_id.encode(buf);
1391 list.hostname.encode(buf);
1392 list.max_frame_size.encode(buf);
1393 list.channel_max.encode(buf);
1394 list.idle_time_out.encode(buf);
1395 list.outgoing_locales.encode(buf);
1396 list.incoming_locales.encode(buf);
1397 list.offered_capabilities.encode(buf);
1398 list.desired_capabilities.encode(buf);
1399 list.properties.encode(buf);
1400}
1401impl DecodeFormatted for Open {
1402 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
1403 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
1404 let (input, descriptor) = Descriptor::decode(input)?;
1405 let is_match = match descriptor {
1406 Descriptor::Ulong(val) => val == 16,
1407 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:open:list",
1408 };
1409 if !is_match {
1410 Err(AmqpParseError::InvalidDescriptor(descriptor))
1411 } else {
1412 decode_open_inner(input)
1413 }
1414 }
1415}
1416impl Encode for Open {
1417 fn encoded_size(&self) -> usize {
1418 encoded_size_open_inner(self)
1419 }
1420 fn encode(&self, buf: &mut BytesMut) {
1421 encode_open_inner(self, buf)
1422 }
1423}
1424#[derive(Clone, Debug, PartialEq)]
1425pub struct Begin {
1426 pub remote_channel: Option<u16>,
1427 pub next_outgoing_id: TransferNumber,
1428 pub incoming_window: u32,
1429 pub outgoing_window: u32,
1430 pub handle_max: Handle,
1431 pub offered_capabilities: Option<Symbols>,
1432 pub desired_capabilities: Option<Symbols>,
1433 pub properties: Option<Fields>,
1434}
1435impl Begin {
1436 pub fn remote_channel(&self) -> Option<u16> {
1437 self.remote_channel
1438 }
1439 pub fn next_outgoing_id(&self) -> TransferNumber {
1440 self.next_outgoing_id
1441 }
1442 pub fn incoming_window(&self) -> u32 {
1443 self.incoming_window
1444 }
1445 pub fn outgoing_window(&self) -> u32 {
1446 self.outgoing_window
1447 }
1448 pub fn handle_max(&self) -> Handle {
1449 self.handle_max
1450 }
1451 pub fn offered_capabilities(&self) -> Option<&Symbols> {
1452 self.offered_capabilities.as_ref()
1453 }
1454 pub fn desired_capabilities(&self) -> Option<&Symbols> {
1455 self.desired_capabilities.as_ref()
1456 }
1457 pub fn properties(&self) -> Option<&Fields> {
1458 self.properties.as_ref()
1459 }
1460 #[allow(clippy::identity_op)]
1461 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
1462}
1463#[allow(unused_mut)]
1464fn decode_begin_inner(input: &[u8]) -> Result<(&[u8], Begin), AmqpParseError> {
1465 let (input, format) = decode_format_code(input)?;
1466 let (input, header) = decode_list_header(input, format)?;
1467 let size = header.size as usize;
1468 decode_check_len!(input, size);
1469 let (mut input, mut remainder) = input.split_at(size);
1470 let mut count = header.count;
1471 let remote_channel: Option<u16>;
1472 if count > 0 {
1473 let decoded = Option::<u16>::decode(input)?;
1474 input = decoded.0;
1475 remote_channel = decoded.1;
1476 count -= 1;
1477 } else {
1478 remote_channel = None;
1479 }
1480 let next_outgoing_id: TransferNumber;
1481 if count > 0 {
1482 let (in1, decoded) = TransferNumber::decode(input)?;
1483 next_outgoing_id = decoded;
1484 input = in1;
1485 count -= 1;
1486 } else {
1487 return Err(AmqpParseError::RequiredFieldOmitted("next_outgoing_id"));
1488 }
1489 let incoming_window: u32;
1490 if count > 0 {
1491 let (in1, decoded) = u32::decode(input)?;
1492 incoming_window = decoded;
1493 input = in1;
1494 count -= 1;
1495 } else {
1496 return Err(AmqpParseError::RequiredFieldOmitted("incoming_window"));
1497 }
1498 let outgoing_window: u32;
1499 if count > 0 {
1500 let (in1, decoded) = u32::decode(input)?;
1501 outgoing_window = decoded;
1502 input = in1;
1503 count -= 1;
1504 } else {
1505 return Err(AmqpParseError::RequiredFieldOmitted("outgoing_window"));
1506 }
1507 let handle_max: Handle;
1508 if count > 0 {
1509 let (in1, decoded) = Option::<Handle>::decode(input)?;
1510 handle_max = decoded.unwrap_or(4294967295);
1511 input = in1;
1512 count -= 1;
1513 } else {
1514 handle_max = 4294967295;
1515 }
1516 let offered_capabilities: Option<Symbols>;
1517 if count > 0 {
1518 let decoded = Option::<Symbols>::decode(input)?;
1519 input = decoded.0;
1520 offered_capabilities = decoded.1;
1521 count -= 1;
1522 } else {
1523 offered_capabilities = None;
1524 }
1525 let desired_capabilities: Option<Symbols>;
1526 if count > 0 {
1527 let decoded = Option::<Symbols>::decode(input)?;
1528 input = decoded.0;
1529 desired_capabilities = decoded.1;
1530 count -= 1;
1531 } else {
1532 desired_capabilities = None;
1533 }
1534 let properties: Option<Fields>;
1535 if count > 0 {
1536 let decoded = Option::<Fields>::decode(input)?;
1537 input = decoded.0;
1538 properties = decoded.1;
1539 count -= 1;
1540 } else {
1541 properties = None;
1542 }
1543 Ok((
1544 remainder,
1545 Begin {
1546 remote_channel,
1547 next_outgoing_id,
1548 incoming_window,
1549 outgoing_window,
1550 handle_max,
1551 offered_capabilities,
1552 desired_capabilities,
1553 properties,
1554 },
1555 ))
1556}
1557fn encoded_size_begin_inner(list: &Begin) -> usize {
1558 #[allow(clippy::identity_op)]
1559 let content_size = 0
1560 + list.remote_channel.encoded_size()
1561 + list.next_outgoing_id.encoded_size()
1562 + list.incoming_window.encoded_size()
1563 + list.outgoing_window.encoded_size()
1564 + list.handle_max.encoded_size()
1565 + list.offered_capabilities.encoded_size()
1566 + list.desired_capabilities.encoded_size()
1567 + list.properties.encoded_size();
1568 (if content_size + 1 > u8::MAX as usize {
1570 12
1571 } else {
1572 6
1573 }) + content_size
1574}
1575fn encode_begin_inner(list: &Begin, buf: &mut BytesMut) {
1576 Descriptor::Ulong(17).encode(buf);
1577 #[allow(clippy::identity_op)]
1578 let content_size = 0
1579 + list.remote_channel.encoded_size()
1580 + list.next_outgoing_id.encoded_size()
1581 + list.incoming_window.encoded_size()
1582 + list.outgoing_window.encoded_size()
1583 + list.handle_max.encoded_size()
1584 + list.offered_capabilities.encoded_size()
1585 + list.desired_capabilities.encoded_size()
1586 + list.properties.encoded_size();
1587 if content_size + 1 > u8::MAX as usize {
1588 buf.put_u8(codec::FORMATCODE_LIST32);
1589 buf.put_u32((content_size + 4) as u32); buf.put_u32(Begin::FIELD_COUNT as u32);
1591 } else {
1592 buf.put_u8(codec::FORMATCODE_LIST8);
1593 buf.put_u8((content_size + 1) as u8);
1594 buf.put_u8(Begin::FIELD_COUNT as u8);
1595 }
1596 list.remote_channel.encode(buf);
1597 list.next_outgoing_id.encode(buf);
1598 list.incoming_window.encode(buf);
1599 list.outgoing_window.encode(buf);
1600 list.handle_max.encode(buf);
1601 list.offered_capabilities.encode(buf);
1602 list.desired_capabilities.encode(buf);
1603 list.properties.encode(buf);
1604}
1605impl DecodeFormatted for Begin {
1606 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
1607 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
1608 let (input, descriptor) = Descriptor::decode(input)?;
1609 let is_match = match descriptor {
1610 Descriptor::Ulong(val) => val == 17,
1611 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:begin:list",
1612 };
1613 if !is_match {
1614 Err(AmqpParseError::InvalidDescriptor(descriptor))
1615 } else {
1616 decode_begin_inner(input)
1617 }
1618 }
1619}
1620impl Encode for Begin {
1621 fn encoded_size(&self) -> usize {
1622 encoded_size_begin_inner(self)
1623 }
1624 fn encode(&self, buf: &mut BytesMut) {
1625 encode_begin_inner(self, buf)
1626 }
1627}
1628#[derive(Clone, Debug, PartialEq)]
1629pub struct Attach {
1630 pub name: ByteString,
1631 pub handle: Handle,
1632 pub role: Role,
1633 pub snd_settle_mode: SenderSettleMode,
1634 pub rcv_settle_mode: ReceiverSettleMode,
1635 pub source: Option<Source>,
1636 pub target: Option<Target>,
1637 pub unsettled: Option<Map>,
1638 pub incomplete_unsettled: bool,
1639 pub initial_delivery_count: Option<SequenceNo>,
1640 pub max_message_size: Option<u64>,
1641 pub offered_capabilities: Option<Symbols>,
1642 pub desired_capabilities: Option<Symbols>,
1643 pub properties: Option<Fields>,
1644}
1645impl Attach {
1646 pub fn name(&self) -> &ByteString {
1647 &self.name
1648 }
1649 pub fn handle(&self) -> Handle {
1650 self.handle
1651 }
1652 pub fn role(&self) -> Role {
1653 self.role
1654 }
1655 pub fn snd_settle_mode(&self) -> SenderSettleMode {
1656 self.snd_settle_mode
1657 }
1658 pub fn rcv_settle_mode(&self) -> ReceiverSettleMode {
1659 self.rcv_settle_mode
1660 }
1661 pub fn source(&self) -> Option<&Source> {
1662 self.source.as_ref()
1663 }
1664 pub fn target(&self) -> Option<&Target> {
1665 self.target.as_ref()
1666 }
1667 pub fn unsettled(&self) -> Option<&Map> {
1668 self.unsettled.as_ref()
1669 }
1670 pub fn incomplete_unsettled(&self) -> bool {
1671 self.incomplete_unsettled
1672 }
1673 pub fn initial_delivery_count(&self) -> Option<SequenceNo> {
1674 self.initial_delivery_count
1675 }
1676 pub fn max_message_size(&self) -> Option<u64> {
1677 self.max_message_size
1678 }
1679 pub fn offered_capabilities(&self) -> Option<&Symbols> {
1680 self.offered_capabilities.as_ref()
1681 }
1682 pub fn desired_capabilities(&self) -> Option<&Symbols> {
1683 self.desired_capabilities.as_ref()
1684 }
1685 pub fn properties(&self) -> Option<&Fields> {
1686 self.properties.as_ref()
1687 }
1688 #[allow(clippy::identity_op)]
1689 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
1690}
1691#[allow(unused_mut)]
1692fn decode_attach_inner(input: &[u8]) -> Result<(&[u8], Attach), AmqpParseError> {
1693 let (input, format) = decode_format_code(input)?;
1694 let (input, header) = decode_list_header(input, format)?;
1695 let size = header.size as usize;
1696 decode_check_len!(input, size);
1697 let (mut input, mut remainder) = input.split_at(size);
1698 let mut count = header.count;
1699 let name: ByteString;
1700 if count > 0 {
1701 let (in1, decoded) = ByteString::decode(input)?;
1702 name = decoded;
1703 input = in1;
1704 count -= 1;
1705 } else {
1706 return Err(AmqpParseError::RequiredFieldOmitted("name"));
1707 }
1708 let handle: Handle;
1709 if count > 0 {
1710 let (in1, decoded) = Handle::decode(input)?;
1711 handle = decoded;
1712 input = in1;
1713 count -= 1;
1714 } else {
1715 return Err(AmqpParseError::RequiredFieldOmitted("handle"));
1716 }
1717 let role: Role;
1718 if count > 0 {
1719 let (in1, decoded) = Role::decode(input)?;
1720 role = decoded;
1721 input = in1;
1722 count -= 1;
1723 } else {
1724 return Err(AmqpParseError::RequiredFieldOmitted("role"));
1725 }
1726 let snd_settle_mode: SenderSettleMode;
1727 if count > 0 {
1728 let (in1, decoded) = Option::<SenderSettleMode>::decode(input)?;
1729 snd_settle_mode = decoded.unwrap_or(SenderSettleMode::Mixed);
1730 input = in1;
1731 count -= 1;
1732 } else {
1733 snd_settle_mode = SenderSettleMode::Mixed;
1734 }
1735 let rcv_settle_mode: ReceiverSettleMode;
1736 if count > 0 {
1737 let (in1, decoded) = Option::<ReceiverSettleMode>::decode(input)?;
1738 rcv_settle_mode = decoded.unwrap_or(ReceiverSettleMode::First);
1739 input = in1;
1740 count -= 1;
1741 } else {
1742 rcv_settle_mode = ReceiverSettleMode::First;
1743 }
1744 let source: Option<Source>;
1745 if count > 0 {
1746 let decoded = Option::<Source>::decode(input)?;
1747 input = decoded.0;
1748 source = decoded.1;
1749 count -= 1;
1750 } else {
1751 source = None;
1752 }
1753 let target: Option<Target>;
1754 if count > 0 {
1755 let decoded = Option::<Target>::decode(input)?;
1756 input = decoded.0;
1757 target = decoded.1;
1758 count -= 1;
1759 } else {
1760 target = None;
1761 }
1762 let unsettled: Option<Map>;
1763 if count > 0 {
1764 let decoded = Option::<Map>::decode(input)?;
1765 input = decoded.0;
1766 unsettled = decoded.1;
1767 count -= 1;
1768 } else {
1769 unsettled = None;
1770 }
1771 let incomplete_unsettled: bool;
1772 if count > 0 {
1773 let (in1, decoded) = Option::<bool>::decode(input)?;
1774 incomplete_unsettled = decoded.unwrap_or(false);
1775 input = in1;
1776 count -= 1;
1777 } else {
1778 incomplete_unsettled = false;
1779 }
1780 let initial_delivery_count: Option<SequenceNo>;
1781 if count > 0 {
1782 let decoded = Option::<SequenceNo>::decode(input)?;
1783 input = decoded.0;
1784 initial_delivery_count = decoded.1;
1785 count -= 1;
1786 } else {
1787 initial_delivery_count = None;
1788 }
1789 let max_message_size: Option<u64>;
1790 if count > 0 {
1791 let decoded = Option::<u64>::decode(input)?;
1792 input = decoded.0;
1793 max_message_size = decoded.1;
1794 count -= 1;
1795 } else {
1796 max_message_size = None;
1797 }
1798 let offered_capabilities: Option<Symbols>;
1799 if count > 0 {
1800 let decoded = Option::<Symbols>::decode(input)?;
1801 input = decoded.0;
1802 offered_capabilities = decoded.1;
1803 count -= 1;
1804 } else {
1805 offered_capabilities = None;
1806 }
1807 let desired_capabilities: Option<Symbols>;
1808 if count > 0 {
1809 let decoded = Option::<Symbols>::decode(input)?;
1810 input = decoded.0;
1811 desired_capabilities = decoded.1;
1812 count -= 1;
1813 } else {
1814 desired_capabilities = None;
1815 }
1816 let properties: Option<Fields>;
1817 if count > 0 {
1818 let decoded = Option::<Fields>::decode(input)?;
1819 input = decoded.0;
1820 properties = decoded.1;
1821 count -= 1;
1822 } else {
1823 properties = None;
1824 }
1825 Ok((
1826 remainder,
1827 Attach {
1828 name,
1829 handle,
1830 role,
1831 snd_settle_mode,
1832 rcv_settle_mode,
1833 source,
1834 target,
1835 unsettled,
1836 incomplete_unsettled,
1837 initial_delivery_count,
1838 max_message_size,
1839 offered_capabilities,
1840 desired_capabilities,
1841 properties,
1842 },
1843 ))
1844}
1845fn encoded_size_attach_inner(list: &Attach) -> usize {
1846 #[allow(clippy::identity_op)]
1847 let content_size = 0
1848 + list.name.encoded_size()
1849 + list.handle.encoded_size()
1850 + list.role.encoded_size()
1851 + list.snd_settle_mode.encoded_size()
1852 + list.rcv_settle_mode.encoded_size()
1853 + list.source.encoded_size()
1854 + list.target.encoded_size()
1855 + list.unsettled.encoded_size()
1856 + list.incomplete_unsettled.encoded_size()
1857 + list.initial_delivery_count.encoded_size()
1858 + list.max_message_size.encoded_size()
1859 + list.offered_capabilities.encoded_size()
1860 + list.desired_capabilities.encoded_size()
1861 + list.properties.encoded_size();
1862 (if content_size + 1 > u8::MAX as usize {
1864 12
1865 } else {
1866 6
1867 }) + content_size
1868}
1869fn encode_attach_inner(list: &Attach, buf: &mut BytesMut) {
1870 Descriptor::Ulong(18).encode(buf);
1871 #[allow(clippy::identity_op)]
1872 let content_size = 0
1873 + list.name.encoded_size()
1874 + list.handle.encoded_size()
1875 + list.role.encoded_size()
1876 + list.snd_settle_mode.encoded_size()
1877 + list.rcv_settle_mode.encoded_size()
1878 + list.source.encoded_size()
1879 + list.target.encoded_size()
1880 + list.unsettled.encoded_size()
1881 + list.incomplete_unsettled.encoded_size()
1882 + list.initial_delivery_count.encoded_size()
1883 + list.max_message_size.encoded_size()
1884 + list.offered_capabilities.encoded_size()
1885 + list.desired_capabilities.encoded_size()
1886 + list.properties.encoded_size();
1887 if content_size + 1 > u8::MAX as usize {
1888 buf.put_u8(codec::FORMATCODE_LIST32);
1889 buf.put_u32((content_size + 4) as u32); buf.put_u32(Attach::FIELD_COUNT as u32);
1891 } else {
1892 buf.put_u8(codec::FORMATCODE_LIST8);
1893 buf.put_u8((content_size + 1) as u8);
1894 buf.put_u8(Attach::FIELD_COUNT as u8);
1895 }
1896 list.name.encode(buf);
1897 list.handle.encode(buf);
1898 list.role.encode(buf);
1899 list.snd_settle_mode.encode(buf);
1900 list.rcv_settle_mode.encode(buf);
1901 list.source.encode(buf);
1902 list.target.encode(buf);
1903 list.unsettled.encode(buf);
1904 list.incomplete_unsettled.encode(buf);
1905 list.initial_delivery_count.encode(buf);
1906 list.max_message_size.encode(buf);
1907 list.offered_capabilities.encode(buf);
1908 list.desired_capabilities.encode(buf);
1909 list.properties.encode(buf);
1910}
1911impl DecodeFormatted for Attach {
1912 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
1913 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
1914 let (input, descriptor) = Descriptor::decode(input)?;
1915 let is_match = match descriptor {
1916 Descriptor::Ulong(val) => val == 18,
1917 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:attach:list",
1918 };
1919 if !is_match {
1920 Err(AmqpParseError::InvalidDescriptor(descriptor))
1921 } else {
1922 decode_attach_inner(input)
1923 }
1924 }
1925}
1926impl Encode for Attach {
1927 fn encoded_size(&self) -> usize {
1928 encoded_size_attach_inner(self)
1929 }
1930 fn encode(&self, buf: &mut BytesMut) {
1931 encode_attach_inner(self, buf)
1932 }
1933}
1934#[derive(Clone, Debug, PartialEq)]
1935pub struct Flow {
1936 pub next_incoming_id: Option<TransferNumber>,
1937 pub incoming_window: u32,
1938 pub next_outgoing_id: TransferNumber,
1939 pub outgoing_window: u32,
1940 pub handle: Option<Handle>,
1941 pub delivery_count: Option<SequenceNo>,
1942 pub link_credit: Option<u32>,
1943 pub available: Option<u32>,
1944 pub drain: bool,
1945 pub echo: bool,
1946 pub properties: Option<Fields>,
1947}
1948impl Flow {
1949 pub fn next_incoming_id(&self) -> Option<TransferNumber> {
1950 self.next_incoming_id
1951 }
1952 pub fn incoming_window(&self) -> u32 {
1953 self.incoming_window
1954 }
1955 pub fn next_outgoing_id(&self) -> TransferNumber {
1956 self.next_outgoing_id
1957 }
1958 pub fn outgoing_window(&self) -> u32 {
1959 self.outgoing_window
1960 }
1961 pub fn handle(&self) -> Option<Handle> {
1962 self.handle
1963 }
1964 pub fn delivery_count(&self) -> Option<SequenceNo> {
1965 self.delivery_count
1966 }
1967 pub fn link_credit(&self) -> Option<u32> {
1968 self.link_credit
1969 }
1970 pub fn available(&self) -> Option<u32> {
1971 self.available
1972 }
1973 pub fn drain(&self) -> bool {
1974 self.drain
1975 }
1976 pub fn echo(&self) -> bool {
1977 self.echo
1978 }
1979 pub fn properties(&self) -> Option<&Fields> {
1980 self.properties.as_ref()
1981 }
1982 #[allow(clippy::identity_op)]
1983 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
1984}
1985#[allow(unused_mut)]
1986fn decode_flow_inner(input: &[u8]) -> Result<(&[u8], Flow), AmqpParseError> {
1987 let (input, format) = decode_format_code(input)?;
1988 let (input, header) = decode_list_header(input, format)?;
1989 let size = header.size as usize;
1990 decode_check_len!(input, size);
1991 let (mut input, mut remainder) = input.split_at(size);
1992 let mut count = header.count;
1993 let next_incoming_id: Option<TransferNumber>;
1994 if count > 0 {
1995 let decoded = Option::<TransferNumber>::decode(input)?;
1996 input = decoded.0;
1997 next_incoming_id = decoded.1;
1998 count -= 1;
1999 } else {
2000 next_incoming_id = None;
2001 }
2002 let incoming_window: u32;
2003 if count > 0 {
2004 let (in1, decoded) = u32::decode(input)?;
2005 incoming_window = decoded;
2006 input = in1;
2007 count -= 1;
2008 } else {
2009 return Err(AmqpParseError::RequiredFieldOmitted("incoming_window"));
2010 }
2011 let next_outgoing_id: TransferNumber;
2012 if count > 0 {
2013 let (in1, decoded) = TransferNumber::decode(input)?;
2014 next_outgoing_id = decoded;
2015 input = in1;
2016 count -= 1;
2017 } else {
2018 return Err(AmqpParseError::RequiredFieldOmitted("next_outgoing_id"));
2019 }
2020 let outgoing_window: u32;
2021 if count > 0 {
2022 let (in1, decoded) = u32::decode(input)?;
2023 outgoing_window = decoded;
2024 input = in1;
2025 count -= 1;
2026 } else {
2027 return Err(AmqpParseError::RequiredFieldOmitted("outgoing_window"));
2028 }
2029 let handle: Option<Handle>;
2030 if count > 0 {
2031 let decoded = Option::<Handle>::decode(input)?;
2032 input = decoded.0;
2033 handle = decoded.1;
2034 count -= 1;
2035 } else {
2036 handle = None;
2037 }
2038 let delivery_count: Option<SequenceNo>;
2039 if count > 0 {
2040 let decoded = Option::<SequenceNo>::decode(input)?;
2041 input = decoded.0;
2042 delivery_count = decoded.1;
2043 count -= 1;
2044 } else {
2045 delivery_count = None;
2046 }
2047 let link_credit: Option<u32>;
2048 if count > 0 {
2049 let decoded = Option::<u32>::decode(input)?;
2050 input = decoded.0;
2051 link_credit = decoded.1;
2052 count -= 1;
2053 } else {
2054 link_credit = None;
2055 }
2056 let available: Option<u32>;
2057 if count > 0 {
2058 let decoded = Option::<u32>::decode(input)?;
2059 input = decoded.0;
2060 available = decoded.1;
2061 count -= 1;
2062 } else {
2063 available = None;
2064 }
2065 let drain: bool;
2066 if count > 0 {
2067 let (in1, decoded) = Option::<bool>::decode(input)?;
2068 drain = decoded.unwrap_or(false);
2069 input = in1;
2070 count -= 1;
2071 } else {
2072 drain = false;
2073 }
2074 let echo: bool;
2075 if count > 0 {
2076 let (in1, decoded) = Option::<bool>::decode(input)?;
2077 echo = decoded.unwrap_or(false);
2078 input = in1;
2079 count -= 1;
2080 } else {
2081 echo = false;
2082 }
2083 let properties: Option<Fields>;
2084 if count > 0 {
2085 let decoded = Option::<Fields>::decode(input)?;
2086 input = decoded.0;
2087 properties = decoded.1;
2088 count -= 1;
2089 } else {
2090 properties = None;
2091 }
2092 Ok((
2093 remainder,
2094 Flow {
2095 next_incoming_id,
2096 incoming_window,
2097 next_outgoing_id,
2098 outgoing_window,
2099 handle,
2100 delivery_count,
2101 link_credit,
2102 available,
2103 drain,
2104 echo,
2105 properties,
2106 },
2107 ))
2108}
2109fn encoded_size_flow_inner(list: &Flow) -> usize {
2110 #[allow(clippy::identity_op)]
2111 let content_size = 0
2112 + list.next_incoming_id.encoded_size()
2113 + list.incoming_window.encoded_size()
2114 + list.next_outgoing_id.encoded_size()
2115 + list.outgoing_window.encoded_size()
2116 + list.handle.encoded_size()
2117 + list.delivery_count.encoded_size()
2118 + list.link_credit.encoded_size()
2119 + list.available.encoded_size()
2120 + list.drain.encoded_size()
2121 + list.echo.encoded_size()
2122 + list.properties.encoded_size();
2123 (if content_size + 1 > u8::MAX as usize {
2125 12
2126 } else {
2127 6
2128 }) + content_size
2129}
2130fn encode_flow_inner(list: &Flow, buf: &mut BytesMut) {
2131 Descriptor::Ulong(19).encode(buf);
2132 #[allow(clippy::identity_op)]
2133 let content_size = 0
2134 + list.next_incoming_id.encoded_size()
2135 + list.incoming_window.encoded_size()
2136 + list.next_outgoing_id.encoded_size()
2137 + list.outgoing_window.encoded_size()
2138 + list.handle.encoded_size()
2139 + list.delivery_count.encoded_size()
2140 + list.link_credit.encoded_size()
2141 + list.available.encoded_size()
2142 + list.drain.encoded_size()
2143 + list.echo.encoded_size()
2144 + list.properties.encoded_size();
2145 if content_size + 1 > u8::MAX as usize {
2146 buf.put_u8(codec::FORMATCODE_LIST32);
2147 buf.put_u32((content_size + 4) as u32); buf.put_u32(Flow::FIELD_COUNT as u32);
2149 } else {
2150 buf.put_u8(codec::FORMATCODE_LIST8);
2151 buf.put_u8((content_size + 1) as u8);
2152 buf.put_u8(Flow::FIELD_COUNT as u8);
2153 }
2154 list.next_incoming_id.encode(buf);
2155 list.incoming_window.encode(buf);
2156 list.next_outgoing_id.encode(buf);
2157 list.outgoing_window.encode(buf);
2158 list.handle.encode(buf);
2159 list.delivery_count.encode(buf);
2160 list.link_credit.encode(buf);
2161 list.available.encode(buf);
2162 list.drain.encode(buf);
2163 list.echo.encode(buf);
2164 list.properties.encode(buf);
2165}
2166impl DecodeFormatted for Flow {
2167 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2168 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2169 let (input, descriptor) = Descriptor::decode(input)?;
2170 let is_match = match descriptor {
2171 Descriptor::Ulong(val) => val == 19,
2172 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:flow:list",
2173 };
2174 if !is_match {
2175 Err(AmqpParseError::InvalidDescriptor(descriptor))
2176 } else {
2177 decode_flow_inner(input)
2178 }
2179 }
2180}
2181impl Encode for Flow {
2182 fn encoded_size(&self) -> usize {
2183 encoded_size_flow_inner(self)
2184 }
2185 fn encode(&self, buf: &mut BytesMut) {
2186 encode_flow_inner(self, buf)
2187 }
2188}
2189#[derive(Clone, Debug, PartialEq)]
2190pub struct Transfer {
2191 pub handle: Handle,
2192 pub delivery_id: Option<DeliveryNumber>,
2193 pub delivery_tag: Option<DeliveryTag>,
2194 pub message_format: Option<MessageFormat>,
2195 pub settled: Option<bool>,
2196 pub more: bool,
2197 pub rcv_settle_mode: Option<ReceiverSettleMode>,
2198 pub state: Option<DeliveryState>,
2199 pub resume: bool,
2200 pub aborted: bool,
2201 pub batchable: bool,
2202 pub body: Option<TransferBody>,
2203}
2204impl Transfer {
2205 pub fn handle(&self) -> Handle {
2206 self.handle
2207 }
2208 pub fn delivery_id(&self) -> Option<DeliveryNumber> {
2209 self.delivery_id
2210 }
2211 pub fn delivery_tag(&self) -> Option<&DeliveryTag> {
2212 self.delivery_tag.as_ref()
2213 }
2214 pub fn message_format(&self) -> Option<MessageFormat> {
2215 self.message_format
2216 }
2217 pub fn settled(&self) -> Option<bool> {
2218 self.settled
2219 }
2220 pub fn more(&self) -> bool {
2221 self.more
2222 }
2223 pub fn rcv_settle_mode(&self) -> Option<ReceiverSettleMode> {
2224 self.rcv_settle_mode
2225 }
2226 pub fn state(&self) -> Option<&DeliveryState> {
2227 self.state.as_ref()
2228 }
2229 pub fn resume(&self) -> bool {
2230 self.resume
2231 }
2232 pub fn aborted(&self) -> bool {
2233 self.aborted
2234 }
2235 pub fn batchable(&self) -> bool {
2236 self.batchable
2237 }
2238 pub fn body(&self) -> Option<&TransferBody> {
2239 self.body.as_ref()
2240 }
2241 #[allow(clippy::identity_op)]
2242 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
2243}
2244#[allow(unused_mut)]
2245fn decode_transfer_inner(input: &[u8]) -> Result<(&[u8], Transfer), AmqpParseError> {
2246 let (input, format) = decode_format_code(input)?;
2247 let (input, header) = decode_list_header(input, format)?;
2248 let size = header.size as usize;
2249 decode_check_len!(input, size);
2250 let (mut input, mut remainder) = input.split_at(size);
2251 let mut count = header.count;
2252 let handle: Handle;
2253 if count > 0 {
2254 let (in1, decoded) = Handle::decode(input)?;
2255 handle = decoded;
2256 input = in1;
2257 count -= 1;
2258 } else {
2259 return Err(AmqpParseError::RequiredFieldOmitted("handle"));
2260 }
2261 let delivery_id: Option<DeliveryNumber>;
2262 if count > 0 {
2263 let decoded = Option::<DeliveryNumber>::decode(input)?;
2264 input = decoded.0;
2265 delivery_id = decoded.1;
2266 count -= 1;
2267 } else {
2268 delivery_id = None;
2269 }
2270 let delivery_tag: Option<DeliveryTag>;
2271 if count > 0 {
2272 let decoded = Option::<DeliveryTag>::decode(input)?;
2273 input = decoded.0;
2274 delivery_tag = decoded.1;
2275 count -= 1;
2276 } else {
2277 delivery_tag = None;
2278 }
2279 let message_format: Option<MessageFormat>;
2280 if count > 0 {
2281 let decoded = Option::<MessageFormat>::decode(input)?;
2282 input = decoded.0;
2283 message_format = decoded.1;
2284 count -= 1;
2285 } else {
2286 message_format = None;
2287 }
2288 let settled: Option<bool>;
2289 if count > 0 {
2290 let decoded = Option::<bool>::decode(input)?;
2291 input = decoded.0;
2292 settled = decoded.1;
2293 count -= 1;
2294 } else {
2295 settled = None;
2296 }
2297 let more: bool;
2298 if count > 0 {
2299 let (in1, decoded) = Option::<bool>::decode(input)?;
2300 more = decoded.unwrap_or(false);
2301 input = in1;
2302 count -= 1;
2303 } else {
2304 more = false;
2305 }
2306 let rcv_settle_mode: Option<ReceiverSettleMode>;
2307 if count > 0 {
2308 let decoded = Option::<ReceiverSettleMode>::decode(input)?;
2309 input = decoded.0;
2310 rcv_settle_mode = decoded.1;
2311 count -= 1;
2312 } else {
2313 rcv_settle_mode = None;
2314 }
2315 let state: Option<DeliveryState>;
2316 if count > 0 {
2317 let decoded = Option::<DeliveryState>::decode(input)?;
2318 input = decoded.0;
2319 state = decoded.1;
2320 count -= 1;
2321 } else {
2322 state = None;
2323 }
2324 let resume: bool;
2325 if count > 0 {
2326 let (in1, decoded) = Option::<bool>::decode(input)?;
2327 resume = decoded.unwrap_or(false);
2328 input = in1;
2329 count -= 1;
2330 } else {
2331 resume = false;
2332 }
2333 let aborted: bool;
2334 if count > 0 {
2335 let (in1, decoded) = Option::<bool>::decode(input)?;
2336 aborted = decoded.unwrap_or(false);
2337 input = in1;
2338 count -= 1;
2339 } else {
2340 aborted = false;
2341 }
2342 let batchable: bool;
2343 if count > 0 {
2344 let (in1, decoded) = Option::<bool>::decode(input)?;
2345 batchable = decoded.unwrap_or(false);
2346 input = in1;
2347 count -= 1;
2348 } else {
2349 batchable = false;
2350 }
2351 let body = if remainder.is_empty() {
2352 None
2353 } else {
2354 let b = Bytes::copy_from_slice(remainder);
2355 remainder = &[];
2356 Some(b.into())
2357 };
2358 Ok((
2359 remainder,
2360 Transfer {
2361 handle,
2362 delivery_id,
2363 delivery_tag,
2364 message_format,
2365 settled,
2366 more,
2367 rcv_settle_mode,
2368 state,
2369 resume,
2370 aborted,
2371 batchable,
2372 body,
2373 },
2374 ))
2375}
2376fn encoded_size_transfer_inner(list: &Transfer) -> usize {
2377 #[allow(clippy::identity_op)]
2378 let content_size = 0
2379 + list.handle.encoded_size()
2380 + list.delivery_id.encoded_size()
2381 + list.delivery_tag.encoded_size()
2382 + list.message_format.encoded_size()
2383 + list.settled.encoded_size()
2384 + list.more.encoded_size()
2385 + list.rcv_settle_mode.encoded_size()
2386 + list.state.encoded_size()
2387 + list.resume.encoded_size()
2388 + list.aborted.encoded_size()
2389 + list.batchable.encoded_size();
2390 (if content_size + 1 > u8::MAX as usize {
2392 12
2393 } else {
2394 6
2395 }) + content_size
2396 + list.body.as_ref().map(|b| b.len()).unwrap_or(0)
2397}
2398fn encode_transfer_inner(list: &Transfer, buf: &mut BytesMut) {
2399 Descriptor::Ulong(20).encode(buf);
2400 #[allow(clippy::identity_op)]
2401 let content_size = 0
2402 + list.handle.encoded_size()
2403 + list.delivery_id.encoded_size()
2404 + list.delivery_tag.encoded_size()
2405 + list.message_format.encoded_size()
2406 + list.settled.encoded_size()
2407 + list.more.encoded_size()
2408 + list.rcv_settle_mode.encoded_size()
2409 + list.state.encoded_size()
2410 + list.resume.encoded_size()
2411 + list.aborted.encoded_size()
2412 + list.batchable.encoded_size();
2413 if content_size + 1 > u8::MAX as usize {
2414 buf.put_u8(codec::FORMATCODE_LIST32);
2415 buf.put_u32((content_size + 4) as u32); buf.put_u32(Transfer::FIELD_COUNT as u32);
2417 } else {
2418 buf.put_u8(codec::FORMATCODE_LIST8);
2419 buf.put_u8((content_size + 1) as u8);
2420 buf.put_u8(Transfer::FIELD_COUNT as u8);
2421 }
2422 list.handle.encode(buf);
2423 list.delivery_id.encode(buf);
2424 list.delivery_tag.encode(buf);
2425 list.message_format.encode(buf);
2426 list.settled.encode(buf);
2427 list.more.encode(buf);
2428 list.rcv_settle_mode.encode(buf);
2429 list.state.encode(buf);
2430 list.resume.encode(buf);
2431 list.aborted.encode(buf);
2432 list.batchable.encode(buf);
2433 if let Some(ref body) = list.body {
2434 body.encode(buf)
2435 }
2436}
2437impl DecodeFormatted for Transfer {
2438 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2439 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2440 let (input, descriptor) = Descriptor::decode(input)?;
2441 let is_match = match descriptor {
2442 Descriptor::Ulong(val) => val == 20,
2443 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:transfer:list",
2444 };
2445 if !is_match {
2446 Err(AmqpParseError::InvalidDescriptor(descriptor))
2447 } else {
2448 decode_transfer_inner(input)
2449 }
2450 }
2451}
2452impl Encode for Transfer {
2453 fn encoded_size(&self) -> usize {
2454 encoded_size_transfer_inner(self)
2455 }
2456 fn encode(&self, buf: &mut BytesMut) {
2457 encode_transfer_inner(self, buf)
2458 }
2459}
2460#[derive(Clone, Debug, PartialEq)]
2461pub struct Disposition {
2462 pub role: Role,
2463 pub first: DeliveryNumber,
2464 pub last: Option<DeliveryNumber>,
2465 pub settled: bool,
2466 pub state: Option<DeliveryState>,
2467 pub batchable: bool,
2468}
2469impl Disposition {
2470 pub fn role(&self) -> Role {
2471 self.role
2472 }
2473 pub fn first(&self) -> DeliveryNumber {
2474 self.first
2475 }
2476 pub fn last(&self) -> Option<DeliveryNumber> {
2477 self.last
2478 }
2479 pub fn settled(&self) -> bool {
2480 self.settled
2481 }
2482 pub fn state(&self) -> Option<&DeliveryState> {
2483 self.state.as_ref()
2484 }
2485 pub fn batchable(&self) -> bool {
2486 self.batchable
2487 }
2488 #[allow(clippy::identity_op)]
2489 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1;
2490}
2491#[allow(unused_mut)]
2492fn decode_disposition_inner(input: &[u8]) -> Result<(&[u8], Disposition), AmqpParseError> {
2493 let (input, format) = decode_format_code(input)?;
2494 let (input, header) = decode_list_header(input, format)?;
2495 let size = header.size as usize;
2496 decode_check_len!(input, size);
2497 let (mut input, mut remainder) = input.split_at(size);
2498 let mut count = header.count;
2499 let role: Role;
2500 if count > 0 {
2501 let (in1, decoded) = Role::decode(input)?;
2502 role = decoded;
2503 input = in1;
2504 count -= 1;
2505 } else {
2506 return Err(AmqpParseError::RequiredFieldOmitted("role"));
2507 }
2508 let first: DeliveryNumber;
2509 if count > 0 {
2510 let (in1, decoded) = DeliveryNumber::decode(input)?;
2511 first = decoded;
2512 input = in1;
2513 count -= 1;
2514 } else {
2515 return Err(AmqpParseError::RequiredFieldOmitted("first"));
2516 }
2517 let last: Option<DeliveryNumber>;
2518 if count > 0 {
2519 let decoded = Option::<DeliveryNumber>::decode(input)?;
2520 input = decoded.0;
2521 last = decoded.1;
2522 count -= 1;
2523 } else {
2524 last = None;
2525 }
2526 let settled: bool;
2527 if count > 0 {
2528 let (in1, decoded) = Option::<bool>::decode(input)?;
2529 settled = decoded.unwrap_or(false);
2530 input = in1;
2531 count -= 1;
2532 } else {
2533 settled = false;
2534 }
2535 let state: Option<DeliveryState>;
2536 if count > 0 {
2537 let decoded = Option::<DeliveryState>::decode(input)?;
2538 input = decoded.0;
2539 state = decoded.1;
2540 count -= 1;
2541 } else {
2542 state = None;
2543 }
2544 let batchable: bool;
2545 if count > 0 {
2546 let (in1, decoded) = Option::<bool>::decode(input)?;
2547 batchable = decoded.unwrap_or(false);
2548 input = in1;
2549 count -= 1;
2550 } else {
2551 batchable = false;
2552 }
2553 Ok((
2554 remainder,
2555 Disposition {
2556 role,
2557 first,
2558 last,
2559 settled,
2560 state,
2561 batchable,
2562 },
2563 ))
2564}
2565fn encoded_size_disposition_inner(list: &Disposition) -> usize {
2566 #[allow(clippy::identity_op)]
2567 let content_size = 0
2568 + list.role.encoded_size()
2569 + list.first.encoded_size()
2570 + list.last.encoded_size()
2571 + list.settled.encoded_size()
2572 + list.state.encoded_size()
2573 + list.batchable.encoded_size();
2574 (if content_size + 1 > u8::MAX as usize {
2576 12
2577 } else {
2578 6
2579 }) + content_size
2580}
2581fn encode_disposition_inner(list: &Disposition, buf: &mut BytesMut) {
2582 Descriptor::Ulong(21).encode(buf);
2583 #[allow(clippy::identity_op)]
2584 let content_size = 0
2585 + list.role.encoded_size()
2586 + list.first.encoded_size()
2587 + list.last.encoded_size()
2588 + list.settled.encoded_size()
2589 + list.state.encoded_size()
2590 + list.batchable.encoded_size();
2591 if content_size + 1 > u8::MAX as usize {
2592 buf.put_u8(codec::FORMATCODE_LIST32);
2593 buf.put_u32((content_size + 4) as u32); buf.put_u32(Disposition::FIELD_COUNT as u32);
2595 } else {
2596 buf.put_u8(codec::FORMATCODE_LIST8);
2597 buf.put_u8((content_size + 1) as u8);
2598 buf.put_u8(Disposition::FIELD_COUNT as u8);
2599 }
2600 list.role.encode(buf);
2601 list.first.encode(buf);
2602 list.last.encode(buf);
2603 list.settled.encode(buf);
2604 list.state.encode(buf);
2605 list.batchable.encode(buf);
2606}
2607impl DecodeFormatted for Disposition {
2608 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2609 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2610 let (input, descriptor) = Descriptor::decode(input)?;
2611 let is_match = match descriptor {
2612 Descriptor::Ulong(val) => val == 21,
2613 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:disposition:list",
2614 };
2615 if !is_match {
2616 Err(AmqpParseError::InvalidDescriptor(descriptor))
2617 } else {
2618 decode_disposition_inner(input)
2619 }
2620 }
2621}
2622impl Encode for Disposition {
2623 fn encoded_size(&self) -> usize {
2624 encoded_size_disposition_inner(self)
2625 }
2626 fn encode(&self, buf: &mut BytesMut) {
2627 encode_disposition_inner(self, buf)
2628 }
2629}
2630#[derive(Clone, Debug, PartialEq)]
2631pub struct Detach {
2632 pub handle: Handle,
2633 pub closed: bool,
2634 pub error: Option<Error>,
2635}
2636impl Detach {
2637 pub fn handle(&self) -> Handle {
2638 self.handle
2639 }
2640 pub fn closed(&self) -> bool {
2641 self.closed
2642 }
2643 pub fn error(&self) -> Option<&Error> {
2644 self.error.as_ref()
2645 }
2646 #[allow(clippy::identity_op)]
2647 const FIELD_COUNT: usize = 0 + 1 + 1 + 1;
2648}
2649#[allow(unused_mut)]
2650fn decode_detach_inner(input: &[u8]) -> Result<(&[u8], Detach), AmqpParseError> {
2651 let (input, format) = decode_format_code(input)?;
2652 let (input, header) = decode_list_header(input, format)?;
2653 let size = header.size as usize;
2654 decode_check_len!(input, size);
2655 let (mut input, mut remainder) = input.split_at(size);
2656 let mut count = header.count;
2657 let handle: Handle;
2658 if count > 0 {
2659 let (in1, decoded) = Handle::decode(input)?;
2660 handle = decoded;
2661 input = in1;
2662 count -= 1;
2663 } else {
2664 return Err(AmqpParseError::RequiredFieldOmitted("handle"));
2665 }
2666 let closed: bool;
2667 if count > 0 {
2668 let (in1, decoded) = Option::<bool>::decode(input)?;
2669 closed = decoded.unwrap_or(false);
2670 input = in1;
2671 count -= 1;
2672 } else {
2673 closed = false;
2674 }
2675 let error: Option<Error>;
2676 if count > 0 {
2677 let decoded = Option::<Error>::decode(input)?;
2678 input = decoded.0;
2679 error = decoded.1;
2680 count -= 1;
2681 } else {
2682 error = None;
2683 }
2684 Ok((
2685 remainder,
2686 Detach {
2687 handle,
2688 closed,
2689 error,
2690 },
2691 ))
2692}
2693fn encoded_size_detach_inner(list: &Detach) -> usize {
2694 #[allow(clippy::identity_op)]
2695 let content_size =
2696 0 + list.handle.encoded_size() + list.closed.encoded_size() + list.error.encoded_size();
2697 (if content_size + 1 > u8::MAX as usize {
2699 12
2700 } else {
2701 6
2702 }) + content_size
2703}
2704fn encode_detach_inner(list: &Detach, buf: &mut BytesMut) {
2705 Descriptor::Ulong(22).encode(buf);
2706 #[allow(clippy::identity_op)]
2707 let content_size =
2708 0 + list.handle.encoded_size() + list.closed.encoded_size() + list.error.encoded_size();
2709 if content_size + 1 > u8::MAX as usize {
2710 buf.put_u8(codec::FORMATCODE_LIST32);
2711 buf.put_u32((content_size + 4) as u32); buf.put_u32(Detach::FIELD_COUNT as u32);
2713 } else {
2714 buf.put_u8(codec::FORMATCODE_LIST8);
2715 buf.put_u8((content_size + 1) as u8);
2716 buf.put_u8(Detach::FIELD_COUNT as u8);
2717 }
2718 list.handle.encode(buf);
2719 list.closed.encode(buf);
2720 list.error.encode(buf);
2721}
2722impl DecodeFormatted for Detach {
2723 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2724 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2725 let (input, descriptor) = Descriptor::decode(input)?;
2726 let is_match = match descriptor {
2727 Descriptor::Ulong(val) => val == 22,
2728 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:detach:list",
2729 };
2730 if !is_match {
2731 Err(AmqpParseError::InvalidDescriptor(descriptor))
2732 } else {
2733 decode_detach_inner(input)
2734 }
2735 }
2736}
2737impl Encode for Detach {
2738 fn encoded_size(&self) -> usize {
2739 encoded_size_detach_inner(self)
2740 }
2741 fn encode(&self, buf: &mut BytesMut) {
2742 encode_detach_inner(self, buf)
2743 }
2744}
2745#[derive(Clone, Debug, PartialEq)]
2746pub struct End {
2747 pub error: Option<Error>,
2748}
2749impl End {
2750 pub fn error(&self) -> Option<&Error> {
2751 self.error.as_ref()
2752 }
2753 #[allow(clippy::identity_op)]
2754 const FIELD_COUNT: usize = 0 + 1;
2755}
2756#[allow(unused_mut)]
2757fn decode_end_inner(input: &[u8]) -> Result<(&[u8], End), AmqpParseError> {
2758 let (input, format) = decode_format_code(input)?;
2759 let (input, header) = decode_list_header(input, format)?;
2760 let size = header.size as usize;
2761 decode_check_len!(input, size);
2762 let (mut input, mut remainder) = input.split_at(size);
2763 let mut count = header.count;
2764 let error: Option<Error>;
2765 if count > 0 {
2766 let decoded = Option::<Error>::decode(input)?;
2767 input = decoded.0;
2768 error = decoded.1;
2769 count -= 1;
2770 } else {
2771 error = None;
2772 }
2773 Ok((remainder, End { error }))
2774}
2775fn encoded_size_end_inner(list: &End) -> usize {
2776 #[allow(clippy::identity_op)]
2777 let content_size = 0 + list.error.encoded_size();
2778 (if content_size + 1 > u8::MAX as usize {
2780 12
2781 } else {
2782 6
2783 }) + content_size
2784}
2785fn encode_end_inner(list: &End, buf: &mut BytesMut) {
2786 Descriptor::Ulong(23).encode(buf);
2787 #[allow(clippy::identity_op)]
2788 let content_size = 0 + list.error.encoded_size();
2789 if content_size + 1 > u8::MAX as usize {
2790 buf.put_u8(codec::FORMATCODE_LIST32);
2791 buf.put_u32((content_size + 4) as u32); buf.put_u32(End::FIELD_COUNT as u32);
2793 } else {
2794 buf.put_u8(codec::FORMATCODE_LIST8);
2795 buf.put_u8((content_size + 1) as u8);
2796 buf.put_u8(End::FIELD_COUNT as u8);
2797 }
2798 list.error.encode(buf);
2799}
2800impl DecodeFormatted for End {
2801 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2802 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2803 let (input, descriptor) = Descriptor::decode(input)?;
2804 let is_match = match descriptor {
2805 Descriptor::Ulong(val) => val == 23,
2806 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:end:list",
2807 };
2808 if !is_match {
2809 Err(AmqpParseError::InvalidDescriptor(descriptor))
2810 } else {
2811 decode_end_inner(input)
2812 }
2813 }
2814}
2815impl Encode for End {
2816 fn encoded_size(&self) -> usize {
2817 encoded_size_end_inner(self)
2818 }
2819 fn encode(&self, buf: &mut BytesMut) {
2820 encode_end_inner(self, buf)
2821 }
2822}
2823#[derive(Clone, Debug, PartialEq)]
2824pub struct Close {
2825 pub error: Option<Error>,
2826}
2827impl Close {
2828 pub fn error(&self) -> Option<&Error> {
2829 self.error.as_ref()
2830 }
2831 #[allow(clippy::identity_op)]
2832 const FIELD_COUNT: usize = 0 + 1;
2833}
2834#[allow(unused_mut)]
2835fn decode_close_inner(input: &[u8]) -> Result<(&[u8], Close), AmqpParseError> {
2836 let (input, format) = decode_format_code(input)?;
2837 let (input, header) = decode_list_header(input, format)?;
2838 let size = header.size as usize;
2839 decode_check_len!(input, size);
2840 let (mut input, mut remainder) = input.split_at(size);
2841 let mut count = header.count;
2842 let error: Option<Error>;
2843 if count > 0 {
2844 let decoded = Option::<Error>::decode(input)?;
2845 input = decoded.0;
2846 error = decoded.1;
2847 count -= 1;
2848 } else {
2849 error = None;
2850 }
2851 Ok((remainder, Close { error }))
2852}
2853fn encoded_size_close_inner(list: &Close) -> usize {
2854 #[allow(clippy::identity_op)]
2855 let content_size = 0 + list.error.encoded_size();
2856 (if content_size + 1 > u8::MAX as usize {
2858 12
2859 } else {
2860 6
2861 }) + content_size
2862}
2863fn encode_close_inner(list: &Close, buf: &mut BytesMut) {
2864 Descriptor::Ulong(24).encode(buf);
2865 #[allow(clippy::identity_op)]
2866 let content_size = 0 + list.error.encoded_size();
2867 if content_size + 1 > u8::MAX as usize {
2868 buf.put_u8(codec::FORMATCODE_LIST32);
2869 buf.put_u32((content_size + 4) as u32); buf.put_u32(Close::FIELD_COUNT as u32);
2871 } else {
2872 buf.put_u8(codec::FORMATCODE_LIST8);
2873 buf.put_u8((content_size + 1) as u8);
2874 buf.put_u8(Close::FIELD_COUNT as u8);
2875 }
2876 list.error.encode(buf);
2877}
2878impl DecodeFormatted for Close {
2879 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2880 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2881 let (input, descriptor) = Descriptor::decode(input)?;
2882 let is_match = match descriptor {
2883 Descriptor::Ulong(val) => val == 24,
2884 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:close:list",
2885 };
2886 if !is_match {
2887 Err(AmqpParseError::InvalidDescriptor(descriptor))
2888 } else {
2889 decode_close_inner(input)
2890 }
2891 }
2892}
2893impl Encode for Close {
2894 fn encoded_size(&self) -> usize {
2895 encoded_size_close_inner(self)
2896 }
2897 fn encode(&self, buf: &mut BytesMut) {
2898 encode_close_inner(self, buf)
2899 }
2900}
2901#[derive(Clone, Debug, PartialEq)]
2902pub struct SaslMechanisms {
2903 pub sasl_server_mechanisms: Symbols,
2904}
2905impl SaslMechanisms {
2906 pub fn sasl_server_mechanisms(&self) -> &Symbols {
2907 &self.sasl_server_mechanisms
2908 }
2909 #[allow(clippy::identity_op)]
2910 const FIELD_COUNT: usize = 0 + 1;
2911}
2912#[allow(unused_mut)]
2913fn decode_sasl_mechanisms_inner(input: &[u8]) -> Result<(&[u8], SaslMechanisms), AmqpParseError> {
2914 let (input, format) = decode_format_code(input)?;
2915 let (input, header) = decode_list_header(input, format)?;
2916 let size = header.size as usize;
2917 decode_check_len!(input, size);
2918 let (mut input, mut remainder) = input.split_at(size);
2919 let mut count = header.count;
2920 let sasl_server_mechanisms: Symbols;
2921 if count > 0 {
2922 let (in1, decoded) = Symbols::decode(input)?;
2923 sasl_server_mechanisms = decoded;
2924 input = in1;
2925 count -= 1;
2926 } else {
2927 return Err(AmqpParseError::RequiredFieldOmitted(
2928 "sasl_server_mechanisms",
2929 ));
2930 }
2931 Ok((
2932 remainder,
2933 SaslMechanisms {
2934 sasl_server_mechanisms,
2935 },
2936 ))
2937}
2938fn encoded_size_sasl_mechanisms_inner(list: &SaslMechanisms) -> usize {
2939 #[allow(clippy::identity_op)]
2940 let content_size = 0 + list.sasl_server_mechanisms.encoded_size();
2941 (if content_size + 1 > u8::MAX as usize {
2943 12
2944 } else {
2945 6
2946 }) + content_size
2947}
2948fn encode_sasl_mechanisms_inner(list: &SaslMechanisms, buf: &mut BytesMut) {
2949 Descriptor::Ulong(64).encode(buf);
2950 #[allow(clippy::identity_op)]
2951 let content_size = 0 + list.sasl_server_mechanisms.encoded_size();
2952 if content_size + 1 > u8::MAX as usize {
2953 buf.put_u8(codec::FORMATCODE_LIST32);
2954 buf.put_u32((content_size + 4) as u32); buf.put_u32(SaslMechanisms::FIELD_COUNT as u32);
2956 } else {
2957 buf.put_u8(codec::FORMATCODE_LIST8);
2958 buf.put_u8((content_size + 1) as u8);
2959 buf.put_u8(SaslMechanisms::FIELD_COUNT as u8);
2960 }
2961 list.sasl_server_mechanisms.encode(buf);
2962}
2963impl DecodeFormatted for SaslMechanisms {
2964 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
2965 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
2966 let (input, descriptor) = Descriptor::decode(input)?;
2967 let is_match = match descriptor {
2968 Descriptor::Ulong(val) => val == 64,
2969 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:sasl-mechanisms:list",
2970 };
2971 if !is_match {
2972 Err(AmqpParseError::InvalidDescriptor(descriptor))
2973 } else {
2974 decode_sasl_mechanisms_inner(input)
2975 }
2976 }
2977}
2978impl Encode for SaslMechanisms {
2979 fn encoded_size(&self) -> usize {
2980 encoded_size_sasl_mechanisms_inner(self)
2981 }
2982 fn encode(&self, buf: &mut BytesMut) {
2983 encode_sasl_mechanisms_inner(self, buf)
2984 }
2985}
2986#[derive(Clone, Debug, PartialEq)]
2987pub struct SaslInit {
2988 pub mechanism: Symbol,
2989 pub initial_response: Option<Bytes>,
2990 pub hostname: Option<ByteString>,
2991}
2992impl SaslInit {
2993 pub fn mechanism(&self) -> &Symbol {
2994 &self.mechanism
2995 }
2996 pub fn initial_response(&self) -> Option<&Bytes> {
2997 self.initial_response.as_ref()
2998 }
2999 pub fn hostname(&self) -> Option<&ByteString> {
3000 self.hostname.as_ref()
3001 }
3002 #[allow(clippy::identity_op)]
3003 const FIELD_COUNT: usize = 0 + 1 + 1 + 1;
3004}
3005#[allow(unused_mut)]
3006fn decode_sasl_init_inner(input: &[u8]) -> Result<(&[u8], SaslInit), AmqpParseError> {
3007 let (input, format) = decode_format_code(input)?;
3008 let (input, header) = decode_list_header(input, format)?;
3009 let size = header.size as usize;
3010 decode_check_len!(input, size);
3011 let (mut input, mut remainder) = input.split_at(size);
3012 let mut count = header.count;
3013 let mechanism: Symbol;
3014 if count > 0 {
3015 let (in1, decoded) = Symbol::decode(input)?;
3016 mechanism = decoded;
3017 input = in1;
3018 count -= 1;
3019 } else {
3020 return Err(AmqpParseError::RequiredFieldOmitted("mechanism"));
3021 }
3022 let initial_response: Option<Bytes>;
3023 if count > 0 {
3024 let decoded = Option::<Bytes>::decode(input)?;
3025 input = decoded.0;
3026 initial_response = decoded.1;
3027 count -= 1;
3028 } else {
3029 initial_response = None;
3030 }
3031 let hostname: Option<ByteString>;
3032 if count > 0 {
3033 let decoded = Option::<ByteString>::decode(input)?;
3034 input = decoded.0;
3035 hostname = decoded.1;
3036 count -= 1;
3037 } else {
3038 hostname = None;
3039 }
3040 Ok((
3041 remainder,
3042 SaslInit {
3043 mechanism,
3044 initial_response,
3045 hostname,
3046 },
3047 ))
3048}
3049fn encoded_size_sasl_init_inner(list: &SaslInit) -> usize {
3050 #[allow(clippy::identity_op)]
3051 let content_size = 0
3052 + list.mechanism.encoded_size()
3053 + list.initial_response.encoded_size()
3054 + list.hostname.encoded_size();
3055 (if content_size + 1 > u8::MAX as usize {
3057 12
3058 } else {
3059 6
3060 }) + content_size
3061}
3062fn encode_sasl_init_inner(list: &SaslInit, buf: &mut BytesMut) {
3063 Descriptor::Ulong(65).encode(buf);
3064 #[allow(clippy::identity_op)]
3065 let content_size = 0
3066 + list.mechanism.encoded_size()
3067 + list.initial_response.encoded_size()
3068 + list.hostname.encoded_size();
3069 if content_size + 1 > u8::MAX as usize {
3070 buf.put_u8(codec::FORMATCODE_LIST32);
3071 buf.put_u32((content_size + 4) as u32); buf.put_u32(SaslInit::FIELD_COUNT as u32);
3073 } else {
3074 buf.put_u8(codec::FORMATCODE_LIST8);
3075 buf.put_u8((content_size + 1) as u8);
3076 buf.put_u8(SaslInit::FIELD_COUNT as u8);
3077 }
3078 list.mechanism.encode(buf);
3079 list.initial_response.encode(buf);
3080 list.hostname.encode(buf);
3081}
3082impl DecodeFormatted for SaslInit {
3083 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3084 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3085 let (input, descriptor) = Descriptor::decode(input)?;
3086 let is_match = match descriptor {
3087 Descriptor::Ulong(val) => val == 65,
3088 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:sasl-init:list",
3089 };
3090 if !is_match {
3091 Err(AmqpParseError::InvalidDescriptor(descriptor))
3092 } else {
3093 decode_sasl_init_inner(input)
3094 }
3095 }
3096}
3097impl Encode for SaslInit {
3098 fn encoded_size(&self) -> usize {
3099 encoded_size_sasl_init_inner(self)
3100 }
3101 fn encode(&self, buf: &mut BytesMut) {
3102 encode_sasl_init_inner(self, buf)
3103 }
3104}
3105#[derive(Clone, Debug, PartialEq)]
3106pub struct SaslChallenge {
3107 pub challenge: Bytes,
3108}
3109impl SaslChallenge {
3110 pub fn challenge(&self) -> &Bytes {
3111 &self.challenge
3112 }
3113 #[allow(clippy::identity_op)]
3114 const FIELD_COUNT: usize = 0 + 1;
3115}
3116#[allow(unused_mut)]
3117fn decode_sasl_challenge_inner(input: &[u8]) -> Result<(&[u8], SaslChallenge), AmqpParseError> {
3118 let (input, format) = decode_format_code(input)?;
3119 let (input, header) = decode_list_header(input, format)?;
3120 let size = header.size as usize;
3121 decode_check_len!(input, size);
3122 let (mut input, mut remainder) = input.split_at(size);
3123 let mut count = header.count;
3124 let challenge: Bytes;
3125 if count > 0 {
3126 let (in1, decoded) = Bytes::decode(input)?;
3127 challenge = decoded;
3128 input = in1;
3129 count -= 1;
3130 } else {
3131 return Err(AmqpParseError::RequiredFieldOmitted("challenge"));
3132 }
3133 Ok((remainder, SaslChallenge { challenge }))
3134}
3135fn encoded_size_sasl_challenge_inner(list: &SaslChallenge) -> usize {
3136 #[allow(clippy::identity_op)]
3137 let content_size = 0 + list.challenge.encoded_size();
3138 (if content_size + 1 > u8::MAX as usize {
3140 12
3141 } else {
3142 6
3143 }) + content_size
3144}
3145fn encode_sasl_challenge_inner(list: &SaslChallenge, buf: &mut BytesMut) {
3146 Descriptor::Ulong(66).encode(buf);
3147 #[allow(clippy::identity_op)]
3148 let content_size = 0 + list.challenge.encoded_size();
3149 if content_size + 1 > u8::MAX as usize {
3150 buf.put_u8(codec::FORMATCODE_LIST32);
3151 buf.put_u32((content_size + 4) as u32); buf.put_u32(SaslChallenge::FIELD_COUNT as u32);
3153 } else {
3154 buf.put_u8(codec::FORMATCODE_LIST8);
3155 buf.put_u8((content_size + 1) as u8);
3156 buf.put_u8(SaslChallenge::FIELD_COUNT as u8);
3157 }
3158 list.challenge.encode(buf);
3159}
3160impl DecodeFormatted for SaslChallenge {
3161 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3162 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3163 let (input, descriptor) = Descriptor::decode(input)?;
3164 let is_match = match descriptor {
3165 Descriptor::Ulong(val) => val == 66,
3166 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:sasl-challenge:list",
3167 };
3168 if !is_match {
3169 Err(AmqpParseError::InvalidDescriptor(descriptor))
3170 } else {
3171 decode_sasl_challenge_inner(input)
3172 }
3173 }
3174}
3175impl Encode for SaslChallenge {
3176 fn encoded_size(&self) -> usize {
3177 encoded_size_sasl_challenge_inner(self)
3178 }
3179 fn encode(&self, buf: &mut BytesMut) {
3180 encode_sasl_challenge_inner(self, buf)
3181 }
3182}
3183#[derive(Clone, Debug, PartialEq)]
3184pub struct SaslResponse {
3185 pub response: Bytes,
3186}
3187impl SaslResponse {
3188 pub fn response(&self) -> &Bytes {
3189 &self.response
3190 }
3191 #[allow(clippy::identity_op)]
3192 const FIELD_COUNT: usize = 0 + 1;
3193}
3194#[allow(unused_mut)]
3195fn decode_sasl_response_inner(input: &[u8]) -> Result<(&[u8], SaslResponse), AmqpParseError> {
3196 let (input, format) = decode_format_code(input)?;
3197 let (input, header) = decode_list_header(input, format)?;
3198 let size = header.size as usize;
3199 decode_check_len!(input, size);
3200 let (mut input, mut remainder) = input.split_at(size);
3201 let mut count = header.count;
3202 let response: Bytes;
3203 if count > 0 {
3204 let (in1, decoded) = Bytes::decode(input)?;
3205 response = decoded;
3206 input = in1;
3207 count -= 1;
3208 } else {
3209 return Err(AmqpParseError::RequiredFieldOmitted("response"));
3210 }
3211 Ok((remainder, SaslResponse { response }))
3212}
3213fn encoded_size_sasl_response_inner(list: &SaslResponse) -> usize {
3214 #[allow(clippy::identity_op)]
3215 let content_size = 0 + list.response.encoded_size();
3216 (if content_size + 1 > u8::MAX as usize {
3218 12
3219 } else {
3220 6
3221 }) + content_size
3222}
3223fn encode_sasl_response_inner(list: &SaslResponse, buf: &mut BytesMut) {
3224 Descriptor::Ulong(67).encode(buf);
3225 #[allow(clippy::identity_op)]
3226 let content_size = 0 + list.response.encoded_size();
3227 if content_size + 1 > u8::MAX as usize {
3228 buf.put_u8(codec::FORMATCODE_LIST32);
3229 buf.put_u32((content_size + 4) as u32); buf.put_u32(SaslResponse::FIELD_COUNT as u32);
3231 } else {
3232 buf.put_u8(codec::FORMATCODE_LIST8);
3233 buf.put_u8((content_size + 1) as u8);
3234 buf.put_u8(SaslResponse::FIELD_COUNT as u8);
3235 }
3236 list.response.encode(buf);
3237}
3238impl DecodeFormatted for SaslResponse {
3239 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3240 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3241 let (input, descriptor) = Descriptor::decode(input)?;
3242 let is_match = match descriptor {
3243 Descriptor::Ulong(val) => val == 67,
3244 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:sasl-response:list",
3245 };
3246 if !is_match {
3247 Err(AmqpParseError::InvalidDescriptor(descriptor))
3248 } else {
3249 decode_sasl_response_inner(input)
3250 }
3251 }
3252}
3253impl Encode for SaslResponse {
3254 fn encoded_size(&self) -> usize {
3255 encoded_size_sasl_response_inner(self)
3256 }
3257 fn encode(&self, buf: &mut BytesMut) {
3258 encode_sasl_response_inner(self, buf)
3259 }
3260}
3261#[derive(Clone, Debug, PartialEq)]
3262pub struct SaslOutcome {
3263 pub code: SaslCode,
3264 pub additional_data: Option<Bytes>,
3265}
3266impl SaslOutcome {
3267 pub fn code(&self) -> SaslCode {
3268 self.code
3269 }
3270 pub fn additional_data(&self) -> Option<&Bytes> {
3271 self.additional_data.as_ref()
3272 }
3273 #[allow(clippy::identity_op)]
3274 const FIELD_COUNT: usize = 0 + 1 + 1;
3275}
3276#[allow(unused_mut)]
3277fn decode_sasl_outcome_inner(input: &[u8]) -> Result<(&[u8], SaslOutcome), AmqpParseError> {
3278 let (input, format) = decode_format_code(input)?;
3279 let (input, header) = decode_list_header(input, format)?;
3280 let size = header.size as usize;
3281 decode_check_len!(input, size);
3282 let (mut input, mut remainder) = input.split_at(size);
3283 let mut count = header.count;
3284 let code: SaslCode;
3285 if count > 0 {
3286 let (in1, decoded) = SaslCode::decode(input)?;
3287 code = decoded;
3288 input = in1;
3289 count -= 1;
3290 } else {
3291 return Err(AmqpParseError::RequiredFieldOmitted("code"));
3292 }
3293 let additional_data: Option<Bytes>;
3294 if count > 0 {
3295 let decoded = Option::<Bytes>::decode(input)?;
3296 input = decoded.0;
3297 additional_data = decoded.1;
3298 count -= 1;
3299 } else {
3300 additional_data = None;
3301 }
3302 Ok((
3303 remainder,
3304 SaslOutcome {
3305 code,
3306 additional_data,
3307 },
3308 ))
3309}
3310fn encoded_size_sasl_outcome_inner(list: &SaslOutcome) -> usize {
3311 #[allow(clippy::identity_op)]
3312 let content_size = 0 + list.code.encoded_size() + list.additional_data.encoded_size();
3313 (if content_size + 1 > u8::MAX as usize {
3315 12
3316 } else {
3317 6
3318 }) + content_size
3319}
3320fn encode_sasl_outcome_inner(list: &SaslOutcome, buf: &mut BytesMut) {
3321 Descriptor::Ulong(68).encode(buf);
3322 #[allow(clippy::identity_op)]
3323 let content_size = 0 + list.code.encoded_size() + list.additional_data.encoded_size();
3324 if content_size + 1 > u8::MAX as usize {
3325 buf.put_u8(codec::FORMATCODE_LIST32);
3326 buf.put_u32((content_size + 4) as u32); buf.put_u32(SaslOutcome::FIELD_COUNT as u32);
3328 } else {
3329 buf.put_u8(codec::FORMATCODE_LIST8);
3330 buf.put_u8((content_size + 1) as u8);
3331 buf.put_u8(SaslOutcome::FIELD_COUNT as u8);
3332 }
3333 list.code.encode(buf);
3334 list.additional_data.encode(buf);
3335}
3336impl DecodeFormatted for SaslOutcome {
3337 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3338 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3339 let (input, descriptor) = Descriptor::decode(input)?;
3340 let is_match = match descriptor {
3341 Descriptor::Ulong(val) => val == 68,
3342 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:sasl-outcome:list",
3343 };
3344 if !is_match {
3345 Err(AmqpParseError::InvalidDescriptor(descriptor))
3346 } else {
3347 decode_sasl_outcome_inner(input)
3348 }
3349 }
3350}
3351impl Encode for SaslOutcome {
3352 fn encoded_size(&self) -> usize {
3353 encoded_size_sasl_outcome_inner(self)
3354 }
3355 fn encode(&self, buf: &mut BytesMut) {
3356 encode_sasl_outcome_inner(self, buf)
3357 }
3358}
3359#[derive(Clone, Debug, PartialEq)]
3360pub struct Source {
3361 pub address: Option<Address>,
3362 pub durable: TerminusDurability,
3363 pub expiry_policy: TerminusExpiryPolicy,
3364 pub timeout: Seconds,
3365 pub dynamic: bool,
3366 pub dynamic_node_properties: Option<NodeProperties>,
3367 pub distribution_mode: Option<DistributionMode>,
3368 pub filter: Option<FilterSet>,
3369 pub default_outcome: Option<Outcome>,
3370 pub outcomes: Option<Symbols>,
3371 pub capabilities: Option<Symbols>,
3372}
3373impl Source {
3374 pub fn address(&self) -> Option<&Address> {
3375 self.address.as_ref()
3376 }
3377 pub fn durable(&self) -> TerminusDurability {
3378 self.durable
3379 }
3380 pub fn expiry_policy(&self) -> TerminusExpiryPolicy {
3381 self.expiry_policy
3382 }
3383 pub fn timeout(&self) -> Seconds {
3384 self.timeout
3385 }
3386 pub fn dynamic(&self) -> bool {
3387 self.dynamic
3388 }
3389 pub fn dynamic_node_properties(&self) -> Option<&NodeProperties> {
3390 self.dynamic_node_properties.as_ref()
3391 }
3392 pub fn distribution_mode(&self) -> Option<&DistributionMode> {
3393 self.distribution_mode.as_ref()
3394 }
3395 pub fn filter(&self) -> Option<&FilterSet> {
3396 self.filter.as_ref()
3397 }
3398 pub fn default_outcome(&self) -> Option<&Outcome> {
3399 self.default_outcome.as_ref()
3400 }
3401 pub fn outcomes(&self) -> Option<&Symbols> {
3402 self.outcomes.as_ref()
3403 }
3404 pub fn capabilities(&self) -> Option<&Symbols> {
3405 self.capabilities.as_ref()
3406 }
3407 #[allow(clippy::identity_op)]
3408 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
3409}
3410#[allow(unused_mut)]
3411fn decode_source_inner(input: &[u8]) -> Result<(&[u8], Source), AmqpParseError> {
3412 let (input, format) = decode_format_code(input)?;
3413 let (input, header) = decode_list_header(input, format)?;
3414 let size = header.size as usize;
3415 decode_check_len!(input, size);
3416 let (mut input, mut remainder) = input.split_at(size);
3417 let mut count = header.count;
3418 let address: Option<Address>;
3419 if count > 0 {
3420 let decoded = Option::<Address>::decode(input)?;
3421 input = decoded.0;
3422 address = decoded.1;
3423 count -= 1;
3424 } else {
3425 address = None;
3426 }
3427 let durable: TerminusDurability;
3428 if count > 0 {
3429 let (in1, decoded) = Option::<TerminusDurability>::decode(input)?;
3430 durable = decoded.unwrap_or(TerminusDurability::None);
3431 input = in1;
3432 count -= 1;
3433 } else {
3434 durable = TerminusDurability::None;
3435 }
3436 let expiry_policy: TerminusExpiryPolicy;
3437 if count > 0 {
3438 let (in1, decoded) = Option::<TerminusExpiryPolicy>::decode(input)?;
3439 expiry_policy = decoded.unwrap_or(TerminusExpiryPolicy::SessionEnd);
3440 input = in1;
3441 count -= 1;
3442 } else {
3443 expiry_policy = TerminusExpiryPolicy::SessionEnd;
3444 }
3445 let timeout: Seconds;
3446 if count > 0 {
3447 let (in1, decoded) = Option::<Seconds>::decode(input)?;
3448 timeout = decoded.unwrap_or(0);
3449 input = in1;
3450 count -= 1;
3451 } else {
3452 timeout = 0;
3453 }
3454 let dynamic: bool;
3455 if count > 0 {
3456 let (in1, decoded) = Option::<bool>::decode(input)?;
3457 dynamic = decoded.unwrap_or(false);
3458 input = in1;
3459 count -= 1;
3460 } else {
3461 dynamic = false;
3462 }
3463 let dynamic_node_properties: Option<NodeProperties>;
3464 if count > 0 {
3465 let decoded = Option::<NodeProperties>::decode(input)?;
3466 input = decoded.0;
3467 dynamic_node_properties = decoded.1;
3468 count -= 1;
3469 } else {
3470 dynamic_node_properties = None;
3471 }
3472 let distribution_mode: Option<DistributionMode>;
3473 if count > 0 {
3474 let decoded = Option::<DistributionMode>::decode(input)?;
3475 input = decoded.0;
3476 distribution_mode = decoded.1;
3477 count -= 1;
3478 } else {
3479 distribution_mode = None;
3480 }
3481 let filter: Option<FilterSet>;
3482 if count > 0 {
3483 let decoded = Option::<FilterSet>::decode(input)?;
3484 input = decoded.0;
3485 filter = decoded.1;
3486 count -= 1;
3487 } else {
3488 filter = None;
3489 }
3490 let default_outcome: Option<Outcome>;
3491 if count > 0 {
3492 let decoded = Option::<Outcome>::decode(input)?;
3493 input = decoded.0;
3494 default_outcome = decoded.1;
3495 count -= 1;
3496 } else {
3497 default_outcome = None;
3498 }
3499 let outcomes: Option<Symbols>;
3500 if count > 0 {
3501 let decoded = Option::<Symbols>::decode(input)?;
3502 input = decoded.0;
3503 outcomes = decoded.1;
3504 count -= 1;
3505 } else {
3506 outcomes = None;
3507 }
3508 let capabilities: Option<Symbols>;
3509 if count > 0 {
3510 let decoded = Option::<Symbols>::decode(input)?;
3511 input = decoded.0;
3512 capabilities = decoded.1;
3513 count -= 1;
3514 } else {
3515 capabilities = None;
3516 }
3517 Ok((
3518 remainder,
3519 Source {
3520 address,
3521 durable,
3522 expiry_policy,
3523 timeout,
3524 dynamic,
3525 dynamic_node_properties,
3526 distribution_mode,
3527 filter,
3528 default_outcome,
3529 outcomes,
3530 capabilities,
3531 },
3532 ))
3533}
3534fn encoded_size_source_inner(list: &Source) -> usize {
3535 #[allow(clippy::identity_op)]
3536 let content_size = 0
3537 + list.address.encoded_size()
3538 + list.durable.encoded_size()
3539 + list.expiry_policy.encoded_size()
3540 + list.timeout.encoded_size()
3541 + list.dynamic.encoded_size()
3542 + list.dynamic_node_properties.encoded_size()
3543 + list.distribution_mode.encoded_size()
3544 + list.filter.encoded_size()
3545 + list.default_outcome.encoded_size()
3546 + list.outcomes.encoded_size()
3547 + list.capabilities.encoded_size();
3548 (if content_size + 1 > u8::MAX as usize {
3550 12
3551 } else {
3552 6
3553 }) + content_size
3554}
3555fn encode_source_inner(list: &Source, buf: &mut BytesMut) {
3556 Descriptor::Ulong(40).encode(buf);
3557 #[allow(clippy::identity_op)]
3558 let content_size = 0
3559 + list.address.encoded_size()
3560 + list.durable.encoded_size()
3561 + list.expiry_policy.encoded_size()
3562 + list.timeout.encoded_size()
3563 + list.dynamic.encoded_size()
3564 + list.dynamic_node_properties.encoded_size()
3565 + list.distribution_mode.encoded_size()
3566 + list.filter.encoded_size()
3567 + list.default_outcome.encoded_size()
3568 + list.outcomes.encoded_size()
3569 + list.capabilities.encoded_size();
3570 if content_size + 1 > u8::MAX as usize {
3571 buf.put_u8(codec::FORMATCODE_LIST32);
3572 buf.put_u32((content_size + 4) as u32); buf.put_u32(Source::FIELD_COUNT as u32);
3574 } else {
3575 buf.put_u8(codec::FORMATCODE_LIST8);
3576 buf.put_u8((content_size + 1) as u8);
3577 buf.put_u8(Source::FIELD_COUNT as u8);
3578 }
3579 list.address.encode(buf);
3580 list.durable.encode(buf);
3581 list.expiry_policy.encode(buf);
3582 list.timeout.encode(buf);
3583 list.dynamic.encode(buf);
3584 list.dynamic_node_properties.encode(buf);
3585 list.distribution_mode.encode(buf);
3586 list.filter.encode(buf);
3587 list.default_outcome.encode(buf);
3588 list.outcomes.encode(buf);
3589 list.capabilities.encode(buf);
3590}
3591impl DecodeFormatted for Source {
3592 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3593 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3594 let (input, descriptor) = Descriptor::decode(input)?;
3595 let is_match = match descriptor {
3596 Descriptor::Ulong(val) => val == 40,
3597 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:source:list",
3598 };
3599 if !is_match {
3600 Err(AmqpParseError::InvalidDescriptor(descriptor))
3601 } else {
3602 decode_source_inner(input)
3603 }
3604 }
3605}
3606impl Encode for Source {
3607 fn encoded_size(&self) -> usize {
3608 encoded_size_source_inner(self)
3609 }
3610 fn encode(&self, buf: &mut BytesMut) {
3611 encode_source_inner(self, buf)
3612 }
3613}
3614#[derive(Clone, Debug, PartialEq)]
3615pub struct Target {
3616 pub address: Option<Address>,
3617 pub durable: TerminusDurability,
3618 pub expiry_policy: TerminusExpiryPolicy,
3619 pub timeout: Seconds,
3620 pub dynamic: bool,
3621 pub dynamic_node_properties: Option<NodeProperties>,
3622 pub capabilities: Option<Symbols>,
3623}
3624impl Target {
3625 pub fn address(&self) -> Option<&Address> {
3626 self.address.as_ref()
3627 }
3628 pub fn durable(&self) -> TerminusDurability {
3629 self.durable
3630 }
3631 pub fn expiry_policy(&self) -> TerminusExpiryPolicy {
3632 self.expiry_policy
3633 }
3634 pub fn timeout(&self) -> Seconds {
3635 self.timeout
3636 }
3637 pub fn dynamic(&self) -> bool {
3638 self.dynamic
3639 }
3640 pub fn dynamic_node_properties(&self) -> Option<&NodeProperties> {
3641 self.dynamic_node_properties.as_ref()
3642 }
3643 pub fn capabilities(&self) -> Option<&Symbols> {
3644 self.capabilities.as_ref()
3645 }
3646 #[allow(clippy::identity_op)]
3647 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
3648}
3649#[allow(unused_mut)]
3650fn decode_target_inner(input: &[u8]) -> Result<(&[u8], Target), AmqpParseError> {
3651 let (input, format) = decode_format_code(input)?;
3652 let (input, header) = decode_list_header(input, format)?;
3653 let size = header.size as usize;
3654 decode_check_len!(input, size);
3655 let (mut input, mut remainder) = input.split_at(size);
3656 let mut count = header.count;
3657 let address: Option<Address>;
3658 if count > 0 {
3659 let decoded = Option::<Address>::decode(input)?;
3660 input = decoded.0;
3661 address = decoded.1;
3662 count -= 1;
3663 } else {
3664 address = None;
3665 }
3666 let durable: TerminusDurability;
3667 if count > 0 {
3668 let (in1, decoded) = Option::<TerminusDurability>::decode(input)?;
3669 durable = decoded.unwrap_or(TerminusDurability::None);
3670 input = in1;
3671 count -= 1;
3672 } else {
3673 durable = TerminusDurability::None;
3674 }
3675 let expiry_policy: TerminusExpiryPolicy;
3676 if count > 0 {
3677 let (in1, decoded) = Option::<TerminusExpiryPolicy>::decode(input)?;
3678 expiry_policy = decoded.unwrap_or(TerminusExpiryPolicy::SessionEnd);
3679 input = in1;
3680 count -= 1;
3681 } else {
3682 expiry_policy = TerminusExpiryPolicy::SessionEnd;
3683 }
3684 let timeout: Seconds;
3685 if count > 0 {
3686 let (in1, decoded) = Option::<Seconds>::decode(input)?;
3687 timeout = decoded.unwrap_or(0);
3688 input = in1;
3689 count -= 1;
3690 } else {
3691 timeout = 0;
3692 }
3693 let dynamic: bool;
3694 if count > 0 {
3695 let (in1, decoded) = Option::<bool>::decode(input)?;
3696 dynamic = decoded.unwrap_or(false);
3697 input = in1;
3698 count -= 1;
3699 } else {
3700 dynamic = false;
3701 }
3702 let dynamic_node_properties: Option<NodeProperties>;
3703 if count > 0 {
3704 let decoded = Option::<NodeProperties>::decode(input)?;
3705 input = decoded.0;
3706 dynamic_node_properties = decoded.1;
3707 count -= 1;
3708 } else {
3709 dynamic_node_properties = None;
3710 }
3711 let capabilities: Option<Symbols>;
3712 if count > 0 {
3713 let decoded = Option::<Symbols>::decode(input)?;
3714 input = decoded.0;
3715 capabilities = decoded.1;
3716 count -= 1;
3717 } else {
3718 capabilities = None;
3719 }
3720 Ok((
3721 remainder,
3722 Target {
3723 address,
3724 durable,
3725 expiry_policy,
3726 timeout,
3727 dynamic,
3728 dynamic_node_properties,
3729 capabilities,
3730 },
3731 ))
3732}
3733fn encoded_size_target_inner(list: &Target) -> usize {
3734 #[allow(clippy::identity_op)]
3735 let content_size = 0
3736 + list.address.encoded_size()
3737 + list.durable.encoded_size()
3738 + list.expiry_policy.encoded_size()
3739 + list.timeout.encoded_size()
3740 + list.dynamic.encoded_size()
3741 + list.dynamic_node_properties.encoded_size()
3742 + list.capabilities.encoded_size();
3743 (if content_size + 1 > u8::MAX as usize {
3745 12
3746 } else {
3747 6
3748 }) + content_size
3749}
3750fn encode_target_inner(list: &Target, buf: &mut BytesMut) {
3751 Descriptor::Ulong(41).encode(buf);
3752 #[allow(clippy::identity_op)]
3753 let content_size = 0
3754 + list.address.encoded_size()
3755 + list.durable.encoded_size()
3756 + list.expiry_policy.encoded_size()
3757 + list.timeout.encoded_size()
3758 + list.dynamic.encoded_size()
3759 + list.dynamic_node_properties.encoded_size()
3760 + list.capabilities.encoded_size();
3761 if content_size + 1 > u8::MAX as usize {
3762 buf.put_u8(codec::FORMATCODE_LIST32);
3763 buf.put_u32((content_size + 4) as u32); buf.put_u32(Target::FIELD_COUNT as u32);
3765 } else {
3766 buf.put_u8(codec::FORMATCODE_LIST8);
3767 buf.put_u8((content_size + 1) as u8);
3768 buf.put_u8(Target::FIELD_COUNT as u8);
3769 }
3770 list.address.encode(buf);
3771 list.durable.encode(buf);
3772 list.expiry_policy.encode(buf);
3773 list.timeout.encode(buf);
3774 list.dynamic.encode(buf);
3775 list.dynamic_node_properties.encode(buf);
3776 list.capabilities.encode(buf);
3777}
3778impl DecodeFormatted for Target {
3779 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3780 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3781 let (input, descriptor) = Descriptor::decode(input)?;
3782 let is_match = match descriptor {
3783 Descriptor::Ulong(val) => val == 41,
3784 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:target:list",
3785 };
3786 if !is_match {
3787 Err(AmqpParseError::InvalidDescriptor(descriptor))
3788 } else {
3789 decode_target_inner(input)
3790 }
3791 }
3792}
3793impl Encode for Target {
3794 fn encoded_size(&self) -> usize {
3795 encoded_size_target_inner(self)
3796 }
3797 fn encode(&self, buf: &mut BytesMut) {
3798 encode_target_inner(self, buf)
3799 }
3800}
3801#[derive(Clone, Debug, PartialEq)]
3802pub struct Header {
3803 pub durable: bool,
3804 pub priority: u8,
3805 pub ttl: Option<Milliseconds>,
3806 pub first_acquirer: bool,
3807 pub delivery_count: u32,
3808}
3809impl Header {
3810 pub fn durable(&self) -> bool {
3811 self.durable
3812 }
3813 pub fn priority(&self) -> u8 {
3814 self.priority
3815 }
3816 pub fn ttl(&self) -> Option<Milliseconds> {
3817 self.ttl
3818 }
3819 pub fn first_acquirer(&self) -> bool {
3820 self.first_acquirer
3821 }
3822 pub fn delivery_count(&self) -> u32 {
3823 self.delivery_count
3824 }
3825 #[allow(clippy::identity_op)]
3826 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1;
3827}
3828#[allow(unused_mut)]
3829fn decode_header_inner(input: &[u8]) -> Result<(&[u8], Header), AmqpParseError> {
3830 let (input, format) = decode_format_code(input)?;
3831 let (input, header) = decode_list_header(input, format)?;
3832 let size = header.size as usize;
3833 decode_check_len!(input, size);
3834 let (mut input, mut remainder) = input.split_at(size);
3835 let mut count = header.count;
3836 let durable: bool;
3837 if count > 0 {
3838 let (in1, decoded) = Option::<bool>::decode(input)?;
3839 durable = decoded.unwrap_or(false);
3840 input = in1;
3841 count -= 1;
3842 } else {
3843 durable = false;
3844 }
3845 let priority: u8;
3846 if count > 0 {
3847 let (in1, decoded) = Option::<u8>::decode(input)?;
3848 priority = decoded.unwrap_or(4);
3849 input = in1;
3850 count -= 1;
3851 } else {
3852 priority = 4;
3853 }
3854 let ttl: Option<Milliseconds>;
3855 if count > 0 {
3856 let decoded = Option::<Milliseconds>::decode(input)?;
3857 input = decoded.0;
3858 ttl = decoded.1;
3859 count -= 1;
3860 } else {
3861 ttl = None;
3862 }
3863 let first_acquirer: bool;
3864 if count > 0 {
3865 let (in1, decoded) = Option::<bool>::decode(input)?;
3866 first_acquirer = decoded.unwrap_or(false);
3867 input = in1;
3868 count -= 1;
3869 } else {
3870 first_acquirer = false;
3871 }
3872 let delivery_count: u32;
3873 if count > 0 {
3874 let (in1, decoded) = Option::<u32>::decode(input)?;
3875 delivery_count = decoded.unwrap_or(0);
3876 input = in1;
3877 count -= 1;
3878 } else {
3879 delivery_count = 0;
3880 }
3881 Ok((
3882 remainder,
3883 Header {
3884 durable,
3885 priority,
3886 ttl,
3887 first_acquirer,
3888 delivery_count,
3889 },
3890 ))
3891}
3892fn encoded_size_header_inner(list: &Header) -> usize {
3893 #[allow(clippy::identity_op)]
3894 let content_size = 0
3895 + list.durable.encoded_size()
3896 + list.priority.encoded_size()
3897 + list.ttl.encoded_size()
3898 + list.first_acquirer.encoded_size()
3899 + list.delivery_count.encoded_size();
3900 (if content_size + 1 > u8::MAX as usize {
3902 12
3903 } else {
3904 6
3905 }) + content_size
3906}
3907fn encode_header_inner(list: &Header, buf: &mut BytesMut) {
3908 Descriptor::Ulong(112).encode(buf);
3909 #[allow(clippy::identity_op)]
3910 let content_size = 0
3911 + list.durable.encoded_size()
3912 + list.priority.encoded_size()
3913 + list.ttl.encoded_size()
3914 + list.first_acquirer.encoded_size()
3915 + list.delivery_count.encoded_size();
3916 if content_size + 1 > u8::MAX as usize {
3917 buf.put_u8(codec::FORMATCODE_LIST32);
3918 buf.put_u32((content_size + 4) as u32); buf.put_u32(Header::FIELD_COUNT as u32);
3920 } else {
3921 buf.put_u8(codec::FORMATCODE_LIST8);
3922 buf.put_u8((content_size + 1) as u8);
3923 buf.put_u8(Header::FIELD_COUNT as u8);
3924 }
3925 list.durable.encode(buf);
3926 list.priority.encode(buf);
3927 list.ttl.encode(buf);
3928 list.first_acquirer.encode(buf);
3929 list.delivery_count.encode(buf);
3930}
3931impl DecodeFormatted for Header {
3932 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
3933 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
3934 let (input, descriptor) = Descriptor::decode(input)?;
3935 let is_match = match descriptor {
3936 Descriptor::Ulong(val) => val == 112,
3937 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:header:list",
3938 };
3939 if !is_match {
3940 Err(AmqpParseError::InvalidDescriptor(descriptor))
3941 } else {
3942 decode_header_inner(input)
3943 }
3944 }
3945}
3946impl Encode for Header {
3947 fn encoded_size(&self) -> usize {
3948 encoded_size_header_inner(self)
3949 }
3950 fn encode(&self, buf: &mut BytesMut) {
3951 encode_header_inner(self, buf)
3952 }
3953}
3954#[derive(Clone, Debug, PartialEq)]
3955pub struct Properties {
3956 pub message_id: Option<MessageId>,
3957 pub user_id: Option<Bytes>,
3958 pub to: Option<Address>,
3959 pub subject: Option<ByteString>,
3960 pub reply_to: Option<Address>,
3961 pub correlation_id: Option<MessageId>,
3962 pub content_type: Option<Symbol>,
3963 pub content_encoding: Option<Symbol>,
3964 pub absolute_expiry_time: Option<Timestamp>,
3965 pub creation_time: Option<Timestamp>,
3966 pub group_id: Option<ByteString>,
3967 pub group_sequence: Option<SequenceNo>,
3968 pub reply_to_group_id: Option<ByteString>,
3969}
3970impl Properties {
3971 pub fn message_id(&self) -> Option<&MessageId> {
3972 self.message_id.as_ref()
3973 }
3974 pub fn user_id(&self) -> Option<&Bytes> {
3975 self.user_id.as_ref()
3976 }
3977 pub fn to(&self) -> Option<&Address> {
3978 self.to.as_ref()
3979 }
3980 pub fn subject(&self) -> Option<&ByteString> {
3981 self.subject.as_ref()
3982 }
3983 pub fn reply_to(&self) -> Option<&Address> {
3984 self.reply_to.as_ref()
3985 }
3986 pub fn correlation_id(&self) -> Option<&MessageId> {
3987 self.correlation_id.as_ref()
3988 }
3989 pub fn content_type(&self) -> Option<&Symbol> {
3990 self.content_type.as_ref()
3991 }
3992 pub fn content_encoding(&self) -> Option<&Symbol> {
3993 self.content_encoding.as_ref()
3994 }
3995 pub fn absolute_expiry_time(&self) -> Option<Timestamp> {
3996 self.absolute_expiry_time
3997 }
3998 pub fn creation_time(&self) -> Option<Timestamp> {
3999 self.creation_time
4000 }
4001 pub fn group_id(&self) -> Option<&ByteString> {
4002 self.group_id.as_ref()
4003 }
4004 pub fn group_sequence(&self) -> Option<SequenceNo> {
4005 self.group_sequence
4006 }
4007 pub fn reply_to_group_id(&self) -> Option<&ByteString> {
4008 self.reply_to_group_id.as_ref()
4009 }
4010 #[allow(clippy::identity_op)]
4011 const FIELD_COUNT: usize = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
4012}
4013#[allow(unused_mut)]
4014fn decode_properties_inner(input: &[u8]) -> Result<(&[u8], Properties), AmqpParseError> {
4015 let (input, format) = decode_format_code(input)?;
4016 let (input, header) = decode_list_header(input, format)?;
4017 let size = header.size as usize;
4018 decode_check_len!(input, size);
4019 let (mut input, mut remainder) = input.split_at(size);
4020 let mut count = header.count;
4021 let message_id: Option<MessageId>;
4022 if count > 0 {
4023 let decoded = Option::<MessageId>::decode(input)?;
4024 input = decoded.0;
4025 message_id = decoded.1;
4026 count -= 1;
4027 } else {
4028 message_id = None;
4029 }
4030 let user_id: Option<Bytes>;
4031 if count > 0 {
4032 let decoded = Option::<Bytes>::decode(input)?;
4033 input = decoded.0;
4034 user_id = decoded.1;
4035 count -= 1;
4036 } else {
4037 user_id = None;
4038 }
4039 let to: Option<Address>;
4040 if count > 0 {
4041 let decoded = Option::<Address>::decode(input)?;
4042 input = decoded.0;
4043 to = decoded.1;
4044 count -= 1;
4045 } else {
4046 to = None;
4047 }
4048 let subject: Option<ByteString>;
4049 if count > 0 {
4050 let decoded = Option::<ByteString>::decode(input)?;
4051 input = decoded.0;
4052 subject = decoded.1;
4053 count -= 1;
4054 } else {
4055 subject = None;
4056 }
4057 let reply_to: Option<Address>;
4058 if count > 0 {
4059 let decoded = Option::<Address>::decode(input)?;
4060 input = decoded.0;
4061 reply_to = decoded.1;
4062 count -= 1;
4063 } else {
4064 reply_to = None;
4065 }
4066 let correlation_id: Option<MessageId>;
4067 if count > 0 {
4068 let decoded = Option::<MessageId>::decode(input)?;
4069 input = decoded.0;
4070 correlation_id = decoded.1;
4071 count -= 1;
4072 } else {
4073 correlation_id = None;
4074 }
4075 let content_type: Option<Symbol>;
4076 if count > 0 {
4077 let decoded = Option::<Symbol>::decode(input)?;
4078 input = decoded.0;
4079 content_type = decoded.1;
4080 count -= 1;
4081 } else {
4082 content_type = None;
4083 }
4084 let content_encoding: Option<Symbol>;
4085 if count > 0 {
4086 let decoded = Option::<Symbol>::decode(input)?;
4087 input = decoded.0;
4088 content_encoding = decoded.1;
4089 count -= 1;
4090 } else {
4091 content_encoding = None;
4092 }
4093 let absolute_expiry_time: Option<Timestamp>;
4094 if count > 0 {
4095 let decoded = Option::<Timestamp>::decode(input)?;
4096 input = decoded.0;
4097 absolute_expiry_time = decoded.1;
4098 count -= 1;
4099 } else {
4100 absolute_expiry_time = None;
4101 }
4102 let creation_time: Option<Timestamp>;
4103 if count > 0 {
4104 let decoded = Option::<Timestamp>::decode(input)?;
4105 input = decoded.0;
4106 creation_time = decoded.1;
4107 count -= 1;
4108 } else {
4109 creation_time = None;
4110 }
4111 let group_id: Option<ByteString>;
4112 if count > 0 {
4113 let decoded = Option::<ByteString>::decode(input)?;
4114 input = decoded.0;
4115 group_id = decoded.1;
4116 count -= 1;
4117 } else {
4118 group_id = None;
4119 }
4120 let group_sequence: Option<SequenceNo>;
4121 if count > 0 {
4122 let decoded = Option::<SequenceNo>::decode(input)?;
4123 input = decoded.0;
4124 group_sequence = decoded.1;
4125 count -= 1;
4126 } else {
4127 group_sequence = None;
4128 }
4129 let reply_to_group_id: Option<ByteString>;
4130 if count > 0 {
4131 let decoded = Option::<ByteString>::decode(input)?;
4132 input = decoded.0;
4133 reply_to_group_id = decoded.1;
4134 count -= 1;
4135 } else {
4136 reply_to_group_id = None;
4137 }
4138 Ok((
4139 remainder,
4140 Properties {
4141 message_id,
4142 user_id,
4143 to,
4144 subject,
4145 reply_to,
4146 correlation_id,
4147 content_type,
4148 content_encoding,
4149 absolute_expiry_time,
4150 creation_time,
4151 group_id,
4152 group_sequence,
4153 reply_to_group_id,
4154 },
4155 ))
4156}
4157fn encoded_size_properties_inner(list: &Properties) -> usize {
4158 #[allow(clippy::identity_op)]
4159 let content_size = 0
4160 + list.message_id.encoded_size()
4161 + list.user_id.encoded_size()
4162 + list.to.encoded_size()
4163 + list.subject.encoded_size()
4164 + list.reply_to.encoded_size()
4165 + list.correlation_id.encoded_size()
4166 + list.content_type.encoded_size()
4167 + list.content_encoding.encoded_size()
4168 + list.absolute_expiry_time.encoded_size()
4169 + list.creation_time.encoded_size()
4170 + list.group_id.encoded_size()
4171 + list.group_sequence.encoded_size()
4172 + list.reply_to_group_id.encoded_size();
4173 (if content_size + 1 > u8::MAX as usize {
4175 12
4176 } else {
4177 6
4178 }) + content_size
4179}
4180fn encode_properties_inner(list: &Properties, buf: &mut BytesMut) {
4181 Descriptor::Ulong(115).encode(buf);
4182 #[allow(clippy::identity_op)]
4183 let content_size = 0
4184 + list.message_id.encoded_size()
4185 + list.user_id.encoded_size()
4186 + list.to.encoded_size()
4187 + list.subject.encoded_size()
4188 + list.reply_to.encoded_size()
4189 + list.correlation_id.encoded_size()
4190 + list.content_type.encoded_size()
4191 + list.content_encoding.encoded_size()
4192 + list.absolute_expiry_time.encoded_size()
4193 + list.creation_time.encoded_size()
4194 + list.group_id.encoded_size()
4195 + list.group_sequence.encoded_size()
4196 + list.reply_to_group_id.encoded_size();
4197 if content_size + 1 > u8::MAX as usize {
4198 buf.put_u8(codec::FORMATCODE_LIST32);
4199 buf.put_u32((content_size + 4) as u32); buf.put_u32(Properties::FIELD_COUNT as u32);
4201 } else {
4202 buf.put_u8(codec::FORMATCODE_LIST8);
4203 buf.put_u8((content_size + 1) as u8);
4204 buf.put_u8(Properties::FIELD_COUNT as u8);
4205 }
4206 list.message_id.encode(buf);
4207 list.user_id.encode(buf);
4208 list.to.encode(buf);
4209 list.subject.encode(buf);
4210 list.reply_to.encode(buf);
4211 list.correlation_id.encode(buf);
4212 list.content_type.encode(buf);
4213 list.content_encoding.encode(buf);
4214 list.absolute_expiry_time.encode(buf);
4215 list.creation_time.encode(buf);
4216 list.group_id.encode(buf);
4217 list.group_sequence.encode(buf);
4218 list.reply_to_group_id.encode(buf);
4219}
4220impl DecodeFormatted for Properties {
4221 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4222 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4223 let (input, descriptor) = Descriptor::decode(input)?;
4224 let is_match = match descriptor {
4225 Descriptor::Ulong(val) => val == 115,
4226 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:properties:list",
4227 };
4228 if !is_match {
4229 Err(AmqpParseError::InvalidDescriptor(descriptor))
4230 } else {
4231 decode_properties_inner(input)
4232 }
4233 }
4234}
4235impl Encode for Properties {
4236 fn encoded_size(&self) -> usize {
4237 encoded_size_properties_inner(self)
4238 }
4239 fn encode(&self, buf: &mut BytesMut) {
4240 encode_properties_inner(self, buf)
4241 }
4242}
4243#[derive(Clone, Debug, PartialEq)]
4244pub struct Received {
4245 pub section_number: u32,
4246 pub section_offset: u64,
4247}
4248impl Received {
4249 pub fn section_number(&self) -> u32 {
4250 self.section_number
4251 }
4252 pub fn section_offset(&self) -> u64 {
4253 self.section_offset
4254 }
4255 #[allow(clippy::identity_op)]
4256 const FIELD_COUNT: usize = 0 + 1 + 1;
4257}
4258#[allow(unused_mut)]
4259fn decode_received_inner(input: &[u8]) -> Result<(&[u8], Received), AmqpParseError> {
4260 let (input, format) = decode_format_code(input)?;
4261 let (input, header) = decode_list_header(input, format)?;
4262 let size = header.size as usize;
4263 decode_check_len!(input, size);
4264 let (mut input, mut remainder) = input.split_at(size);
4265 let mut count = header.count;
4266 let section_number: u32;
4267 if count > 0 {
4268 let (in1, decoded) = u32::decode(input)?;
4269 section_number = decoded;
4270 input = in1;
4271 count -= 1;
4272 } else {
4273 return Err(AmqpParseError::RequiredFieldOmitted("section_number"));
4274 }
4275 let section_offset: u64;
4276 if count > 0 {
4277 let (in1, decoded) = u64::decode(input)?;
4278 section_offset = decoded;
4279 input = in1;
4280 count -= 1;
4281 } else {
4282 return Err(AmqpParseError::RequiredFieldOmitted("section_offset"));
4283 }
4284 Ok((
4285 remainder,
4286 Received {
4287 section_number,
4288 section_offset,
4289 },
4290 ))
4291}
4292fn encoded_size_received_inner(list: &Received) -> usize {
4293 #[allow(clippy::identity_op)]
4294 let content_size = 0 + list.section_number.encoded_size() + list.section_offset.encoded_size();
4295 (if content_size + 1 > u8::MAX as usize {
4297 12
4298 } else {
4299 6
4300 }) + content_size
4301}
4302fn encode_received_inner(list: &Received, buf: &mut BytesMut) {
4303 Descriptor::Ulong(35).encode(buf);
4304 #[allow(clippy::identity_op)]
4305 let content_size = 0 + list.section_number.encoded_size() + list.section_offset.encoded_size();
4306 if content_size + 1 > u8::MAX as usize {
4307 buf.put_u8(codec::FORMATCODE_LIST32);
4308 buf.put_u32((content_size + 4) as u32); buf.put_u32(Received::FIELD_COUNT as u32);
4310 } else {
4311 buf.put_u8(codec::FORMATCODE_LIST8);
4312 buf.put_u8((content_size + 1) as u8);
4313 buf.put_u8(Received::FIELD_COUNT as u8);
4314 }
4315 list.section_number.encode(buf);
4316 list.section_offset.encode(buf);
4317}
4318impl DecodeFormatted for Received {
4319 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4320 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4321 let (input, descriptor) = Descriptor::decode(input)?;
4322 let is_match = match descriptor {
4323 Descriptor::Ulong(val) => val == 35,
4324 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:received:list",
4325 };
4326 if !is_match {
4327 Err(AmqpParseError::InvalidDescriptor(descriptor))
4328 } else {
4329 decode_received_inner(input)
4330 }
4331 }
4332}
4333impl Encode for Received {
4334 fn encoded_size(&self) -> usize {
4335 encoded_size_received_inner(self)
4336 }
4337 fn encode(&self, buf: &mut BytesMut) {
4338 encode_received_inner(self, buf)
4339 }
4340}
4341#[derive(Clone, Debug, PartialEq)]
4342pub struct Accepted {}
4343impl Accepted {
4344 #[allow(clippy::identity_op)]
4345 const FIELD_COUNT: usize = 0;
4346}
4347#[allow(unused_mut)]
4348fn decode_accepted_inner(input: &[u8]) -> Result<(&[u8], Accepted), AmqpParseError> {
4349 let (input, format) = decode_format_code(input)?;
4350 let (input, header) = decode_list_header(input, format)?;
4351 let size = header.size as usize;
4352 decode_check_len!(input, size);
4353 let mut remainder = &input[size..];
4354 Ok((remainder, Accepted {}))
4355}
4356fn encoded_size_accepted_inner(list: &Accepted) -> usize {
4357 #[allow(clippy::identity_op)]
4358 let content_size = 0;
4359 (if content_size + 1 > u8::MAX as usize {
4361 12
4362 } else {
4363 6
4364 }) + content_size
4365}
4366fn encode_accepted_inner(list: &Accepted, buf: &mut BytesMut) {
4367 Descriptor::Ulong(36).encode(buf);
4368 #[allow(clippy::identity_op)]
4369 let content_size = 0;
4370 if content_size + 1 > u8::MAX as usize {
4371 buf.put_u8(codec::FORMATCODE_LIST32);
4372 buf.put_u32((content_size + 4) as u32); buf.put_u32(Accepted::FIELD_COUNT as u32);
4374 } else {
4375 buf.put_u8(codec::FORMATCODE_LIST8);
4376 buf.put_u8((content_size + 1) as u8);
4377 buf.put_u8(Accepted::FIELD_COUNT as u8);
4378 }
4379}
4380impl DecodeFormatted for Accepted {
4381 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4382 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4383 let (input, descriptor) = Descriptor::decode(input)?;
4384 let is_match = match descriptor {
4385 Descriptor::Ulong(val) => val == 36,
4386 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:accepted:list",
4387 };
4388 if !is_match {
4389 Err(AmqpParseError::InvalidDescriptor(descriptor))
4390 } else {
4391 decode_accepted_inner(input)
4392 }
4393 }
4394}
4395impl Encode for Accepted {
4396 fn encoded_size(&self) -> usize {
4397 encoded_size_accepted_inner(self)
4398 }
4399 fn encode(&self, buf: &mut BytesMut) {
4400 encode_accepted_inner(self, buf)
4401 }
4402}
4403#[derive(Clone, Debug, PartialEq)]
4404pub struct Rejected {
4405 pub error: Option<Error>,
4406}
4407impl Rejected {
4408 pub fn error(&self) -> Option<&Error> {
4409 self.error.as_ref()
4410 }
4411 #[allow(clippy::identity_op)]
4412 const FIELD_COUNT: usize = 0 + 1;
4413}
4414#[allow(unused_mut)]
4415fn decode_rejected_inner(input: &[u8]) -> Result<(&[u8], Rejected), AmqpParseError> {
4416 let (input, format) = decode_format_code(input)?;
4417 let (input, header) = decode_list_header(input, format)?;
4418 let size = header.size as usize;
4419 decode_check_len!(input, size);
4420 let (mut input, mut remainder) = input.split_at(size);
4421 let mut count = header.count;
4422 let error: Option<Error>;
4423 if count > 0 {
4424 let decoded = Option::<Error>::decode(input)?;
4425 input = decoded.0;
4426 error = decoded.1;
4427 count -= 1;
4428 } else {
4429 error = None;
4430 }
4431 Ok((remainder, Rejected { error }))
4432}
4433fn encoded_size_rejected_inner(list: &Rejected) -> usize {
4434 #[allow(clippy::identity_op)]
4435 let content_size = 0 + list.error.encoded_size();
4436 (if content_size + 1 > u8::MAX as usize {
4438 12
4439 } else {
4440 6
4441 }) + content_size
4442}
4443fn encode_rejected_inner(list: &Rejected, buf: &mut BytesMut) {
4444 Descriptor::Ulong(37).encode(buf);
4445 #[allow(clippy::identity_op)]
4446 let content_size = 0 + list.error.encoded_size();
4447 if content_size + 1 > u8::MAX as usize {
4448 buf.put_u8(codec::FORMATCODE_LIST32);
4449 buf.put_u32((content_size + 4) as u32); buf.put_u32(Rejected::FIELD_COUNT as u32);
4451 } else {
4452 buf.put_u8(codec::FORMATCODE_LIST8);
4453 buf.put_u8((content_size + 1) as u8);
4454 buf.put_u8(Rejected::FIELD_COUNT as u8);
4455 }
4456 list.error.encode(buf);
4457}
4458impl DecodeFormatted for Rejected {
4459 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4460 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4461 let (input, descriptor) = Descriptor::decode(input)?;
4462 let is_match = match descriptor {
4463 Descriptor::Ulong(val) => val == 37,
4464 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:rejected:list",
4465 };
4466 if !is_match {
4467 Err(AmqpParseError::InvalidDescriptor(descriptor))
4468 } else {
4469 decode_rejected_inner(input)
4470 }
4471 }
4472}
4473impl Encode for Rejected {
4474 fn encoded_size(&self) -> usize {
4475 encoded_size_rejected_inner(self)
4476 }
4477 fn encode(&self, buf: &mut BytesMut) {
4478 encode_rejected_inner(self, buf)
4479 }
4480}
4481#[derive(Clone, Debug, PartialEq)]
4482pub struct Released {}
4483impl Released {
4484 #[allow(clippy::identity_op)]
4485 const FIELD_COUNT: usize = 0;
4486}
4487#[allow(unused_mut)]
4488fn decode_released_inner(input: &[u8]) -> Result<(&[u8], Released), AmqpParseError> {
4489 let (input, format) = decode_format_code(input)?;
4490 let (input, header) = decode_list_header(input, format)?;
4491 let size = header.size as usize;
4492 decode_check_len!(input, size);
4493 let mut remainder = &input[size..];
4494 Ok((remainder, Released {}))
4495}
4496fn encoded_size_released_inner(list: &Released) -> usize {
4497 #[allow(clippy::identity_op)]
4498 let content_size = 0;
4499 (if content_size + 1 > u8::MAX as usize {
4501 12
4502 } else {
4503 6
4504 }) + content_size
4505}
4506fn encode_released_inner(list: &Released, buf: &mut BytesMut) {
4507 Descriptor::Ulong(38).encode(buf);
4508 #[allow(clippy::identity_op)]
4509 let content_size = 0;
4510 if content_size + 1 > u8::MAX as usize {
4511 buf.put_u8(codec::FORMATCODE_LIST32);
4512 buf.put_u32((content_size + 4) as u32); buf.put_u32(Released::FIELD_COUNT as u32);
4514 } else {
4515 buf.put_u8(codec::FORMATCODE_LIST8);
4516 buf.put_u8((content_size + 1) as u8);
4517 buf.put_u8(Released::FIELD_COUNT as u8);
4518 }
4519}
4520impl DecodeFormatted for Released {
4521 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4522 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4523 let (input, descriptor) = Descriptor::decode(input)?;
4524 let is_match = match descriptor {
4525 Descriptor::Ulong(val) => val == 38,
4526 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:released:list",
4527 };
4528 if !is_match {
4529 Err(AmqpParseError::InvalidDescriptor(descriptor))
4530 } else {
4531 decode_released_inner(input)
4532 }
4533 }
4534}
4535impl Encode for Released {
4536 fn encoded_size(&self) -> usize {
4537 encoded_size_released_inner(self)
4538 }
4539 fn encode(&self, buf: &mut BytesMut) {
4540 encode_released_inner(self, buf)
4541 }
4542}
4543#[derive(Clone, Debug, PartialEq)]
4544pub struct Modified {
4545 pub delivery_failed: Option<bool>,
4546 pub undeliverable_here: Option<bool>,
4547 pub message_annotations: Option<Fields>,
4548}
4549impl Modified {
4550 pub fn delivery_failed(&self) -> Option<bool> {
4551 self.delivery_failed
4552 }
4553 pub fn undeliverable_here(&self) -> Option<bool> {
4554 self.undeliverable_here
4555 }
4556 pub fn message_annotations(&self) -> Option<&Fields> {
4557 self.message_annotations.as_ref()
4558 }
4559 #[allow(clippy::identity_op)]
4560 const FIELD_COUNT: usize = 0 + 1 + 1 + 1;
4561}
4562#[allow(unused_mut)]
4563fn decode_modified_inner(input: &[u8]) -> Result<(&[u8], Modified), AmqpParseError> {
4564 let (input, format) = decode_format_code(input)?;
4565 let (input, header) = decode_list_header(input, format)?;
4566 let size = header.size as usize;
4567 decode_check_len!(input, size);
4568 let (mut input, mut remainder) = input.split_at(size);
4569 let mut count = header.count;
4570 let delivery_failed: Option<bool>;
4571 if count > 0 {
4572 let decoded = Option::<bool>::decode(input)?;
4573 input = decoded.0;
4574 delivery_failed = decoded.1;
4575 count -= 1;
4576 } else {
4577 delivery_failed = None;
4578 }
4579 let undeliverable_here: Option<bool>;
4580 if count > 0 {
4581 let decoded = Option::<bool>::decode(input)?;
4582 input = decoded.0;
4583 undeliverable_here = decoded.1;
4584 count -= 1;
4585 } else {
4586 undeliverable_here = None;
4587 }
4588 let message_annotations: Option<Fields>;
4589 if count > 0 {
4590 let decoded = Option::<Fields>::decode(input)?;
4591 input = decoded.0;
4592 message_annotations = decoded.1;
4593 count -= 1;
4594 } else {
4595 message_annotations = None;
4596 }
4597 Ok((
4598 remainder,
4599 Modified {
4600 delivery_failed,
4601 undeliverable_here,
4602 message_annotations,
4603 },
4604 ))
4605}
4606fn encoded_size_modified_inner(list: &Modified) -> usize {
4607 #[allow(clippy::identity_op)]
4608 let content_size = 0
4609 + list.delivery_failed.encoded_size()
4610 + list.undeliverable_here.encoded_size()
4611 + list.message_annotations.encoded_size();
4612 (if content_size + 1 > u8::MAX as usize {
4614 12
4615 } else {
4616 6
4617 }) + content_size
4618}
4619fn encode_modified_inner(list: &Modified, buf: &mut BytesMut) {
4620 Descriptor::Ulong(39).encode(buf);
4621 #[allow(clippy::identity_op)]
4622 let content_size = 0
4623 + list.delivery_failed.encoded_size()
4624 + list.undeliverable_here.encoded_size()
4625 + list.message_annotations.encoded_size();
4626 if content_size + 1 > u8::MAX as usize {
4627 buf.put_u8(codec::FORMATCODE_LIST32);
4628 buf.put_u32((content_size + 4) as u32); buf.put_u32(Modified::FIELD_COUNT as u32);
4630 } else {
4631 buf.put_u8(codec::FORMATCODE_LIST8);
4632 buf.put_u8((content_size + 1) as u8);
4633 buf.put_u8(Modified::FIELD_COUNT as u8);
4634 }
4635 list.delivery_failed.encode(buf);
4636 list.undeliverable_here.encode(buf);
4637 list.message_annotations.encode(buf);
4638}
4639impl DecodeFormatted for Modified {
4640 fn decode_with_format(input: &[u8], fmt: u8) -> Result<(&[u8], Self), AmqpParseError> {
4641 validate_code!(fmt, codec::FORMATCODE_DESCRIBED);
4642 let (input, descriptor) = Descriptor::decode(input)?;
4643 let is_match = match descriptor {
4644 Descriptor::Ulong(val) => val == 39,
4645 Descriptor::Symbol(ref sym) => sym.as_bytes() == b"amqp:modified:list",
4646 };
4647 if !is_match {
4648 Err(AmqpParseError::InvalidDescriptor(descriptor))
4649 } else {
4650 decode_modified_inner(input)
4651 }
4652 }
4653}
4654impl Encode for Modified {
4655 fn encoded_size(&self) -> usize {
4656 encoded_size_modified_inner(self)
4657 }
4658 fn encode(&self, buf: &mut BytesMut) {
4659 encode_modified_inner(self, buf)
4660 }
4661}