Interface OBinarySerializer<T>

All Known Implementing Classes:
CompositeKeySerializer, EdgeKeySerializer, IntSerializer, MultiValueEntrySerializer, OBinaryTypeSerializer, OBooleanSerializer, OByteSerializer, OCharSerializer, OCompactedLinkSerializer, OCompositeKeySerializer, ODateSerializer, ODateTimeSerializer, ODecimalSerializer, ODoubleSerializer, OFloatSerializer, OIntegerSerializer, OLinkSerializer, OLongSerializer, OLuceneMockSpatialSerializer, OMixedIndexRIDContainerSerializer, ONullSerializer, OShortSerializer, OSimpleKeySerializer, OStreamSerializerRID, OStreamSerializerSBTreeIndexRIDContainer, OStringSerializer, OUTF8Serializer, OUUIDSerializer

public interface OBinarySerializer<T>
This interface is used for serializing OrientDB datatypes in binary format. Serialized content is written into buffer that will contain not only given object presentation but all binary content. Such approach prevents creation of separate byte array for each object and decreased GC overhead.
Author:
Evgeniy Degtiarenko (gmandnepr-at-gmail.com), Andrey Lomakin
  • Method Details

    • getObjectSize

      int getObjectSize(T object, Object... hints)
      Obtain size of the serialized object Size is the amount of bites that required for storing object (for example: for storing integer we need 4 bytes)
      Parameters:
      object - is the object to measure its size
      hints - List of parameters which may be used to choose appropriate serialization approach.
      Returns:
      size of the serialized object
    • getObjectSize

      int getObjectSize(byte[] stream, int startPosition)
      Return size serialized presentation of given object.
      Parameters:
      stream - Serialized content.
      startPosition - Position from which serialized presentation of given object is stored.
      Returns:
      Size serialized presentation of given object in bytes.
    • serialize

      void serialize(T object, byte[] stream, int startPosition, Object... hints)
      Writes object to the stream starting from the startPosition
      Parameters:
      object - is the object to serialize
      stream - is the stream where object will be written
      hints - List of parameters which may be used to choose appropriate serialization approach.
    • deserialize

      T deserialize(byte[] stream, int startPosition)
      Reads object from the stream starting from the startPosition
      Parameters:
      stream - is the stream from object will be read
      startPosition - is the position to start reading from
      Returns:
      instance of the deserialized object
    • getId

      byte getId()
      Returns:
      Identifier of given serializer.
    • isFixedLength

      boolean isFixedLength()
      Returns:
      true if binary presentation of object always has the same length.
    • getFixedLength

      int getFixedLength()
      Returns:
      Length of serialized data if isFixedLength() method returns true. If isFixedLength() method return false returned value is undefined.
    • serializeNativeObject

      void serializeNativeObject(T object, byte[] stream, int startPosition, Object... hints)
      Writes object to the stream starting from the startPosition using native acceleration. Serialized object presentation is platform dependant.
      Parameters:
      object - is the object to serialize
      stream - is the stream where object will be written
      hints - List of parameters which may be used to choose appropriate serialization approach.
    • deserializeNativeObject

      T deserializeNativeObject(byte[] stream, int startPosition)
      Reads object from the stream starting from the startPosition, in case there were serialized using serializeNativeObject(T, byte[], int, Object...) method.
      Parameters:
      stream - is the stream from object will be read
      startPosition - is the position to start reading from
      Returns:
      instance of the deserialized object
    • getObjectSizeNative

      int getObjectSizeNative(byte[] stream, int startPosition)
      Return size serialized presentation of given object, if it was serialized using serializeNativeObject(T, byte[], int, Object...) method.
      Parameters:
      stream - Serialized content.
      startPosition - Position from which serialized presentation of given object is stored.
      Returns:
      Size serialized presentation of given object in bytes.
    • preprocess

      T preprocess(T value, Object... hints)
    • serializeInByteBufferObject

      void serializeInByteBufferObject(T object, ByteBuffer buffer, Object... hints)
      Serializes binary presentation of object to ByteBuffer. Position of buffer should be set before calling of given method. Serialization result is compatible with result of call of serializeNativeObject(Object, byte[], int, Object...) method. So if we call: buffer.position(10); binarySerializer.serializeInByteBufferObject(object, buffer); and then byte[] stream = new byte[serializedSize + 10]; buffer.position(10); buffer.get(stream); following assert should pass assert object.equals(binarySerializer.deserializeNativeObject(stream, 10)) Final position of ByteBuffer will be changed and will be equal to sum of buffer start position and value returned by method getObjectSize(Object, Object...)
      Parameters:
      object - Object to serialize.
      buffer - Buffer which will contain serialized presentation of buffer.
      hints - Type (types in case of composite object) of object.
    • deserializeFromByteBufferObject

      T deserializeFromByteBufferObject(ByteBuffer buffer)
      Converts binary presentation of object to object instance. Position of buffer should be set before call of this method. Binary format of method is expected to be the same as binary format of serializeNativeObject(Object, byte[], int, Object...) So if we call byte[] stream = new byte[serializedSize]; binarySerializer.serializeNativeObject(object, stream, 0); following assert should pass byteBuffer.position(10); byteBuffer.put(stream); byteBuffer.position(10); assert object.equals(binarySerializer.deserializeFromByteBufferObject(buffer)) Final position of ByteBuffer will be changed and will be equal to sum of buffer start position and value returned by method getObjectSize(Object, Object...)
      Parameters:
      buffer - Buffer which contains serialized presentation of object
      Returns:
      Instance of object serialized in buffer.
    • getObjectSizeInByteBuffer

      int getObjectSizeInByteBuffer(ByteBuffer buffer)
      Returns amount of bytes which is consumed by object which is already serialized in buffer. Position of buffer should be set before call of this method. Result of call should be the same as result of call of getObjectSize(Object, Object...) on deserialized object.
      Parameters:
      buffer - Buffer which contains serialized version of object
      Returns:
      Size of serialized object.
    • deserializeFromByteBufferObject

      T deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset)
      Converts binary presentation of object to object instance taking in account changes which are done inside of atomic operation OAtomicOperation. Binary format of method is expected to be the same as binary format of method serializeNativeObject(Object, byte[], int, Object...). So if we call: byte[] stream = new byte[serializedSize]; binarySerializer.serializeNativeObject(object, stream, 0); walChanges.setBinaryValue(buffer, stream, 10); Then following assert should pass assert object.equals(binarySerializer.deserializeFromByteBufferObject(buffer, walChanges, 10));
      Parameters:
      buffer - Buffer which will contain serialized changes.
      walChanges - Changes are done during atomic operation.
      offset - Offset of binary presentation of object inside of byte buffer/atomic operations changes.
      Returns:
      Instance of object serialized in buffer.
    • getObjectSizeInByteBuffer

      int getObjectSizeInByteBuffer(ByteBuffer buffer, OWALChanges walChanges, int offset)
      Returns amount of bytes which is consumed by object which is already serialized in buffer taking in account changes which are done inside of atomic operation OAtomicOperation. Result of call should be the same as result of call of getObjectSize(Object, Object...) on deserialized object.
      Parameters:
      buffer - Buffer which will contain serialized changes.
      walChanges - Changes are done during atomic operation.
      offset - Offset of binary presentation of object inside of byte buffer/atomic operations changes.
      Returns:
      Size of serialized object.
    • serializeNativeAsWhole

      default byte[] serializeNativeAsWhole(T object, Object... hints)