public void Can_Decode_And_Assign_NullableInt_Without_Boxing_Using_Generic_DecodeObject() { // write to buffer var buffer = new ByteBuffer(1024, true); int value = randNum.Next(0, 1000); Encoder.WriteInt(buffer, value, false); // compile lambda expression var compiled = CompileGenericPropertyDecodeExpression(typeof(TestCompositeClass), "NullableIntValue"); // execute var instance = new TestCompositeClass(); var formatCode = AmqpCodec.DecodeFormatCode(buffer); compiled(instance, buffer, formatCode); Assert.AreEqual(value, instance.NullableIntValue); }
protected override void DecodeValue(ByteBuffer buffer) { var formatCode = AmqpCodec.DecodeFormatCode(buffer); if (formatCode == FormatCode.Null) { return; // nothing to decode } int size; int count; if (formatCode == FormatCode.List0) { size = count = 0; } else if (formatCode == FormatCode.List8) { size = AmqpBitConverter.ReadUByte(buffer); count = AmqpBitConverter.ReadUByte(buffer); } else if (formatCode == FormatCode.List32) { size = (int)AmqpBitConverter.ReadUInt(buffer); count = (int)AmqpBitConverter.ReadUInt(buffer); } else { throw new AmqpException(ErrorCode.DecodeError, $"The format code '{formatCode}' at frame buffer offset '{buffer.ReadOffset}' is invalid."); } var thisType = GetType(); for (int i = 0; i < count; i++) { var itemFormatCode = AmqpCodec.DecodeFormatCode(buffer); if (itemFormatCode == FormatCode.Null) { continue; // null value, ignore and continue } GetDecoderDelegate(thisType, i)(this, buffer, itemFormatCode); } }