David Gordon
David Gordon

Reputation: 21

Little-endian support in Netty 4

The New & Noteworthy docs for 4 state that support for -ness has changed significantly, going on to show the use of ByteBuf.order(). Whilst that's useful for localised use within channel handlers, I would like for the whole downstream pipeline to use little-endian buffers.

The upstream handler LengthFieldBasedFrameDecoder takes a constructor argument for byte order, but the downstream handler LengthFieldPrepender does not. It appears that the support for configuration-driven replacement of buffer factories has gone from Netty 4, so how should I arrive at a complete little-endian downstream pipeline?

Upvotes: 2

Views: 915

Answers (1)

Tom Lee
Tom Lee

Reputation: 1

I did this, though it feels awfully hacky:

https://gist.github.com/thomaslee/7871444

If you wire this up in your pipeline after your LengthFieldPrepender is run, this will rewrite the (big endian) length field using little endian byte ordering.

Probably more efficient to just write the length in little endian yourself after measuring the length of in & dropping LengthFieldPrepender entirely rather than adding another step to the pipeline but this code has been lazily copied & I can attest to it working. :)

I too would love to know if there's a better solution beyond hand-rolling this stuff in 4.x.

Upvotes: 0

Related Questions