private static Attach ReadAttach()

in src/Proton/Codec/Decoders/Transport/AttachTypeDecoder.cs [185:277]


      private static Attach ReadAttach(Stream stream, IStreamDecoderState state, IListTypeDecoder listDecoder)
      {
         Attach result = new();

         _ = listDecoder.ReadSize(stream, state);
         int count = listDecoder.ReadCount(stream, state);

         if (count < MinAttachListEntries)
         {
            throw new DecodeException(ErrorForMissingRequiredFields(count));
         }

         if (count > MaxAttachListEntries)
         {
            throw new DecodeException("To many entries in Attach list encoding: " + count);
         }

         for (int index = 0; index < count; ++index)
         {
            // Peek ahead and see if there is a null in the next slot, if so we don't call
            // the setter for that entry to ensure the returned type reflects the encoded
            // state in the modification entry.
            if (stream.CanSeek)
            {
               bool nullValue = stream.ReadByte() == (byte)EncodingCodes.Null;
               if (nullValue)
               {
                  // Ensure mandatory fields are set
                  if (index < MinAttachListEntries)
                  {
                     throw new DecodeException(ErrorForMissingRequiredFields(index));
                  }

                  continue;
               }
               else
               {
                  stream.Seek(-1, SeekOrigin.Current);
               }
            }

            switch (index)
            {
               case 0:
                  result.Name = state.Decoder.ReadString(stream, state);
                  break;
               case 1:
                  result.Handle = state.Decoder.ReadUnsignedInteger(stream, state) ?? 0;
                  break;
               case 2:
                  bool role = state.Decoder.ReadBoolean(stream, state) ?? false;
                  result.Role = RoleExtension.Lookup(role);
                  break;
               case 3:
                  byte sndSettleMode = state.Decoder.ReadUnsignedByte(stream, state) ?? 0;
                  result.SenderSettleMode = SenderSettleModeExtension.Lookup(sndSettleMode);
                  break;
               case 4:
                  byte rcvSettleMode = state.Decoder.ReadUnsignedByte(stream, state) ?? 0;
                  result.ReceiverSettleMode = ReceiverSettleModeExtension.Lookup(rcvSettleMode);
                  break;
               case 5:
                  result.Source = state.Decoder.ReadObject<Source>(stream, state);
                  break;
               case 6:
                  result.Target = state.Decoder.ReadObject<ITerminus>(stream, state);
                  break;
               case 7:
                  result.Unsettled = state.Decoder.ReadMap<IProtonBuffer, IDeliveryState>(stream, state);
                  break;
               case 8:
                  result.IncompleteUnsettled = state.Decoder.ReadBoolean(stream, state) ?? false;
                  break;
               case 9:
                  result.InitialDeliveryCount = state.Decoder.ReadUnsignedInteger(stream, state) ?? 0;
                  break;
               case 10:
                  result.MaxMessageSize = state.Decoder.ReadUnsignedLong(stream, state) ?? 0;
                  break;
               case 11:
                  result.OfferedCapabilities = state.Decoder.ReadMultiple<Symbol>(stream, state);
                  break;
               case 12:
                  result.DesiredCapabilities = state.Decoder.ReadMultiple<Symbol>(stream, state);
                  break;
               case 13:
                  result.Properties = state.Decoder.ReadMap<Symbol, object>(stream, state);
                  break;
            }
         }

         return result;
      }