I have one or more byte buffers containing parts of a single message. Now I want to read this post, but I do not want to copy N ByteBuffer to one. My parser expects one ByteBuffer to receive the full message, but my message is split into N ByteBuffers.
Is there a way to combine these N ByteBuffers into one without byte copy? I imagined some intellectual implementation of the abstract ByteBuffer class, which is backed up by these ByteBuffer under the hood and just sets pointers and delegates to the correct ByteBuffer.
If you are wondering why I need this, check the protocol below from BM & F / Bovespa. They break the message into pieces, and they can fail in different packets, in other words, the same sequence of messages can come in several packets, each of which has a piece of message. I cannot write sequentially the same ByteBuffer, because these pieces may be out of order. :(
Did I miss something smarter here? There seems to be no way to write the same ByteBuffer sequentially, given this chunk protocol below :(


source share