@Override
    public ByteBuffer toByteBuffer( Message message, ByteBuffer target ) {
    
        // Could let the caller pass their own in       
        ByteBuffer buffer = target == null ? ByteBuffer.allocate(32767 + 2) : target;
        
        try {
            buffer.position(2);
            Serializer.writeClassAndObject(buffer, message);
            buffer.flip();
            short dataLength = (short)(buffer.remaining() - 2);
            buffer.putShort(dataLength);
            buffer.position(0);
            
            return buffer;
        } catch( IOException e ) {
            throw new RuntimeException("Error serializing message", e);
        }
    }
Converts a message to a ByteBuffer using the com.jme3.network.serializing.Serializer
 and the (short length) + data protocol.  If target is null
 then a 32k byte buffer will be created and filled.
jme3-networking/src/main/java/com/jme3/network/base/protocol/SerializerMessageProtocol.java