use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method deserializeFromByteBufferObject.
/**
* {@inheritDoc}
*/
@Override
public OCompositeKey deserializeFromByteBufferObject(ByteBuffer buffer) {
final OCompositeKey compositeKey = new OCompositeKey();
buffer.position(buffer.position() + OIntegerSerializer.INT_SIZE);
final int keysSize = buffer.getInt();
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keysSize; i++) {
final byte serializerId = buffer.get();
OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
final Object key = binarySerializer.deserializeFromByteBufferObject(buffer);
compositeKey.addKey(key);
}
return compositeKey;
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method getObjectSize.
public int getObjectSize(OCompositeKey compositeKey, Object... hints) {
final OType[] types = getKeyTypes(hints);
final List<Object> keys = compositeKey.getKeys();
int size = 2 * OIntegerSerializer.INT_SIZE;
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
if (key != null) {
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ((OBinarySerializer<Object>) factory.getObjectSerializer(type)).getObjectSize(key);
} else {
size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ONullSerializer.INSTANCE.getObjectSize(null);
}
}
return size;
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method serializeNativeObject.
public void serializeNativeObject(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) {
final OType[] types = getKeyTypes(hints);
final List<Object> keys = compositeKey.getKeys();
final int keysSize = keys.size();
final int oldStartPosition = startPosition;
startPosition += OIntegerSerializer.INT_SIZE;
OIntegerSerializer.INSTANCE.serializeNative(keysSize, stream, startPosition);
startPosition += OIntegerSerializer.INT_SIZE;
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
OBinarySerializer<Object> binarySerializer;
if (key != null) {
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
binarySerializer = factory.getObjectSerializer(type);
} else
binarySerializer = ONullSerializer.INSTANCE;
stream[startPosition] = binarySerializer.getId();
startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
binarySerializer.serializeNativeObject(key, stream, startPosition);
startPosition += binarySerializer.getObjectSize(key);
}
OIntegerSerializer.INSTANCE.serializeNative((startPosition - oldStartPosition), stream, oldStartPosition);
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method serialize.
public void serialize(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) {
final OType[] types = getKeyTypes(hints);
final List<Object> keys = compositeKey.getKeys();
final int keysSize = keys.size();
final int oldStartPosition = startPosition;
startPosition += OIntegerSerializer.INT_SIZE;
OIntegerSerializer.INSTANCE.serializeLiteral(keysSize, stream, startPosition);
startPosition += OIntegerSerializer.INT_SIZE;
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keys.size(); i++) {
final Object key = keys.get(i);
OBinarySerializer<Object> binarySerializer;
if (key != null) {
final OType type;
if (types.length > i)
type = types[i];
else
type = OType.getTypeByClass(key.getClass());
binarySerializer = factory.getObjectSerializer(type);
} else
binarySerializer = ONullSerializer.INSTANCE;
stream[startPosition] = binarySerializer.getId();
startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
binarySerializer.serialize(key, stream, startPosition);
startPosition += binarySerializer.getObjectSize(key);
}
OIntegerSerializer.INSTANCE.serializeLiteral((startPosition - oldStartPosition), stream, oldStartPosition);
}
use of com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory in project orientdb by orientechnologies.
the class OCompositeKeySerializer method deserializeFromByteBufferObject.
/**
* {@inheritDoc}
*/
@Override
public OCompositeKey deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset) {
final OCompositeKey compositeKey = new OCompositeKey();
offset += OIntegerSerializer.INT_SIZE;
final int keysSize = walChanges.getIntValue(buffer, offset);
offset += OIntegerSerializer.INT_SIZE;
final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
for (int i = 0; i < keysSize; i++) {
final byte serializerId = walChanges.getByteValue(buffer, offset);
offset += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE;
OBinarySerializer<Object> binarySerializer = (OBinarySerializer<Object>) factory.getObjectSerializer(serializerId);
final Object key = binarySerializer.deserializeFromByteBufferObject(buffer, walChanges, offset);
compositeKey.addKey(key);
offset += binarySerializer.getObjectSize(key);
}
return compositeKey;
}
Aggregations