if (!(element instanceof MessageEvent)) {
context.sendDownstream(element);
return;
}
MessageEvent e = (MessageEvent) element;
ByteArrayOutputStream bout = new ByteArrayOutputStream(initialCapacity);
bout.write(LENGTH_PLACEHOLDER);
ObjectOutputStream oout = new CompactObjectOutputStream(bout);
oout.writeObject(e.getMessage());
oout.flush();
oout.close();
byte[] msg = bout.toByteArray();
int bodyLen = msg.length - 4;
msg[0] = (byte) (bodyLen >>> 24);
msg[1] = (byte) (bodyLen >>> 16);
msg[2] = (byte) (bodyLen >>> 8);
msg[3] = (byte) (bodyLen >>> 0);
ChannelUtil.write(
context, e.getChannel(), e.getFuture(), new HeapByteArray(msg));
}