@SuppressWarnings("unchecked")
public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) {
serializeClass(document, bytes);
if (iClassOnly) {
writeEmptyString(bytes);
return;
}
final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document);
OVarIntSerializer.write(bytes, document.fields());
for (Entry<String, ODocumentEntry> entry : fields) {
ODocumentEntry docEntry = entry.getValue();
if (!docEntry.exist())
continue;
writeString(bytes, entry.getKey());
final Object value = entry.getValue().value;
if (value != null) {
final OType type = getFieldType(entry.getValue());
if (type == null) {
throw new OSerializationException(
"Impossible serialize value of type " + value.getClass() + " with the Result binary serializer");
}
writeOType(bytes, bytes.alloc(1), type);
serializeValue(bytes, value, type, getLinkedType(document, type, entry.getKey()));
} else {
writeOType(bytes, bytes.alloc(1), null);
}
}
}