ntex_amqp_codec/protocol/
definitions.rs

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