ObjectOutputStream oout = new CompactObjectOutputStream(bout);
oout.writeObject(obj);
oout.flush();
oout.close();
ChannelBuffer buffer = bout.buffer();
int objectSize = buffer.readableBytes();
writeInt(objectSize);
buffer.getBytes(0, this, objectSize);
}