return serialize(message).remaining();
}
private ByteBuffer serialize(OUT message) {
if (message != lastObject) {
ByteBufferOutputStream ebbosa = new ByteBufferOutputStream();
ebbosa.setElastic(true);
try {
ObjectOutputStream oos = new ObjectOutputStream(ebbosa);
oos.writeObject(message);
oos.close();
lastObject = message;
lastSerialized = ebbosa.getByteBuffer();
} catch (IOException e) {
throw new IllegalStateException("Serialization exception", e);
}
}
return lastSerialized;