SBE / DirectBuffer stupid question

280 views
Skip to first unread message

Andre Mermegas

unread,
Nov 10, 2015, 11:02:17 AM11/10/15
to mechanical-sympathy
Hi All,

apologies in advance for a stupid API question..

But, how does one go from:
ByteBuffer bb = ByteBuffer.allocateDirect(1024);
UnsafeBuffer encodeBuffer = new UnsafeBuffer(bb)
;
...encoder.wrap(.....)....etc...

to byte[] ?

I've tried a couple things but no luck.
encodeBuffer.byteArray(); only works for heap based buffers

thanks!

Michael Barker

unread,
Nov 10, 2015, 2:13:31 PM11/10/15
to mechanica...@googlegroups.com
You can't without a copy.

byte[] data = new byte[encodeBuffer.capacity()]
encodeBuffer.getBytes(0, data);

Mike.

--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Thompson

unread,
Nov 11, 2015, 6:20:40 AM11/11/15
to mechanica...@googlegroups.com
You can start with a byte[] and encode directly into that.

byte[] bytes = new byte[LENGTH];
UnsafeBuffer encodeBuffer = new UnsafeBuffer(bytes);

On 10 November 2015 at 16:02, Andre Mermegas <and...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages