in src/Proton/Codec/Encoders/Transport/DispositionTypeEncoder.cs [54:136]
protected override void WriteElement(Disposition disposition, 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 (disposition.HasRole())
{
buffer.WriteUnsignedByte((byte)disposition.Role.ToBooleanEncoding());
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
case 1:
if (disposition.HasFirst())
{
state.Encoder.WriteUnsignedInteger(buffer, state, disposition.First);
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
case 2:
if (disposition.HasLast())
{
state.Encoder.WriteUnsignedInteger(buffer, state, disposition.Last);
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
case 3:
if (disposition.HasSettled())
{
buffer.WriteUnsignedByte((byte)(disposition.Settled ? EncodingCodes.BooleanTrue : EncodingCodes.BooleanFalse));
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
case 4:
if (disposition.HasState())
{
if (disposition.State == Accepted.Instance)
{
buffer.WriteUnsignedByte((byte)EncodingCodes.DescribedTypeIndicator);
buffer.WriteUnsignedByte((byte)EncodingCodes.SmallULong);
buffer.WriteUnsignedByte((byte)Accepted.DescriptorCode);
buffer.WriteUnsignedByte((byte)EncodingCodes.List0);
}
else
{
state.Encoder.WriteObject(buffer, state, disposition.State);
}
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
case 5:
if (disposition.HasBatchable())
{
buffer.WriteUnsignedByte((byte)(disposition.Batchable ? EncodingCodes.BooleanTrue : EncodingCodes.BooleanFalse));
}
else
{
buffer.WriteUnsignedByte((byte)EncodingCodes.Null);
}
break;
default:
throw new ArgumentOutOfRangeException("Unknown Disposition value index: " + index);
}
}