如何设置LengthFieldBasedFrameDecoder类中提到的长度调整字节

时间:2015-07-05 16:21:50

标签: netty

LengthFieldBasedFrameDecoder的文档中,它允许用户解码标题字段Header 1。那么哪个编码器类允许用户定义这样的头字段?

* This is an advanced example that shows the case where there is an extra
 * header between the length field and the message body.  You have to specify a
 * positive <tt>lengthAdjustment</tt> so that the decoder counts the extra
 * header into the frame length calculation.
 * <pre>
 * lengthFieldOffset   = 0
 * lengthFieldLength   = 3
 * <b>lengthAdjustment</b>    = <b>2</b> (= the length of Header 1)
 * initialBytesToStrip = 0
 *
 * BEFORE DECODE (17 bytes)                      AFTER DECODE (17 bytes)
 * +----------+----------+----------------+      +----------+----------+----------------+
 * |  Length  | Header 1 | Actual Content |----->|  Length  | Header 1 | Actual Content |
 * | 0x00000C |  0xCAFE  | "HELLO, WORLD" |      | 0x00000C |  0xCAFE  | "HELLO, WORLD" |
 * +----------+----------+----------------+      +----------+----------+----------------+

1 个答案:

答案 0 :(得分:0)

Netty本身并不包含这样的编码器,但您应该能够轻松编写自己的编码器,并在将其写入管道之前将字节写入ByteBuf。