MessageNano into a
ByteBuf. 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", newProtobufDecoderNano(MyMessage.getDefaultInstance())); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("protobufEncoder", newProtobufEncoderNano());
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);
}
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | encode(ChannelHandlerContext
the ctx, MessageNano ChannelHandlerContext which this MessageToMessageEncoder belongs tothe message to encode to an other one msg, List<Object> the out)List into which the encoded msg should be added
needs to do some kind of aggregationImplements abstract io. |
| ProtobufEncoderNano | back to summary |
|---|---|
| public ProtobufEncoderNano() | |
| encode | back to summary |
|---|---|
| protected void encode(ChannelHandlerContext ctx, MessageNano msg, List<Object> out) throws Exception Implements abstract io. Doc from io. Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.
| |