[Question] How to create a ByteBuffer from an array of bytes?
See original GitHub issueHi everyone 👋,
I’m having some trouble getting an instance of Amqp.Message
when receiving a message from a AMQP broker (RabbitMQ in this case). All I have in the receiving end is an array of bytes, here is a code snippet:
byte[] body = //something...
Amqp.Message message = Amqp.Message.Decode(new ByteBuffer(body, 0, body.Length, body.Length));
This results in this error: System.InvalidOperationException: 'buffer too small'
.
I’ve also tried doing Message.Decode(new ByteBuffer(body, 0, 0, body.Length))
instead, but I get a System.NullReferenceException
in another line of code since all fields in the Amqp.Message
are null
. For further context on my use case, I’m using CloudNative.CloudEvents
and CloudNative.CloudEvents.Amqp
which uses AMQP.Net Lite, so I’m trying to get an Amqp.Message
in order to get a CloudEvent instance: CloudEvent decodedMessage = message.ToCloudEvent(new JsonEventFormatter());
Any help is much appreciated, Thank you!
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
That is fine if it is not too much work for you. Since you have it in code, you could also encode it as BASE64 string and post the string here.
@xinchen10 thank you, it works with
ReadOnlyMemory
👍. Not sure why it wasn’t working with the snippet I sent before for decoding, but your explanation makes sense. I’ll close this issue since it’s now resolved, thanks again for all the help 😃