Class OLuceneMockSpatialSerializer

java.lang.Object
com.orientechnologies.spatial.OLuceneMockSpatialSerializer
All Implemented Interfaces:
OBinarySerializer<ODocument>

public class OLuceneMockSpatialSerializer extends Object implements OBinarySerializer<ODocument>
Created by Enrico Risa on 04/09/15.
  • Field Details

  • Constructor Details

    • OLuceneMockSpatialSerializer

      protected OLuceneMockSpatialSerializer()
  • Method Details

    • getObjectSize

      public int getObjectSize(ODocument object, Object... hints)
      Description copied from interface: OBinarySerializer
      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)
      Specified by:
      getObjectSize in interface OBinarySerializer<ODocument>
      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

      public int getObjectSize(byte[] stream, int startPosition)
      Description copied from interface: OBinarySerializer
      Return size serialized presentation of given object.
      Specified by:
      getObjectSize in interface OBinarySerializer<ODocument>
      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

      public void serialize(ODocument object, byte[] stream, int startPosition, Object... hints)
      Description copied from interface: OBinarySerializer
      Writes object to the stream starting from the startPosition
      Specified by:
      serialize in interface OBinarySerializer<ODocument>
      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

      public ODocument deserialize(byte[] stream, int startPosition)
      Description copied from interface: OBinarySerializer
      Reads object from the stream starting from the startPosition
      Specified by:
      deserialize in interface OBinarySerializer<ODocument>
      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

      public byte getId()
      Specified by:
      getId in interface OBinarySerializer<ODocument>
      Returns:
      Identifier of given serializer.
    • isFixedLength

      public boolean isFixedLength()
      Specified by:
      isFixedLength in interface OBinarySerializer<ODocument>
      Returns:
      true if binary presentation of object always has the same length.
    • getFixedLength

      public int getFixedLength()
      Specified by:
      getFixedLength in interface OBinarySerializer<ODocument>
      Returns:
      Length of serialized data if OBinarySerializer.isFixedLength() method returns true. If OBinarySerializer.isFixedLength() method return false returned value is undefined.
    • serializeNativeObject

      public void serializeNativeObject(ODocument object, byte[] stream, int startPosition, Object... hints)
      Description copied from interface: OBinarySerializer
      Writes object to the stream starting from the startPosition using native acceleration. Serialized object presentation is platform dependant.
      Specified by:
      serializeNativeObject in interface OBinarySerializer<ODocument>
      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

      public ODocument deserializeNativeObject(byte[] stream, int startPosition)
      Description copied from interface: OBinarySerializer
      Reads object from the stream starting from the startPosition, in case there were serialized using OBinarySerializer.serializeNativeObject(T, byte[], int, Object...) method.
      Specified by:
      deserializeNativeObject in interface OBinarySerializer<ODocument>
      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

      public int getObjectSizeNative(byte[] stream, int startPosition)
      Description copied from interface: OBinarySerializer
      Return size serialized presentation of given object, if it was serialized using OBinarySerializer.serializeNativeObject(T, byte[], int, Object...) method.
      Specified by:
      getObjectSizeNative in interface OBinarySerializer<ODocument>
      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

      public ODocument preprocess(ODocument value, Object... hints)
      Specified by:
      preprocess in interface OBinarySerializer<ODocument>
    • serializeInByteBufferObject

      public void serializeInByteBufferObject(ODocument object, ByteBuffer buffer, Object... hints)
      Description copied from interface: OBinarySerializer
      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 OBinarySerializer.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 OBinarySerializer.getObjectSize(Object, Object...)
      Specified by:
      serializeInByteBufferObject in interface OBinarySerializer<ODocument>
      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

      public ODocument deserializeFromByteBufferObject(ByteBuffer buffer)
      Description copied from interface: OBinarySerializer
      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 OBinarySerializer.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 OBinarySerializer.getObjectSize(Object, Object...)
      Specified by:
      deserializeFromByteBufferObject in interface OBinarySerializer<ODocument>
      Parameters:
      buffer - Buffer which contains serialized presentation of object
      Returns:
      Instance of object serialized in buffer.
    • deserializeFromByteBufferObject

      public ODocument deserializeFromByteBufferObject(int offset, ByteBuffer buffer)
      Description copied from interface: OBinarySerializer
      Converts binary presentation of object to object instance. Binary format of method is expected to be the same as binary format of OBinarySerializer.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, 10)) Final position of ByteBuffer will NOT be changed during the call.
      Specified by:
      deserializeFromByteBufferObject in interface OBinarySerializer<ODocument>
      Parameters:
      offset - offset inside the ByteBuffer from which deserialization should be started.
      buffer - Buffer which contains serialized presentation of object
      Returns:
      Instance of object serialized in buffer.
    • getObjectSizeInByteBuffer

      public int getObjectSizeInByteBuffer(ByteBuffer buffer)
      Description copied from interface: OBinarySerializer
      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 OBinarySerializer.getObjectSize(Object, Object...) on deserialized object.
      Specified by:
      getObjectSizeInByteBuffer in interface OBinarySerializer<ODocument>
      Parameters:
      buffer - Buffer which contains serialized version of object
      Returns:
      Size of serialized object.
    • getObjectSizeInByteBuffer

      public int getObjectSizeInByteBuffer(int offset, ByteBuffer buffer)
      Description copied from interface: OBinarySerializer
      Returns amount of bytes which is consumed by object which is already serialized in buffer. Result of call should be the same as result of call of OBinarySerializer.getObjectSize(Object, Object...) on deserialized object.

      Position of ByteBuffer is not changed after result of the call.

      Specified by:
      getObjectSizeInByteBuffer in interface OBinarySerializer<ODocument>
      Parameters:
      offset - offset inside the buffer since which object is serialized.
      buffer - Buffer which contains serialized version of object
      Returns:
      Size of serialized object.
    • deserializeFromByteBufferObject

      public ODocument deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset)
      Description copied from interface: OBinarySerializer
      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 OBinarySerializer.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));

      ByteBuffer position should NOT be changed during call of this method.

      Specified by:
      deserializeFromByteBufferObject in interface OBinarySerializer<ODocument>
      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

      public int getObjectSizeInByteBuffer(ByteBuffer buffer, OWALChanges walChanges, int offset)
      Description copied from interface: OBinarySerializer
      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 OBinarySerializer.getObjectSize(Object, Object...) on deserialized object.

      ByteBuffer position should NOT be changed during call of this method.

      Specified by:
      getObjectSizeInByteBuffer in interface OBinarySerializer<ODocument>
      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.