@Override
    public void write(ByteBuffer buffer) {
        byte[] payloadBytes = writeHeader(buffer);
        buffer.put(payloadBytes);
    }
@ Override public void write ( ByteBuffer buffer ) { byte [ ] payloadBytes = writeHeader ( buffer ) ; buffer . put ( payloadBytes ) ; }
For improved memory efficiency, you should use {@link #writeHeaderAndGetPayloadBuffer(ByteBuffer)}
and write the header buffer as well as the returned payload buffer into the channel.

@param buffer where everything gets written to. Needs to be large enough for the whole message
to be written.