LengthFieldBasedFrameDecoder

hezjing hezjing at gmail.com
Sat Sep 19 11:11:41 EDT 2009


Hi

To close this thread, my solution is to extends FrameDecoder like the
following code:

@ChannelPipelineCoverage("all")
public class MyFrameDecoder extends FrameDecoder {

    @Override
    protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buf) throws Exception {
        // the length field is at 3rd and 4th octet
        if (buf.readableBytes() < 4) {
            return null;
        }
        // The length field is in the buffer.
        buf.markReaderIndex();
        ...
        // Read the length field (the payload size)
        int length = buf.readUnsignedShort();
        // The actual frame size is header (20) + payload size
        length += 20;
        buf.resetReaderIndex();
        if (buf.readableBytes() < length) {
            return null;
        }
        ChannelBuffer frame = buf.readBytes(length);
        return frame;
    }
}


Thank you!


On Thu, Sep 10, 2009 at 9:23 PM, hezjing <hezjing at gmail.com> wrote:

> Hi
> I have a message containing a fixed length header of 20 bytes, followed by
> a payload of variable length.
> The header contains a 2 bytes length field, indicating the length of the
> payload (excluding the header).
>
> For example if the message has 10 bytes payload, then the entire frame
> length is 30 bytes (20 bytes header + 10 bytes of payload),
> and the length field is 10.
>
> May I know what is the parameter to create LengthFieldBasedFrameDecoder?
>
>
> Thank you!
>
>
> --
>
> Hez
>



-- 

Hez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20090919/b0c21e2a/attachment.html 


More information about the netty-users mailing list