protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object message) throws Exception {
if (message instanceof SyncMessage) {
ChannelBuffer buf = new DynamicChannelBuffer(512);
ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(os));
((SyncMessage) message).write(thriftProtocol);
ChannelBuffer len = ChannelBuffers.buffer(4);
len.writeInt(buf.readableBytes());
return ChannelBuffers.wrappedBuffer(len, buf);