> hezjing [mailto:[email protected]] wrote:
>
> Hi

Hi!

> I'm trying to implement an UDP message that has a fixed 6 byte of
> header,
> where the 3rd and 4th byte are the size of the message payload.

Ok, its common to have a fixed size header.

> CumulativeProtocolDecoder is the choice since the header's size fixed,
> and
> there is a payload length information (correct?).

The CumulativeProtocolDecoder is always a good idea. ;-)

> I will have to first read the 6 bytes header, and continue to read the
> subsequent bytes as specified by the payload size.
>
> For example, the following is the IoBuffer printed in doDecode():
>
> HeapBuffer[pos=0 lim=20 cap=20: 0E 01 00 00 00 DB 00 00 00 00 00 00 00
> 00 00
> 00...]
>
>
> The IoBuffer has the limit() , capacity()  and remaining() of 20 bytes.

The capacity is the maximum number of bytes the buffer can take, without 
copying internal buffers.
The limit defines up to which position data was filled to the buffer.
The remaining defines how much bytes you can read before you reach limit
Or to say it with signs:
pos <= limit <= capacity
remaining = limit-pos

> The question is, how do we know the header is ready to be parsed?

"if (buffer.remaining() >= 6)" should work for you

hth

btw: Please use the user ML as you are having problems using mina for your 
development.
This ml is intended for discussions for further development of mina itself.

regards

Steve

Reply via email to