private static Attach ReadAttach()

in src/Proton/Codec/Decoders/Transport/AttachTypeDecoder.cs [68:154]


      private static Attach ReadAttach(IProtonBuffer buffer, IDecoderState state, IListTypeDecoder listDecoder)
      {
         Attach result = new();

         _ = listDecoder.ReadSize(buffer, state);
         int count = listDecoder.ReadCount(buffer, 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.
            bool nullValue = buffer.GetByte(buffer.ReadOffset) == (byte)EncodingCodes.Null;
            if (nullValue)
            {
               // Ensure mandatory fields are set
               if (index < MinAttachListEntries)
               {
                  throw new DecodeException(ErrorForMissingRequiredFields(index));
               }

               buffer.ReadByte();
               continue;
            }

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

         return result;
      }