Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to create a ByteBuffer from an array of bytes?

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

xinchen10commented, Sep 10, 2021

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.

BOLT04commented, Sep 10, 2021

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert ByteBuffer to byte array java [duplicate]
ByteBuffer exposes the bulk get(byte[]) method which transfers bytes from the buffer into the array. You'll need to instantiate an array of ...
Read more >
ByteBuffer array() method in Java with Examples
The array() method of java.nio.ByteBuffer class is used to return the byte array that backs the taken buffer. Modifications to this buffer's ...
Read more >
Guide to ByteBuffer
Conceptually, the ByteBuffer class is a byte array wrapped inside an object. It provides lots of convenient methods to facilitate reading or ...
Read more >
What is the ByteBuffer array() method in Java?
In Java, the array() method of the ByteBuffer class returns the array that backs a provided ByteBuffer object. The process is illustrated below....
Read more >
Difference between ByteBuffer vs byte array in Java ...
ByteBuffer has a unique capability to pass a subset of a byte buffer as a value without copying the bytes, by instantiating a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found