if (!(iObject instanceof OSerializableStream))
throw new OSerializationException("Cannot serialize the object [" + iObject.getClass() + ":" + iObject
+ "] since it does not implement the OSerializableStream interface");
OSerializableStream stream = (OSerializableStream) iObject;
// SERIALIZE THE CLASS NAME
final byte[] className;
if (iObject instanceof OQuery<?>)
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
className = OBinaryProtocol.string2bytes(iObject.getClass().getName());
// SERIALIZE THE OBJECT CONTENT
byte[] objectContent = stream.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);