LengthFieldBasedFrameDecoder

hezjing hezjing at gmail.com
Sun Sep 20 08:12:05 EDT 2009


Hi Mike
Hmmm ... do you mean the example of the frame like the following?

<-- HEADER 20 bytes --><-- PAYLOAD 14 bytes -->
+-------+---------+----+-----------------------+
|       | Length  |    | Payload               |
|       | 0x000C  |    |                       |
+-------+---------+----+-----------------------+

Total frame size is 34 bytes.

<-- HEADER 20 bytes --><-- PAYLOAD 100 bytes -->
+-------+--------+-----+------------------------+
|       | Length |     | Payload                |
|       | 0x0064 |     |                        |
+-------+--------+-----+------------------------+

Total frame size is 120 bytes.



On Sun, Sep 20, 2009 at 1:41 AM, Mike McGrady
<mmcgrady at topiatechnology.com>wrote:

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


-- 

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


More information about the netty-users mailing list