core/src/main/java/com/orientechnologies/orient/core/serialization/serializer/stream/OStreamSerializerAnyStreamable.java
public byte[] toStream(final OCommandRequestText iObject) throws IOException {
    if (iObject == null)
      return null;

    // SERIALIZE THE CLASS NAME
    final byte[] className;
    if (iObject instanceof OLiveQuery<?>)
      className = iObject.getClass().getName().getBytes("UTF-8");
    else if (iObject instanceof OSQLSynchQuery<?>)
      className = QUERY_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandSQL)
      className = SQL_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandScript)
      className = SCRIPT_COMMAND_CLASS_ASBYTES;
    else {
      if (iObject == null)
        className = null;
      else
        className = iObject.getClass().getName().getBytes("UTF-8");
    }
    // SERIALIZE THE OBJECT CONTENT
    byte[] objectContent = iObject.toStream();

    byte[] result = new byte[4 + className.length + objectContent.length];

    // COPY THE CLASS NAME SIZE + CLASS NAME + OBJECT CONTENT
    System.arraycopy(OBinaryProtocol.int2bytes(className.length), 0, result, 0, 4);
    System.arraycopy(className, 0, result, 4, className.length);
    System.arraycopy(objectContent, 0, result, 4 + className.length, objectContent.length);

    return result;
  }
public byte[] toStream(final OCommandRequestText iObject) throws IOException {
    if (iObject == null)
      return null;

    // SERIALIZE THE CLASS NAME
    final byte[] className;
    if (iObject instanceof OLiveQuery<?>)
      className = iObject.getClass().getName().getBytes("UTF-8");
    else if (iObject instanceof OSQLSynchQuery<?>)
      className = QUERY_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandSQL)
      className = SQL_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandScript)
      className = SCRIPT_COMMAND_CLASS_ASBYTES;
    else {
      if (iObject == null)
        className = null;
      else
        className = iObject.getClass().getName().getBytes("UTF-8");
    }
    // SERIALIZE THE OBJECT CONTENT
    byte[] objectContent = iObject.toStream();

    byte[] result = new byte[4 + className.length + objectContent.length];

    // COPY THE CLASS NAME SIZE + CLASS NAME + OBJECT CONTENT
    System.arraycopy(OBinaryProtocol.int2bytes(className.length), 0, result, 0, 4);
    System.arraycopy(className, 0, result, 4, className.length);
    System.arraycopy(objectContent, 0, result, 4 + className.length, objectContent.length);

    return result;
  }
public byte [ ] toStream ( final OCommandRequestText iObject ) throws IOException { if ( iObject == null ) return null ; // SERIALIZE THE CLASS NAME
 final byte [ ] className ; if ( iObject instanceof OLiveQuery < ? > ) className = iObject . getClass ( ) . getName ( ) . getBytes ( "UTF-8" ) ; else if ( iObject instanceof OSQLSynchQuery < ? > ) className = QUERY_COMMAND_CLASS_ASBYTES ; else if ( iObject instanceof OCommandSQL ) className = SQL_COMMAND_CLASS_ASBYTES ; else if ( iObject instanceof OCommandScript ) className = SCRIPT_COMMAND_CLASS_ASBYTES ; else { if ( iObject == null ) className = null ; else className = iObject . getClass ( ) . getName ( ) . getBytes ( "UTF-8" ) ; } // SERIALIZE THE OBJECT CONTENT
 byte [ ] objectContent = iObject . toStream ( ) ; byte [ ] result = new byte [ 4 + className . length + objectContent . length ] ; // COPY THE CLASS NAME SIZE + CLASS NAME + OBJECT CONTENT
 System . arraycopy ( OBinaryProtocol . int2bytes ( className . length ) , 0 , result , 0 , 4 ) ; System . arraycopy ( className , 0 , result , 4 , className . length ) ; System . arraycopy ( objectContent , 0 , result , 4 + className . length , objectContent . length ) ; return result ; }
Serialize the class name size + class name + object content
Serialize the class name size + class name + object content