Amqp Value should be encoded properly when value was not initialized (#364)

* Amqp Value should be encoded properly when value was not initialized

* Copy the valueBuffer into the encoding buffer instead of decoding it eagerly

* do not use pattern matching for casting
This commit is contained in:
Havret 2019-07-18 20:55:57 +02:00 коммит произвёл Xin Chen
Родитель abf0504cc9
Коммит f0ca0ddd69
2 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -83,10 +83,14 @@ namespace Amqp.Framing
internal override void EncodeValue(ByteBuffer buffer)
{
var byteBuffer = this.value as ByteBuffer;
if (byteBuffer != null)
if (this.value is ByteBuffer)
{
Encoder.WriteBinaryBuffer(buffer, byteBuffer);
}
else if (this.valueBuffer != null && !this.valueDecoded)
{
AmqpBitConverter.WriteBytes(buffer, this.valueBuffer.Buffer, this.valueBuffer.Offset, this.valueBuffer.Length);
}
else
{
this.WriteValue(buffer, this.value);

Просмотреть файл

@ -1091,6 +1091,26 @@ namespace Test.Amqp
}
#endif
[TestMethod]
public void EncodeDecodeMessageWithAmqpValueTest()
{
string name = "EncodeDecodeMessageWithAmqpValueTest";
Queue<Message> messages = new Queue<Message>();
messages.Enqueue(new Message("test") { Properties = new Properties() { MessageId = name } });
var source = new TestMessageSource(messages);
this.host.RegisterMessageSource(name, source);
var connection = new Connection(Address);
var session = new Session(connection);
var receiver = new ReceiverLink(session, "receiver0", name);
Message message = receiver.Receive();
Message copy = Message.Decode(message.Encode());
Assert.AreEqual((message.BodySection as AmqpValue).Value, (copy.BodySection as AmqpValue).Value);
}
public static X509Certificate2 GetCertificate(StoreLocation storeLocation, StoreName storeName, string certFindValue)
{
X509Store store = new X509Store(storeName, storeLocation);