LengthFieldBasedFrameDecoder

Mike McGrady mmcgrady at topiatechnology.com
Sat Sep 19 13:41:25 EDT 2009


Could you include an example write with this?  The two together, I  
suspect, will be most helpful to many people, including me.

Mike

On Sep 19, 2009, at 8:11 AM, hezjing wrote:

> 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
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users

Mike McGrady
Principal Investigator AF081-028 AFRL SBIR
Senior Engineer
Topia Technology, Inc.
1.253.720.3365
mmcgrady at topiatechnology.com









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


More information about the netty-users mailing list