I am developing an application that uses the protocol buffer as a serializer . My application will be a client to a server. The requirement is that before sending the protobuf data I have to prepend the size of the protobuf data with 4 bytes. I am using Netty as my socket library. I have used the in-built protocolbuffer encoder and decoder of netty but I am still not getting the right result. This is the code I am running: Pipeline code
public class SmpPipelineFactory implements ChannelPipelineFactory {
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
*
*/
public SmpPipelineFactory() {
}
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = pipeline();
// Add Decoders
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
//p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
p.addLast("protobufDecoder", new ProtobufDecoder(Pdu.getDefaultInstance()));
// Add encoders
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
//p.addLast("frameEncoder", new LengthFieldPrepender(4));
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast("handler", new SmpChannelConnector());
return p;
}
}
Any help will help Thank you.