Buffer endianness?

115 views
Skip to first unread message

Hoobajoob

unread,
Oct 22, 2015, 3:06:59 PM10/22/15
to vert.x
I can't seem to find it documented anywhere, but am I correct in assuming that the vertx Buffer classes are big-endian?

I need to interoperate with a little-endian service that sends and receives short-ish messages that include integers of various sizes. Streaming isn't really applicable or necessary in these exchanges.

For now, I'm guessing I'll use java.nio.ByteBuffer in little-endian mode, and use it to convert to byte arrays for use with vertx's Buffer class.

Any other suggestions?

jordan.h...@gmail.com

unread,
Oct 22, 2015, 9:21:01 PM10/22/15
to ve...@googlegroups.com
Netty ByteBufs are indeed big endian by default, but they can be swapped. However, Vert.x only exposes the default byte order. I suspect you can handle this by calling getByteBuf() on a Buffer and then swap the ByteBuf (which creates a new ByteBuf object) and then wrap it in another Buffer if you need to pass it to a Vert.x API by using BufferFactoryImpl to wrap the swapped ByteBuf. Something like:

Buffer littleBuffer = new BufferFactoryImpl().buffer(bigBuffer.getByteBuf().order(ByteOrder.LITTLE_ENDIAN));
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/5c7986a7-f757-45d6-8efb-add005d99a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages