static void Encode(Array value, int width, int encodeSize, ByteBuffer buffer) { encodeSize -= FixedWidth.FormatCode + width; if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, (byte)encodeSize); AmqpBitConverter.WriteUByte(buffer, (byte)value.Length); } else { AmqpBitConverter.WriteUInt(buffer, (uint)encodeSize); AmqpBitConverter.WriteUInt(buffer, (uint)value.Length); } if (value.Length > 0) { object firstItem = value.GetValue(0); EncodingBase encoding = AmqpEncoding.GetEncoding(firstItem); AmqpBitConverter.WriteUByte(buffer, encoding.FormatCode); if (encoding.FormatCode == FormatCode.Described) { DescribedType describedValue = (DescribedType)firstItem; AmqpEncoding.EncodeObject(describedValue.Descriptor, buffer); AmqpBitConverter.WriteUByte(buffer, AmqpEncoding.GetEncoding(describedValue.Value).FormatCode); } foreach (object item in value) { encoding.EncodeObject(item, true, buffer); } } }
internal static void EncodeValue(AmqpSymbol value, FormatCode formatCode, ByteBuffer buffer) { int len = value.Value.Length; if (formatCode == FormatCode.Symbol8) { AmqpBitConverter.WriteUByte(buffer, (byte)len); } else { AmqpBitConverter.WriteUInt(buffer, (uint)len); } buffer.Validate(write: true, len); int bytes = Encoding.ASCII.GetBytes(value.Value, 0, len, buffer.Buffer, buffer.WritePos); if (bytes != len) { throw new AmqpException(new Error() { Condition = AmqpErrorCode.InternalError, Description = "Symbol encoded byte count not equal to its length." }); } buffer.Append(len); }
static void Encode(byte[] encodedData, int width, ByteBuffer buffer) { if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, (byte)encodedData.Length); } else { AmqpBitConverter.WriteUInt(buffer, (uint)encodedData.Length); } AmqpBitConverter.WriteBytes(buffer, encodedData, 0, encodedData.Length); }
public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer) { if (arrayEncoding) { ArraySegment <byte> binaryValue = (ArraySegment <byte>)value; AmqpBitConverter.WriteUInt(buffer, (uint)binaryValue.Count); AmqpBitConverter.WriteBytes(buffer, binaryValue.Array, binaryValue.Offset, binaryValue.Count); } else { BinaryEncoding.Encode((ArraySegment <byte>)value, buffer); } }
internal static void Encode(IList value, int count, Type itemType, int width, int encodeSize, ByteBuffer buffer) { encodeSize -= FixedWidth.FormatCode + width; if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, (byte)encodeSize); AmqpBitConverter.WriteUByte(buffer, (byte)count); } else { AmqpBitConverter.WriteUInt(buffer, (uint)encodeSize); AmqpBitConverter.WriteUInt(buffer, (uint)count); } EncodeValue(value, count, itemType, buffer); }
static void Encode(IList value, int width, int size, ByteBuffer buffer) { if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, (byte)size); AmqpBitConverter.WriteUByte(buffer, (byte)value.Count); } else { AmqpBitConverter.WriteUInt(buffer, (uint)size); AmqpBitConverter.WriteUInt(buffer, (uint)value.Count); } if (value.Count > 0) { foreach (object item in value) { AmqpEncoding.EncodeObject(item, buffer); } } }
static void Encode(AmqpMap value, int width, int size, ByteBuffer buffer) { if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, (byte)size); AmqpBitConverter.WriteUByte(buffer, (byte)(value.Count * 2)); } else { AmqpBitConverter.WriteUInt(buffer, (uint)size); AmqpBitConverter.WriteUInt(buffer, (uint)(value.Count * 2)); } if (value.Count > 0) { foreach (KeyValuePair <MapKey, object> item in value) { AmqpEncoding.EncodeObject(item.Key.Key, buffer); AmqpEncoding.EncodeObject(item.Value, buffer); } } }
public static void Encode(ArraySegment <byte> value, ByteBuffer buffer) { if (value.Array == null) { AmqpEncoding.EncodeNull(buffer); } else { int width = AmqpEncoding.GetEncodeWidthBySize(value.Count); if (width == FixedWidth.UByte) { AmqpBitConverter.WriteUByte(buffer, FormatCode.Binary8); AmqpBitConverter.WriteUByte(buffer, (byte)value.Count); } else { AmqpBitConverter.WriteUByte(buffer, FormatCode.Binary32); AmqpBitConverter.WriteUInt(buffer, (uint)value.Count); } AmqpBitConverter.WriteBytes(buffer, value.Array, value.Offset, value.Count); } }
internal static void EncodeValue(IList value, int count, Type itemType, ByteBuffer buffer) { if (count == 0) { return; } EncodingBase encoding = AmqpEncoding.GetEncoding(itemType); switch (encoding.FormatCode) { case FormatCode.UInt: EncodeArray <uint>(buffer, (IList <uint>)value, count, FormatCode.UInt, (b, v, i) => AmqpBitConverter.WriteUInt(b, v)); return; case FormatCode.Int: buffer.Validate(true, FixedWidth.Int * count); EncodeArray <int>(buffer, (IList <int>)value, count, FormatCode.Int, (b, v, i) => { AmqpBitConverter.WriteInt(b.Buffer, b.WritePos + i * FixedWidth.Int, v); }); buffer.Append(FixedWidth.Int * count); return; case FormatCode.ULong: EncodeArray <ulong>(buffer, (IList <ulong>)value, count, FormatCode.ULong, (b, v, i) => AmqpBitConverter.WriteULong(b, v)); return; case FormatCode.Long: EncodeArray <long>(buffer, (IList <long>)value, count, FormatCode.Long, (b, v, i) => AmqpBitConverter.WriteLong(b, v)); return; case FormatCode.Symbol32: EncodeArray <AmqpSymbol>(buffer, (IList <AmqpSymbol>)value, count, FormatCode.Symbol32, (b, v, i) => SymbolEncoding.EncodeValue(v, FormatCode.Symbol32, b)); return; case FormatCode.Boolean: EncodeArray <bool>(buffer, (IList <bool>)value, count, FormatCode.Boolean, (b, v, i) => AmqpBitConverter.WriteUByte(b, (byte)(v ? 1 : 0))); return; case FormatCode.UByte: EncodeArray <byte>(buffer, (IList <byte>)value, count, FormatCode.UByte, (b, v, i) => AmqpBitConverter.WriteUByte(b, v)); return; case FormatCode.Byte: EncodeArray <sbyte>(buffer, (IList <sbyte>)value, count, FormatCode.Byte, (b, v, i) => AmqpBitConverter.WriteByte(b, v)); return; case FormatCode.UShort: EncodeArray <ushort>(buffer, (IList <ushort>)value, count, FormatCode.UShort, (b, v, i) => AmqpBitConverter.WriteUShort(b, v)); return; case FormatCode.Short: EncodeArray <short>(buffer, (IList <short>)value, count, FormatCode.Short, (b, v, i) => AmqpBitConverter.WriteShort(b, v)); return; case FormatCode.Float: EncodeArray <float>(buffer, (IList <float>)value, count, FormatCode.Float, (b, v, i) => AmqpBitConverter.WriteFloat(b, v)); return; case FormatCode.Double: EncodeArray <double>(buffer, (IList <double>)value, count, FormatCode.Double, (b, v, i) => AmqpBitConverter.WriteDouble(b, v)); return; case FormatCode.Decimal128: EncodeArray <decimal>(buffer, (IList <decimal>)value, count, FormatCode.Decimal128, (b, v, i) => DecimalEncoding.EncodeValue(v, b)); return; case FormatCode.Char: EncodeArray <char>(buffer, (IList <char>)value, count, FormatCode.Char, (b, v, i) => AmqpBitConverter.WriteChar(b, v)); return; case FormatCode.TimeStamp: EncodeArray <DateTime>(buffer, (IList <DateTime>)value, count, FormatCode.TimeStamp, (b, v, i) => AmqpBitConverter.WriteTimestamp(b, v)); return; case FormatCode.Uuid: EncodeArray <Guid>(buffer, (IList <Guid>)value, count, FormatCode.Uuid, (b, v, i) => AmqpBitConverter.WriteUuid(b, v)); return; default: break; } object firstItem = value[0]; AmqpBitConverter.WriteUByte(buffer, encoding.FormatCode); if (encoding.FormatCode == FormatCode.Described) { DescribedType describedValue = (DescribedType)firstItem; AmqpEncoding.EncodeObject(describedValue.Descriptor, buffer); AmqpBitConverter.WriteUByte(buffer, AmqpEncoding.GetEncoding(describedValue.Value).FormatCode); } for (int i = 0; i < count; i++) { encoding.EncodeObject(value[i], true, buffer); } }