ByteBuf into a
Google Protocol Buffers
Message and MessageLite. Please note that this decoder must
be used with a proper ByteToMessageDecoder such as ProtobufVarint32FrameDecoder
or LengthFieldBasedFrameDecoder if you are using a stream-based
transport such as TCP/IP. A typical setup for TCP/IP would be:
and then you can use aChannelPipelinepipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4)); pipeline.addLast("protobufDecoder", newProtobufDecoder(MyMessage.getDefaultInstance())); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("protobufEncoder", newProtobufEncoder());
MyMessage instead of a ByteBuf
as a message:
void channelRead(ChannelHandlerContext ctx, Object msg) {
MyMessage req = (MyMessage) msg;
MyMessage res = MyMessage.newBuilder().setText(
"Did you say '" + req.getText() + "'?").build();
ch.write(res);
}
| Modifier and Type | Field and Description |
|---|---|
| private final ExtensionRegistryLite | |
| private static final boolean | |
| private final MessageLite |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | decode(ChannelHandlerContext
the ctx, ByteBuf ChannelHandlerContext which this MessageToMessageDecoder belongs tothe message to decode to an other one msg, List<Object> the out)List to which decoded messages should be addedImplements abstract io. |
| extensionRegistry | back to summary |
|---|---|
| private final ExtensionRegistryLite extensionRegistry | |
| HAS_PARSER | back to summary |
|---|---|
| private static final boolean HAS_PARSER | |
| prototype | back to summary |
|---|---|
| private final MessageLite prototype | |
| ProtobufDecoder | back to summary |
|---|---|
| public ProtobufDecoder(MessageLite prototype) Creates a new instance. | |
| ProtobufDecoder | back to summary |
|---|---|
| public ProtobufDecoder(MessageLite prototype, ExtensionRegistry extensionRegistry) | |
| ProtobufDecoder | back to summary |
|---|---|
| public ProtobufDecoder(MessageLite prototype, ExtensionRegistryLite extensionRegistry) | |
| decode | back to summary |
|---|---|
| protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception Implements abstract io. Doc from io. Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.
| |