Hi all,

There is a problem with using slice() along with the CumulativeProtocolDecoder.

The problem is that the CPD does a compact() when has completed the attempt to decode the buffer.

Consider the following case, where you have a buffer like this:

XXX | YYY | ZZ

i.e. we have two protocol messages (XXX and YYY in the diagram) followed by a partial message. We decode those and are left with the partial protocol message (ZZ in the diagram) that we cannot currently decode.

The CPD compacts the buffer so it looks like this:

ZZ

which means that if we have a slice() for XXX that protocol message is now corrupt.

I am looking at a fix for this so that it allocates and copies into a new buffer rather than compacting. I suppose if you are not using slice() that will be a bit slower than compacting but the above case (and hence the case where you need to allocate and copy) is relatively uncommon.

One unrelated question I had is this - when you allocate a ByteBuffer why does it not set the capacity? i.e. if I allocate a buffer of say 600 bytes by calling ByteBuffer.allocate(600) then I get a buffer back from the pool of size 1024 (which is fine) but it does not set the capacity to 600 (which is what you would typically expect).

Thanks,

Robert

This communication is for informational purposes only. It is not intended
as an offer or solicitation for the purchase or sale of any financial
instrument or as an official confirmation of any transaction. All market prices,
data and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

Reply via email to