I would use the ByteBuffer.wrap () method. By taking a close look at the Cisco implementation that Mr. Dean Hiller published earlier, you can replace put () with getWriteBuffer (), which will return you a ByteBuffer, which wraps the part in a buffer that it can write.
The same logic can be applied to the reading part.
The advantage would be that it would not have compactness, which could be expensive depending on the number of bytes available in the ByteBuffer, by bundling the parsing logic: you can get the first part of your message for ByteBuffer, wraps the last area of ββthe lying at the core of the circular buffer. To get the second part of your message, another reading is required to get an array of bytes at the beginning of the circular buffer wrapped in another ByteBuffer.
Pierre-luc bertrand
source share