@ChannelHandler.Sharable public class ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf>
BEFORE ENCODE (300 bytes) AFTER ENCODE (302 bytes)
+---------------+ +--------+---------------+
| Protobuf Data |-------------->| Length | Protobuf Data |
| (300 bytes) | | 0xAC02 | (300 bytes) |
+---------------+ +--------+---------------+
*
CodedOutputStream
, CodedOutputByteBufferNano
ChannelHandler.Sharable
Constructor and Description |
---|
ProtobufVarint32LengthFieldPrepender() |
Modifier and Type | Method and Description |
---|---|
protected void |
encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
将消息编码为 ByteBuf 。
|
acceptOutboundMessage, allocateBuffer, isPreferDirect, write
bind, close, connect, deregister, disconnect, flush, read
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws java.lang.Exception
MessageToByteEncoder
ByteBuf
。
这个方法将被编码器处理的每个书面信息调用。
encode
MessageToByteEncoder<ByteBuf>
ctx
- 这是MessageToByteEncoder
所属的ChannelHandlerContext
msg
- 要编码的消息
out
- 编码消息将写入其中的ByteBuf
java.lang.Exception
- 发生错误时抛出
Copyright © 2008–2018 The Netty Project. All rights reserved.