Reputation: 53
I need to create channelbuffers in Netty in little-endian byte format by default, and to what I understand I use this piece of code.
bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN));
However when I created new channel buffers, they are big-endian, and thus I must make them little-endian manually.
Is there a way to make all channel buffers be little-endian by default?
Thank you!
EDIT:
I'm creating buffers like such:
ChannelBuffer opcodeBuffer = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 4);
If I create them like this
ChannelBuffer opcodeBuffer = ChannelBuffers.buffer(4);
They are not little-endian
Upvotes: 0
Views: 1643
Reputation: 2976
The setting that you are using is for configuring the buffers created by Channel
objects in your app. This means that every backing buffer created by Netty will be little endian.
ChannelBuffers
is a static helper class which cannot use the configuration from the bootstrap. If you check the docs, you can see that the methods which don't take a ByteOrder
say that they are making big-endian buffers explicitly.
So, if you are making the buffers manually, make sure to use the right endianness. Alternatively, you can use one of the ChannelBufferFactory
implementations in your code to be able to switch easily (if needed).
Upvotes: 2