protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeMultiple <AmqpSymbol>(this.Capabilities, buffer); }
public void AmqpSerializerListEncodingTest() { Action <Person, Person> personValidator = (p1, p2) => { Assert.NotNull(p2); Assert.True(21 == p2.Age, "Age should be increased by OnDeserialized"); Assert.Equal(p1.GetType().Name, p2.GetType().Name); Assert.Equal(p1.DateOfBirth.Value, p2.DateOfBirth.Value); Assert.Equal(p1.Properties.Count, p2.Properties.Count); foreach (var k in p1.Properties.Keys) { Assert.Equal(p1.Properties[k], p2.Properties[k]); } }; Action <List <int>, List <int> > gradesValidator = (l1, l2) => { if (l1 == null || l2 == null) { Assert.True(l1 == null && l2 == null); return; } Assert.Equal(l1.Count, l2.Count); for (int i = 0; i < l1.Count; ++i) { Assert.Equal(l1[i], l2[i]); } }; // Create an object to be serialized Person p = new Student("Tom") { Address = new Address() { FullAddress = new string('B', 1024) }, Grades = new List <int>() { 1, 2, 3, 4, 5 } }; p.Age = 20; p.DateOfBirth = new DateTime(1980, 5, 12, 10, 2, 45, DateTimeKind.Utc); p.Properties.Add("height", 6.1); p.Properties.Add("male", true); p.Properties.Add("nick-name", "big foot"); var stream = new MemoryStream(new byte[4096], 0, 4096, true, true); AmqpContractSerializer.WriteObject(stream, p); stream.Flush(); // Deserialize and verify stream.Seek(0, SeekOrigin.Begin); Person p3 = AmqpContractSerializer.ReadObject <Person>(stream); personValidator(p, p3); Assert.Equal(((Student)p).Address.FullAddress, ((Student)p3).Address.FullAddress); gradesValidator(((Student)p).Grades, ((Student)p3).Grades); // Inter-op: it should be an AMQP described list as other clients see it stream.Seek(0, SeekOrigin.Begin); DescribedType dl1 = DescribedEncoding.Decode(new ByteBuffer(stream.ToArray(), 0, (int)stream.Length)); Assert.Equal(dl1.Descriptor, 1ul); List <object> lv = dl1.Value as List <object>; Assert.NotNull(lv); Assert.Equal(p.Name, lv[0]); Assert.Equal(p.Age, lv[1]); Assert.Equal(p.DateOfBirth.Value, lv[2]); Assert.True(lv[3] is DescribedType, "Address is decribed type"); Assert.Equal(((DescribedType)lv[3]).Descriptor, 3ul); Assert.Equal(((List <object>)((DescribedType)lv[3]).Value)[0], ((Student)p).Address.FullAddress); Assert.True(lv[4] is AmqpMap, "Properties should be map"); Assert.Equal(((AmqpMap)lv[4])[new MapKey("height")], p.Properties["height"]); Assert.Equal(((AmqpMap)lv[4])[new MapKey("male")], p.Properties["male"]); Assert.Equal(((AmqpMap)lv[4])[new MapKey("nick-name")], p.Properties["nick-name"]); Assert.True(lv[5] is List <object>); // Non-default serializer AmqpContractSerializer serializer = new AmqpContractSerializer(); ByteBuffer bf1 = new ByteBuffer(1024, true); serializer.WriteObjectInternal(bf1, p); Person p4 = serializer.ReadObjectInternal <Person, Person>(bf1); personValidator(p, p4); // Extensible: more items in the payload should not break DescribedType dl2 = new DescribedType( new AmqpSymbol("teacher"), new List <object>() { "Jerry", 40, null, 50000, lv[4], null, null, "unknown-string", true, new AmqpSymbol("unknown-symbol") }); ByteBuffer bf2 = new ByteBuffer(1024, true); DescribedEncoding.Encode(dl2, bf2); ULongEncoding.Encode(100, bf2); Person p5 = serializer.ReadObjectInternal <Person, Person>(bf2); Assert.True(p5 is Teacher); Assert.Equal(100ul, AmqpCodec.DecodeULong(bf2)); // unknowns should be skipped Assert.Equal(0, bf2.Length); // teacher Teacher teacher = new Teacher("Han"); teacher.Age = 30; teacher.Sallary = 60000; teacher.Classes = new Dictionary <int, string>() { { 101, "CS" }, { 102, "Math" }, { 205, "Project" } }; ByteBuffer bf3 = new ByteBuffer(1024, true); serializer.WriteObjectInternal(bf3, teacher); Person p6 = serializer.ReadObjectInternal <Person, Person>(bf3); Assert.True(p6 is Teacher); Assert.Equal(teacher.Age + 1, p6.Age); Assert.Equal(teacher.Sallary * 2, ((Teacher)p6).Sallary); Assert.Equal(teacher.Id, ((Teacher)p6).Id); Assert.Equal(teacher.Classes[101], ((Teacher)p6).Classes[101]); Assert.Equal(teacher.Classes[102], ((Teacher)p6).Classes[102]); Assert.Equal(teacher.Classes[205], ((Teacher)p6).Classes[205]); }
internal override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeUByte((byte?)this.OutcomeCode, buffer); AmqpCodec.EncodeBinary(this.AdditionalData, buffer); }
public void AmqpCodecSingleValueTest() { byte[] workBuffer = new byte[2048]; ByteBuffer buffer; // boolean true AmqpCodec.EncodeBoolean(boolTrue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(boolTrueBin, 0, boolTrueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); bool?bv = AmqpCodec.DecodeBoolean(new ByteBuffer(new ArraySegment <byte>(boolTrueBin))); Assert.True(bv.Value, "Boolean value is not true."); // boolean false AmqpCodec.EncodeBoolean(boolFalse, buffer = new ByteBuffer(workBuffer)); EnsureEqual(boolFalseBin, 0, boolFalseBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); bv = AmqpCodec.DecodeBoolean(new ByteBuffer(new ArraySegment <byte>(boolFalseBin))); Assert.False(bv.Value, "Boolean value is not false."); // ubyte AmqpCodec.EncodeUByte(ubyteValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(ubyteValueBin, 0, ubyteValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); byte?bytev = AmqpCodec.DecodeUByte(new ByteBuffer(new ArraySegment <byte>(ubyteValueBin))); Assert.True(bytev == ubyteValue, "UByte value is not equal."); // ushort AmqpCodec.EncodeUShort(ushortValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(ushortValueBin, 0, ushortValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ushort?ushortv = AmqpCodec.DecodeUShort(new ByteBuffer(new ArraySegment <byte>(ushortValueBin))); Assert.True(ushortv == ushortValue, "UShort value is not equal."); // uint0 AmqpCodec.EncodeUInt(uint0Value, buffer = new ByteBuffer(workBuffer)); EnsureEqual(uint0ValueBin, 0, uint0ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); uint?uint0v = AmqpCodec.DecodeUInt(new ByteBuffer(new ArraySegment <byte>(uint0ValueBin))); Assert.True(uint0v == uint0Value, "UInt0 value is not equal."); // uint small AmqpCodec.EncodeUInt(uintSmallValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(uintSmallValueBin, 0, uintSmallValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); uint?uintSmallV = AmqpCodec.DecodeUInt(new ByteBuffer(new ArraySegment <byte>(uintSmallValueBin))); Assert.True(uintSmallV == uintSmallValue, "UIntSmall value is not equal."); // uint AmqpCodec.EncodeUInt(uintValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(uintValueBin, 0, uintValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); uint?uintv = AmqpCodec.DecodeUInt(new ByteBuffer(new ArraySegment <byte>(uintValueBin))); Assert.True(uintv == uintValue, "UInt value is not equal."); // ulong0 AmqpCodec.EncodeULong(ulong0Value, buffer = new ByteBuffer(workBuffer)); EnsureEqual(ulong0ValueBin, 0, ulong0ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ulong?ulong0v = AmqpCodec.DecodeULong(new ByteBuffer(new ArraySegment <byte>(ulong0ValueBin))); Assert.True(ulong0v == ulong0Value, "ULong0 value is not equal."); // ulong small AmqpCodec.EncodeULong(ulongSmallValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(ulongSmallValueBin, 0, ulongSmallValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ulong?ulongSmallV = AmqpCodec.DecodeULong(new ByteBuffer(new ArraySegment <byte>(ulongSmallValueBin))); Assert.True(ulongSmallV == ulongSmallValue, "ULong value is not equal."); // ulong AmqpCodec.EncodeULong(ulongValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(ulongValueBin, 0, ulongValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ulong?ulongv = AmqpCodec.DecodeULong(new ByteBuffer(new ArraySegment <byte>(ulongValueBin))); Assert.True(ulongv == ulongValue, "ULong value is not equal."); // byte AmqpCodec.EncodeByte(byteValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(byteValueBin, 0, byteValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); sbyte?sbytev = AmqpCodec.DecodeByte(new ByteBuffer(new ArraySegment <byte>(byteValueBin))); Assert.True(sbytev == byteValue, "Byte value is not equal."); // short AmqpCodec.EncodeShort(shortValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(shortValueBin, 0, shortValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); short?shortv = AmqpCodec.DecodeShort(new ByteBuffer(new ArraySegment <byte>(shortValueBin))); Assert.True(shortv == shortValue, "Short value is not equal."); // int small AmqpCodec.EncodeInt(intSmallValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(intSmallValueBin, 0, intSmallValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); int?intSmallV = AmqpCodec.DecodeInt(new ByteBuffer(new ArraySegment <byte>(intSmallValueBin))); Assert.True(intSmallV == intSmallValue, "Int small value is not equal."); // int AmqpCodec.EncodeInt(intValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(intValueBin, 0, intValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); int?intv = AmqpCodec.DecodeInt(new ByteBuffer(new ArraySegment <byte>(intValueBin))); Assert.True(intv == intValue, "Int value is not equal."); // long AmqpCodec.EncodeLong(longSmallValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(longSmallValueBin, 0, longSmallValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); long?longSmallV = AmqpCodec.DecodeLong(new ByteBuffer(new ArraySegment <byte>(longSmallValueBin))); Assert.True(longSmallV == longSmallValue, "Long small value is not equal."); // long AmqpCodec.EncodeLong(longValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(longValueBin, 0, longValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); long?longv = AmqpCodec.DecodeLong(new ByteBuffer(new ArraySegment <byte>(longValueBin))); Assert.True(longv == longValue, "Long value is not equal."); // float AmqpCodec.EncodeFloat(floatValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(floatValueBin, 0, floatValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); float?floatv = AmqpCodec.DecodeFloat(new ByteBuffer(new ArraySegment <byte>(floatValueBin))); Assert.True(floatv == floatValue, "Float value is not equal."); // double AmqpCodec.EncodeDouble(doubleValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(doubleValueBin, 0, doubleValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); double?doublev = AmqpCodec.DecodeDouble(new ByteBuffer(new ArraySegment <byte>(doubleValueBin))); Assert.True(doublev == doubleValue, "Double value is not equal."); //decimal decimal?dec32 = DecimalEncoding.Decode(new ByteBuffer(new ArraySegment <byte>(decimal32ValueBin)), FormatCode.Decimal32); Assert.True(dec32.Value == decimal32Value, "Decimal32 value is not equal"); decimal?dec64 = DecimalEncoding.Decode(new ByteBuffer(new ArraySegment <byte>(decimal64ValueBin)), FormatCode.Decimal64); Assert.True(dec64.Value == decimal64Value, "Decimal64 value is not equal"); decimal?dec128 = DecimalEncoding.Decode(new ByteBuffer(new ArraySegment <byte>(decimal128ValueBin)), FormatCode.Decimal128); Assert.True(dec128.Value == decimal128Value, "Decimal128 value is not equal"); // char AmqpCodec.EncodeChar(charValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(charValueBin, 0, charValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); char?charv = AmqpCodec.DecodeChar(new ByteBuffer(new ArraySegment <byte>(charValueBin))); Assert.True(charv == charValue, "Char value is not equal."); // timestamp AmqpCodec.EncodeTimeStamp(dtValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(dtValueBin, 0, dtValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); DateTime?dtv = AmqpCodec.DecodeTimeStamp(new ByteBuffer(new ArraySegment <byte>(dtValueBin))); Assert.True(dtv == dtValue.ToUniversalTime(), "UByte value is not equal."); // uuid AmqpCodec.EncodeUuid(uuidValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(uuidValueBin, 0, uuidValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); Guid?uuidv = AmqpCodec.DecodeUuid(new ByteBuffer(new ArraySegment <byte>(uuidValueBin))); Assert.True(uuidv == uuidValue, "Uuid value is not equal."); // binary 8 AmqpCodec.EncodeBinary(bin8Value, buffer = new ByteBuffer(workBuffer)); EnsureEqual(bin8ValueBin, 0, bin8ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ArraySegment <byte> bin8v = AmqpCodec.DecodeBinary(new ByteBuffer(new ArraySegment <byte>(bin8ValueBin))); EnsureEqual(bin8v.Array, bin8v.Offset, bin8v.Count, bin8Value.Array, bin8Value.Offset, bin8Value.Count); // binary 32 AmqpCodec.EncodeBinary(bin32Value, buffer = new ByteBuffer(workBuffer)); EnsureEqual(bin32ValueBin, 0, bin32ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); ArraySegment <byte> bin32v = AmqpCodec.DecodeBinary(new ByteBuffer(new ArraySegment <byte>(bin32ValueBin))); EnsureEqual(bin32v.Array, bin32v.Offset, bin32v.Count, bin32Value.Array, bin32Value.Offset, bin32Value.Count); // symbol 8 AmqpCodec.EncodeSymbol(strValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(sym8ValueBin, 0, sym8ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); AmqpSymbol symbol8v = AmqpCodec.DecodeSymbol(new ByteBuffer(new ArraySegment <byte>(sym8ValueBin))); Assert.True(symbol8v.Value == strValue, "Symbol8 string value is not equal."); // symbol 32 AmqpSymbol symbol32v = AmqpCodec.DecodeSymbol(new ByteBuffer(new ArraySegment <byte>(sym32ValueBin))); Assert.True(symbol32v.Value == strValue, "Symbol32 string value is not equal."); // string 8 UTF8 AmqpCodec.EncodeString(strValue, buffer = new ByteBuffer(workBuffer)); EnsureEqual(str8Utf8ValueBin, 0, str8Utf8ValueBin.Length, buffer.Buffer, buffer.Offset, buffer.Length); string str8Utf8 = AmqpCodec.DecodeString(new ByteBuffer(new ArraySegment <byte>(str8Utf8ValueBin))); Assert.True(str8Utf8 == strValue, "UTF8 string8 string value is not equal."); // string 32 UTF8 string str32Utf8 = AmqpCodec.DecodeString(new ByteBuffer(new ArraySegment <byte>(str32Utf8ValueBin))); Assert.True(str32Utf8 == strValue, "UTF8 string32 string value is not equal."); }
public void AmqpCodecMapTest() { byte[] workBuffer = new byte[4096]; ByteBuffer buffer = new ByteBuffer(workBuffer); string strBig = new string('A', 512); AmqpMap map = new AmqpMap(); map.Add(new MapKey("boolTrue"), boolTrue); map.Add(new MapKey("boolFalse"), boolFalse); map.Add(new MapKey("ubyte"), ubyteValue); map.Add(new MapKey("ushort"), ushortValue); map.Add(new MapKey("uint"), uintValue); map.Add(new MapKey("ulong"), ulongValue); map.Add(new MapKey("byte"), byteValue); map.Add(new MapKey("short"), shortValue); map.Add(new MapKey("int"), intValue); map.Add(new MapKey("long"), longValue); map.Add(new MapKey("null"), null); map.Add(new MapKey("float"), floatValue); map.Add(new MapKey("double"), doubleValue); map.Add(new MapKey("decimal32"), decimal32Value); map.Add(new MapKey("decimal64"), decimal64Value); map.Add(new MapKey("decimal128"), decimal128Value); map.Add(new MapKey("char"), charValue); map.Add(new MapKey("datetime"), dtValue); map.Add(new MapKey("uuid"), uuidValue); map.Add(new MapKey("binaryNull"), new ArraySegment <byte>()); map.Add(new MapKey("binary8"), bin8Value); map.Add(new MapKey("binary32"), bin32Value); map.Add(new MapKey("symbolNull"), new AmqpSymbol()); map.Add(new MapKey("symbol8"), new AmqpSymbol(strValue)); map.Add(new MapKey("symbol32"), new AmqpSymbol(strBig)); map.Add(new MapKey("string8"), strValue); map.Add(new MapKey("string32"), strBig); map.Add(new MapKey("described1"), described1); AmqpCodec.EncodeMap(map, buffer); // make sure the size written is correct (it has to be Map32) // the first byte is FormatCode.Map32 int mapSize = (int)AmqpBitConverter.ReadUInt(workBuffer, 1, 4); Assert.Equal(buffer.Length - 5, mapSize); AmqpMap decMap = AmqpCodec.DecodeMap(buffer); Assert.True(decMap[new MapKey("boolTrue")].Equals(true), "Boolean true expected."); Assert.True(decMap[new MapKey("boolFalse")].Equals(false), "Boolean false expected."); Assert.True(decMap[new MapKey("ubyte")].Equals(ubyteValue), "UByte value not equal."); Assert.True(decMap[new MapKey("ushort")].Equals(ushortValue), "UShort value not equal."); Assert.True(decMap[new MapKey("uint")].Equals(uintValue), "UInt value not equal."); Assert.True(decMap[new MapKey("ulong")].Equals(ulongValue), "ULong value not equal."); Assert.True(decMap[new MapKey("byte")].Equals(byteValue), "Byte value not equal."); Assert.True(decMap[new MapKey("short")].Equals(shortValue), "Short value not equal."); Assert.True(decMap[new MapKey("int")].Equals(intValue), "Int value not equal."); Assert.True(decMap[new MapKey("long")].Equals(longValue), "Long value not equal."); Assert.True(decMap[new MapKey("null")] == null, "Null object expected."); Assert.True(decMap[new MapKey("float")].Equals(floatValue), "Float value not equal."); Assert.True(decMap[new MapKey("double")].Equals(doubleValue), "Double value not equal."); Assert.True(decMap[new MapKey("decimal32")].Equals(decimal32Value), "Decimal32 value not equal."); Assert.True(decMap[new MapKey("decimal64")].Equals(decimal64Value), "Decimal64 value not equal."); Assert.True(decMap[new MapKey("decimal128")].Equals(decimal128Value), "Decimal128 value not equal."); Assert.True(decMap[new MapKey("char")].Equals(charValue), "Char value not equal."); Assert.True(decMap[new MapKey("datetime")].Equals(dtValue), "TimeStamp value not equal."); Assert.True(decMap[new MapKey("uuid")].Equals(uuidValue), "Uuid value not equal."); Assert.True(decMap[new MapKey("binaryNull")] == null, "Null binary expected."); ArraySegment <byte> bin8 = (ArraySegment <byte>)decMap[new MapKey("binary8")]; EnsureEqual(bin8.Array, bin8.Offset, bin8.Count, bin8Value.Array, bin8Value.Offset, bin8Value.Count); ArraySegment <byte> bin32 = (ArraySegment <byte>)decMap[new MapKey("binary32")]; EnsureEqual(bin32.Array, bin32.Offset, bin32.Count, bin32Value.Array, bin32Value.Offset, bin32Value.Count); Assert.True(decMap[new MapKey("symbolNull")] == null, "Null symbol expected."); AmqpSymbol symDecode = (AmqpSymbol)decMap[new MapKey("symbol8")]; Assert.True(symDecode.Equals(strValue), "AmqpSymbol value not equal."); symDecode = (AmqpSymbol)decMap[new MapKey("symbol32")]; Assert.True(symDecode.Equals(strBig), "AmqpSymbol value (big) not equal."); string strDecode = (string)decMap[new MapKey("string8")]; Assert.True(strDecode.Equals(strValue), "string value not equal."); strDecode = (string)decMap[new MapKey("string32")]; Assert.True(strDecode.Equals(strBig), "string value (big) not equal."); DescribedType described = (DescribedType)decMap[new MapKey("described1")]; Assert.True(described.Descriptor.Equals(described1.Descriptor), "Described value 1 descriptor is different"); Assert.True(described.Value.Equals(described1.Value), "Described value 1 value is different"); }
public override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeULong(new ulong?(this.id), buffer); }
protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeObject(this.GlobalId, buffer); }
protected override void DecodeValue(ByteBuffer buffer) { Value = AmqpCodec.DecodeObject <T>(buffer); }
public ReadOnlyMemory <byte> ArrayInt32Encode_MAA_1K() { ScratchByteBuffer.Reset(); AmqpCodec.EncodeArray(RandomInt32Array1K, ScratchByteBuffer); return(ScratchByteBuffer.Buffer.AsMemory(0, ScratchByteBuffer.WritePos)); }
protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeMultiple(this.SaslServerMechanisms, buffer); }
protected override int OnValueSize() { return(0 + AmqpCodec.GetSerializableEncodeSize(this.Error)); }
internal override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeBinary(this.TxnId, buffer); }
public override void DecodeValue(ByteBuffer buffer) { this.Value = AmqpCodec.DecodeObject(buffer); }
protected override int OnValueSize() { return(0 + AmqpCodec.GetMultipleEncodeSize <AmqpSymbol>(this.Capabilities)); }
public override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeBinary(this.id, buffer); }
public ReadOnlyMemory <byte> Bytes_Encode_MAA() { ScratchByteBuffer.Reset(); AmqpCodec.EncodeBinary(RandomBytes1MB, ScratchByteBuffer); return(ScratchByteBuffer.Buffer.AsMemory(0, ScratchByteBuffer.WritePos)); }
public override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeString(this.id, buffer); }
protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeString(this.Expression, buffer); AmqpCodec.EncodeInt(this.CompatibilityLevel, buffer); }
public override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeUuid(new Guid?(this.id), buffer); }
protected override int OnValueSize() { return(AmqpCodec.GetStringEncodeSize(this.Expression) + AmqpCodec.GetIntEncodeSize(this.CompatibilityLevel)); }
protected override int OnValueSize() { return(0 + AmqpCodec.GetObjectEncodeSize(this.GlobalId)); }
/// <summary> /// Encodes the fields into the buffer. /// </summary> /// <param name="buffer">The buffer to write.</param> protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeBinary(this.Response, buffer); }
public void AmqpCodecListTest() { byte[] workBuffer = new byte[4096]; ByteBuffer buffer = new ByteBuffer(workBuffer); string strBig = new string('A', 512); List <object> list = new List <object>(); list.Add(boolTrue); list.Add(boolFalse); list.Add(ubyteValue); list.Add(ushortValue); list.Add(uintValue); list.Add(ulongValue); list.Add(byteValue); list.Add(shortValue); list.Add(intValue); list.Add(longValue); list.Add(null); list.Add(floatValue); list.Add(doubleValue); list.Add(decimal32Value); list.Add(decimal64Value); list.Add(decimal128Value); list.Add(charValue); list.Add(dtValue); list.Add(uuidValue); list.Add(new ArraySegment <byte>()); list.Add(bin8Value); list.Add(bin32Value); list.Add(new AmqpSymbol()); list.Add(new AmqpSymbol(strValue)); list.Add(new AmqpSymbol(strBig)); list.Add(strValue); list.Add(strBig); list.Add(described1); list.Add(described2); list.Add(described3); list.Add(described4); AmqpCodec.EncodeList(list, buffer); // make sure the size written is correct (it has to be List32) // the first byte is FormatCode.List32 int listSize = (int)AmqpBitConverter.ReadUInt(workBuffer, 1, 4); Assert.Equal(buffer.Length - 5, listSize); IList decList = AmqpCodec.DecodeList(buffer); int index = 0; Assert.True(decList[index++].Equals(true), "Boolean true expected."); Assert.True(decList[index++].Equals(false), "Boolean false expected."); Assert.True(decList[index++].Equals(ubyteValue), "UByte value not equal."); Assert.True(decList[index++].Equals(ushortValue), "UShort value not equal."); Assert.True(decList[index++].Equals(uintValue), "UInt value not equal."); Assert.True(decList[index++].Equals(ulongValue), "ULong value not equal."); Assert.True(decList[index++].Equals(byteValue), "Byte value not equal."); Assert.True(decList[index++].Equals(shortValue), "Short value not equal."); Assert.True(decList[index++].Equals(intValue), "Int value not equal."); Assert.True(decList[index++].Equals(longValue), "Long value not equal."); Assert.True(decList[index++] == null, "Null object expected."); Assert.True(decList[index++].Equals(floatValue), "Float value not equal."); Assert.True(decList[index++].Equals(doubleValue), "Double value not equal."); Assert.True(decList[index++].Equals(decimal32Value), "Decimal32 value not equal."); Assert.True(decList[index++].Equals(decimal64Value), "Decimal64 value not equal."); Assert.True(decList[index++].Equals(decimal128Value), "Decimal128 value not equal."); Assert.True(decList[index++].Equals(charValue), "Char value not equal."); Assert.True(decList[index++].Equals(dtValue), "TimeStamp value not equal."); Assert.True(decList[index++].Equals(uuidValue), "Uuid value not equal."); Assert.True(decList[index++] == null, "Null binary expected."); ArraySegment <byte> bin8 = (ArraySegment <byte>)decList[index++]; EnsureEqual(bin8.Array, bin8.Offset, bin8.Count, bin8Value.Array, bin8Value.Offset, bin8Value.Count); ArraySegment <byte> bin32 = (ArraySegment <byte>)decList[index++]; EnsureEqual(bin32.Array, bin32.Offset, bin32.Count, bin32Value.Array, bin32Value.Offset, bin32Value.Count); Assert.True(decList[index++] == null, "Null symbol expected."); AmqpSymbol symDecode = (AmqpSymbol)decList[index++]; Assert.True(symDecode.Equals(strValue), "AmqpSymbol value not equal."); symDecode = (AmqpSymbol)decList[index++]; Assert.True(symDecode.Equals(strBig), "AmqpSymbol value (big) not equal."); string strDecode = (string)decList[index++]; Assert.True(strDecode.Equals(strValue), "string value not equal."); strDecode = (string)decList[index++]; Assert.True(strDecode.Equals(strBig), "string value (big) not equal."); DescribedType described = (DescribedType)decList[index++]; Assert.True(described.Descriptor.Equals(described1.Descriptor), "Described value 1 descriptor is different"); Assert.True(described.Value.Equals(described1.Value), "Described value 1 value is different"); described = (DescribedType)decList[index++]; Assert.True(described.Descriptor.Equals(described2.Descriptor), "Described value 2 descriptor is different"); Assert.True(described.Value.Equals(described2.Value), "Described value 2 value is different"); described = (DescribedType)decList[index++]; Assert.True(described.Descriptor.Equals(described3.Descriptor), "Described value 3 descriptor is different"); Assert.True(described.Value.Equals(described3.Value), "Described value 3 value is different"); described = (DescribedType)decList[index++]; EnsureEqual((DateTime)described4.Descriptor, (DateTime)described.Descriptor); EnsureEqual((IList)described.Value, (IList)described4.Value); }
protected override void OnDecode(ByteBuffer buffer, int count) { if (count-- > 0) { this.MessageId = MessageId.Decode(buffer); } if (count-- > 0) { this.UserId = AmqpCodec.DecodeBinary(buffer); } if (count-- > 0) { this.To = Address.Decode(buffer); } if (count-- > 0) { this.Subject = AmqpCodec.DecodeString(buffer); } if (count-- > 0) { this.ReplyTo = Address.Decode(buffer); } if (count-- > 0) { this.CorrelationId = MessageId.Decode(buffer); } if (count-- > 0) { this.ContentType = AmqpCodec.DecodeSymbol(buffer); } if (count-- > 0) { this.ContentEncoding = AmqpCodec.DecodeSymbol(buffer); } if (count-- > 0) { this.AbsoluteExpiryTime = AmqpCodec.DecodeTimeStamp(buffer); } if (count-- > 0) { this.CreationTime = AmqpCodec.DecodeTimeStamp(buffer); } if (count-- > 0) { this.GroupId = AmqpCodec.DecodeString(buffer); } if (count-- > 0) { this.GroupSequence = AmqpCodec.DecodeUInt(buffer); } if (count-- > 0) { this.ReplyToGroupId = AmqpCodec.DecodeString(buffer); } }
public void AmqpCodecFramingTypeTest() { byte[] workBuffer = new byte[1024 * 16]; ByteBuffer buffer = new ByteBuffer(workBuffer); // transport EncodeDescribedList(buffer, Open.Code, "my-container", "my-hostname", (uint)1000); EncodeDescribedList(buffer, Begin.Name, (ushort)100, (uint)200, (uint)300, (uint)400); EncodeDescribedList(buffer, Attach.Code, "my-link", (uint)100, false, null, null); EncodeDescribedList(buffer, Flow.Code, null, (uint)100, (uint)200, (uint)300, null, (uint)400); EncodeDescribedList(buffer, Transfer.Name, (uint)100, null, null, (uint)0); EncodeDescribedList(buffer, Disposition.Name, true, (uint)200); EncodeDescribedList(buffer, Detach.Code, (uint)300); EncodeDescribedList(buffer, End.Code, new object[0]); EncodeDescribedList(buffer, Close.Code, null, null, null, null, "this string should be ignored"); EncodeDescribedList(buffer, Error.Name, AmqpErrorCode.IllegalState); EncodeDescribedList(buffer, Received.Code, (uint)0, (ulong)12); EncodeDescribedList(buffer, Accepted.Name, "this string should be ignored."); EncodeDescribedList(buffer, Rejected.Code, null, "this string should be ignored", 100); EncodeDescribedList(buffer, Released.Code, new object[0]); EncodeDescribedList(buffer, Modified.Code, true, false, new AmqpMap(), null); EncodeDescribedList(buffer, Source.Name, "my-address"); EncodeDescribedList(buffer, Target.Code, "my-target", (uint)TerminusDurability.Configuration, TerminusExpiryPolicy.LinkDetach, (uint)100); EncodeDescribedList(buffer, DeleteOnClose.Code, null); EncodeDescribedList(buffer, DeleteOnNoLinks.Name, null); EncodeDescribedList(buffer, DeleteOnNoMessages.Name, null, null); EncodeDescribedList(buffer, DeleteOnNoLinksOrMessages.Code, new object[0]); // transaction EncodeDescribedList(buffer, Coordinator.Code, null); EncodeDescribedList(buffer, Declare.Name, null, null); EncodeDescribedList(buffer, Discharge.Name, bin8Value, false, null); EncodeDescribedList(buffer, Declared.Code, bin8Value); EncodeDescribedList(buffer, TransactionalState.Code, bin8Value, null, null); // sasl EncodeDescribedList(buffer, SaslMechanisms.Code, new AmqpSymbol[] { "plain", "kerb" }); EncodeDescribedList(buffer, SaslInit.Name, (AmqpSymbol)"plain", bin8Value, "sasl-host", null, 100); EncodeDescribedList(buffer, SaslChallenge.Name, bin8Value, (AmqpSymbol)"this symbol should be ignored"); EncodeDescribedList(buffer, SaslResponse.Code, bin8Value); EncodeDescribedList(buffer, SaslOutcome.Code, (byte)SaslCode.SysPerm); // transport AmqpCodec.DecodeKnownType <Open>(buffer); AmqpCodec.DecodeKnownType <Begin>(buffer); AmqpCodec.DecodeKnownType <Attach>(buffer); AmqpCodec.DecodeKnownType <Flow>(buffer); AmqpCodec.DecodeKnownType <Transfer>(buffer); AmqpCodec.DecodeKnownType <Disposition>(buffer); AmqpCodec.DecodeKnownType <Detach>(buffer); AmqpCodec.DecodeKnownType <End>(buffer); AmqpCodec.DecodeKnownType <Close>(buffer); AmqpCodec.DecodeKnownType <Error>(buffer); AmqpCodec.DecodeKnownType <Received>(buffer); AmqpCodec.DecodeKnownType <Accepted>(buffer); AmqpCodec.DecodeKnownType <Rejected>(buffer); AmqpCodec.DecodeKnownType <Released>(buffer); AmqpCodec.DecodeKnownType <Modified>(buffer); AmqpCodec.DecodeKnownType <Source>(buffer); AmqpCodec.DecodeKnownType <Target>(buffer); AmqpCodec.DecodeKnownType <DeleteOnClose>(buffer); AmqpCodec.DecodeKnownType <DeleteOnNoLinks>(buffer); AmqpCodec.DecodeKnownType <DeleteOnNoMessages>(buffer); AmqpCodec.DecodeKnownType <DeleteOnNoLinksOrMessages>(buffer); //transaction AmqpCodec.DecodeKnownType <Coordinator>(buffer); AmqpCodec.DecodeKnownType <Declare>(buffer); AmqpCodec.DecodeKnownType <Discharge>(buffer); AmqpCodec.DecodeKnownType <Declared>(buffer); AmqpCodec.DecodeKnownType <TransactionalState>(buffer); //sasl AmqpCodec.DecodeKnownType <SaslMechanisms>(buffer); AmqpCodec.DecodeKnownType <SaslInit>(buffer); AmqpCodec.DecodeKnownType <SaslChallenge>(buffer); AmqpCodec.DecodeKnownType <SaslResponse>(buffer); AmqpCodec.DecodeKnownType <SaslOutcome>(buffer); Assert.True(buffer.Length == 0, "All bytes in the buffer should be consumed"); }
internal override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeString(this.address, buffer); }
/// <summary> /// Encodes the fields into the buffer. /// </summary> /// <param name="buffer">The buffer to write.</param> protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeUInt(this.SectionNumber, buffer); AmqpCodec.EncodeULong(this.SectionOffset, buffer); }
protected override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeSerializable(this.Error, buffer); }
internal override void OnEncode(ByteBuffer buffer) { AmqpCodec.EncodeSymbol(this.Condition, buffer); AmqpCodec.EncodeString(this.Description, buffer); AmqpCodec.EncodeMap(this.Info, buffer); }
protected override void OnDecode(ByteBuffer buffer, int count) { int num = count; count = num - 1; if (num > 0) { this.NextIncomingId = AmqpCodec.DecodeUInt(buffer); } int num1 = count; count = num1 - 1; if (num1 > 0) { this.IncomingWindow = AmqpCodec.DecodeUInt(buffer); } int num2 = count; count = num2 - 1; if (num2 > 0) { this.NextOutgoingId = AmqpCodec.DecodeUInt(buffer); } int num3 = count; count = num3 - 1; if (num3 > 0) { this.OutgoingWindow = AmqpCodec.DecodeUInt(buffer); } int num4 = count; count = num4 - 1; if (num4 > 0) { base.Handle = AmqpCodec.DecodeUInt(buffer); } int num5 = count; count = num5 - 1; if (num5 > 0) { this.DeliveryCount = AmqpCodec.DecodeUInt(buffer); } int num6 = count; count = num6 - 1; if (num6 > 0) { this.LinkCredit = AmqpCodec.DecodeUInt(buffer); } int num7 = count; count = num7 - 1; if (num7 > 0) { this.Available = AmqpCodec.DecodeUInt(buffer); } int num8 = count; count = num8 - 1; if (num8 > 0) { this.Drain = AmqpCodec.DecodeBoolean(buffer); } int num9 = count; count = num9 - 1; if (num9 > 0) { this.Echo = AmqpCodec.DecodeBoolean(buffer); } int num10 = count; count = num10 - 1; if (num10 > 0) { this.Properties = AmqpCodec.DecodeMap <Microsoft.ServiceBus.Messaging.Amqp.Framing.Fields>(buffer); } }