private static Disposition ReadDisposition()

in src/Proton/Codec/Decoders/Transport/DispositionTypeDecoder.cs [67:126]


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

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

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

         if (count > MaxDispositionListEntries)
         {
            throw new DecodeException("To many entries in Disposition 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 < MinDispositionListEntries)
               {
                  throw new DecodeException(ErrorForMissingRequiredFields(index));
               }

               buffer.ReadByte();
               continue;
            }

            switch (index)
            {
               case 0:
                  result.Role = RoleExtension.Lookup(state.Decoder.ReadBoolean(buffer, state) ?? false);
                  break;
               case 1:
                  result.First = state.Decoder.ReadUnsignedInteger(buffer, state) ?? 0;
                  break;
               case 2:
                  result.Last = state.Decoder.ReadUnsignedInteger(buffer, state) ?? 0;
                  break;
               case 3:
                  result.Settled = state.Decoder.ReadBoolean(buffer, state) ?? false;
                  break;
               case 4:
                  result.State = state.Decoder.ReadObject<IDeliveryState>(buffer, state);
                  break;
               case 5:
                  result.Batchable = state.Decoder.ReadBoolean(buffer, state) ?? false;
                  break;
            }
         }

         return result;
      }