public byte[] toStream(final ODatabaseRecord iDatabase, Object iObject) throws IOException {
if (iObject == null)
return null;
if (((ORecord<?>) iObject).getIdentity() == null)
throw new OSerializationException("Can't serialize record without identity. Store it before to serialize.");
final StringBuilder buffer = OStreamSerializerHelper.writeRecordType(iObject.getClass(), new StringBuilder());
buffer.append(((ORecord<?>) iObject).getIdentity().toString());
return OBinaryProtocol.string2bytes(buffer.toString());