use of com.orientechnologies.orient.core.record.impl.ODocumentEntry in project orientdb by orientechnologies.
the class ORecordSerializerBinaryV0 method serialize.
@SuppressWarnings("unchecked")
@Override
public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) {
final OClass clazz = serializeClass(document, bytes);
if (iClassOnly) {
writeEmptyString(bytes);
return;
}
final Map<String, OProperty> props = clazz != null ? clazz.propertiesMap() : null;
final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document);
final int[] pos = new int[fields.size()];
int i = 0;
final Entry<String, ODocumentEntry>[] values = new Entry[fields.size()];
for (Entry<String, ODocumentEntry> entry : fields) {
ODocumentEntry docEntry = entry.getValue();
if (!docEntry.exist())
continue;
if (docEntry.property == null && props != null) {
OProperty prop = props.get(entry.getKey());
if (prop != null && docEntry.type == prop.getType())
docEntry.property = prop;
}
if (docEntry.property != null) {
OVarIntSerializer.write(bytes, (docEntry.property.getId() + 1) * -1);
if (docEntry.property.getType() != OType.ANY)
pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE);
else
pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
} else {
writeString(bytes, entry.getKey());
pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
}
values[i] = entry;
i++;
}
writeEmptyString(bytes);
int size = i;
for (i = 0; i < size; i++) {
int pointer = 0;
final Object value = values[i].getValue().value;
if (value != null) {
final OType type = getFieldType(values[i].getValue());
if (type == null) {
throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
}
pointer = serializeValue(bytes, value, type, getLinkedType(document, type, values[i].getKey()));
OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
if (values[i].getValue().property == null || values[i].getValue().property.getType() == OType.ANY)
writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
}
}
}
use of com.orientechnologies.orient.core.record.impl.ODocumentEntry in project orientdb by orientechnologies.
the class ORecordSerializerNetworkV0 method serialize.
@SuppressWarnings("unchecked")
@Override
public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) {
final OClass clazz = serializeClass(document, bytes);
if (iClassOnly) {
writeEmptyString(bytes);
return;
}
final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document);
final int[] pos = new int[fields.size()];
int i = 0;
final Entry<String, ODocumentEntry>[] values = new Entry[fields.size()];
for (Entry<String, ODocumentEntry> entry : fields) {
ODocumentEntry docEntry = entry.getValue();
if (!docEntry.exist())
continue;
writeString(bytes, entry.getKey());
pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
values[i] = entry;
i++;
}
writeEmptyString(bytes);
int size = i;
for (i = 0; i < size; i++) {
int pointer = 0;
final Object value = values[i].getValue().value;
if (value != null) {
final OType type = getFieldType(values[i].getValue());
if (type == null) {
throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
}
pointer = serializeValue(bytes, value, type, getLinkedType(document, type, values[i].getKey()));
OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
}
}
}
Aggregations