Top Description Constructors Methods
io.netty.handler.codec.protobuf

public Class ProtobufEncoder

extends MessageToMessageEncoder<MessageLiteOrBuilder>
Class Inheritance
Annotations
@Sharable
Imports
com.google.protobuf.Message, .MessageLite, .MessageLiteOrBuilder, io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandler.Sharable, .ChannelHandlerContext, .ChannelPipeline, io.netty.handler.codec.LengthFieldBasedFrameDecoder, .LengthFieldPrepender, .MessageToMessageEncoder, java.util.List

Encodes the requested Google Protocol Buffers Message and MessageLite into a ByteBuf. A typical setup for TCP/IP would be:
ChannelPipeline pipeline = ...;

// Decoders
pipeline.addLast("frameDecoder",
                 new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
pipeline.addLast("protobufDecoder",
                 new ProtobufDecoder(MyMessage.getDefaultInstance()));

// Encoder
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
and then you can use a 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);
}

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
encode(ChannelHandlerContext ctx, MessageLiteOrBuilder
the message to encode to an other one
msg
,
List<Object>
the List into which the encoded msg should be added needs to do some kind of aggregation
out
)

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other.
Inherited from io.netty.handler.codec.MessageToMessageEncoder:
acceptOutboundMessagewrite

Constructor Detail

ProtobufEncoderback to summary
public ProtobufEncoder()

Method Detail

encodeback to summary
protected void encode(ChannelHandlerContext ctx, MessageLiteOrBuilder msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Doc from io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to

msg:MessageLiteOrBuilder

the message to encode to an other one

out:List<Object>

the List into which the encoded msg should be added needs to do some kind of aggregation

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs