Marshaller marshaller = provider.getMarshaller(ctx);
ChannelBufferByteOutput output = new ChannelBufferByteOutput(
ctx.getChannel().getConfig().getBufferFactory(), estimatedLength);
output.getBuffer().writeBytes(LENGTH_PLACEHOLDER);
marshaller.start(output);
marshaller.writeObject(msg);
marshaller.finish();
marshaller.close();
ChannelBuffer encoded = output.getBuffer();
encoded.setInt(0, encoded.writerIndex() - 4);