protected override void WriteElement()

in src/Proton/Codec/Encoders/Transport/OpenTypeEncoder.cs [46:157]


      protected override void WriteElement(Open open, int index, IProtonBuffer buffer, IEncoderState state)
      {
         // When encoding ensure that values that were never set are omitted and a simple
         // NULL entry is written in the slot instead (don't write defaults).
         buffer.EnsureWritable(sizeof(int));

         switch (index)
         {
            case 0:
               if (open.HasContainerId())
               {
                  state.Encoder.WriteString(buffer, state, open.ContainerId);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 1:
               if (open.HasHostname())
               {
                  state.Encoder.WriteString(buffer, state, open.Hostname);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 2:
               if (open.HasMaxFrameSize())
               {
                  state.Encoder.WriteUnsignedInteger(buffer, state, open.MaxFrameSize);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 3:
               if (open.HasChannelMax())
               {
                  state.Encoder.WriteUnsignedShort(buffer, state, open.ChannelMax);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 4:
               if (open.HasIdleTimeout())
               {
                  state.Encoder.WriteUnsignedInteger(buffer, state, open.IdleTimeout);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 5:
               if (open.HasOutgoingLocales())
               {
                  state.Encoder.WriteArray(buffer, state, open.OutgoingLocales);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 6:
               if (open.HasIncomingLocales())
               {
                  state.Encoder.WriteArray(buffer, state, open.IncomingLocales);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 7:
               if (open.HasOfferedCapabilities())
               {
                  state.Encoder.WriteArray(buffer, state, open.OfferedCapabilities);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 8:
               if (open.HasDesiredCapabilities())
               {
                  state.Encoder.WriteArray(buffer, state, open.DesiredCapabilities);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            case 9:
               if (open.HasProperties())
               {
                  state.Encoder.WriteMap(buffer, state, open.Properties);
               }
               else
               {
                  buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
               }
               break;
            default:
               throw new ArgumentOutOfRangeException("Unknown Open value index: " + index);
         }
      }