@Override
    public void writeObject(ByteBuffer buffer, Object object) throws IOException {
//        int p = buffer.position();
        if (object instanceof RemoteObjectDefMessage){
            RemoteObjectDefMessage def = (RemoteObjectDefMessage) object;
            writeObjectDefs(buffer, def);
        }else if (object instanceof RemoteMethodCallMessage){
            RemoteMethodCallMessage call = (RemoteMethodCallMessage) object;
            writeMethodCall(buffer, call);
        }else if (object instanceof RemoteMethodReturnMessage){
            RemoteMethodReturnMessage ret = (RemoteMethodReturnMessage) object;
            writeMethodReturn(buffer, ret);
        }
//        p = buffer.position() - p;
//        System.out.println(object+": uses " + p + " bytes");
    }
{@link RmiSerializer} is responsible for serializing RMI messages
like define object, call, and return.

@author Kirill Vainer
jme3-networking/src/main/java/com/jme3/network/rmi/RmiSerializer.java