public interface OBinarySerializer<T>
Modifier and Type | Method and Description |
---|---|
T |
deserialize(byte[] stream,
int startPosition)
Reads object from the stream starting from the startPosition
|
T |
deserializeFromByteBufferObject(ByteBuffer buffer)
Converts binary presentation of object to object instance.
|
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 . |
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. |
int |
getFixedLength() |
byte |
getId() |
int |
getObjectSize(byte[] stream,
int startPosition)
Return size serialized presentation of given object.
|
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)
|
int |
getObjectSizeInByteBuffer(ByteBuffer buffer)
Returns amount of bytes which is consumed by object which is already serialized in buffer.
|
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 . |
int |
getObjectSizeNative(byte[] stream,
int startPosition)
Return size serialized presentation of given object, if it was serialized using
#serializeNativeObject(T, byte[], int, Object...) method. |
boolean |
isFixedLength() |
T |
preprocess(T value,
Object... hints) |
void |
serialize(T object,
byte[] stream,
int startPosition,
Object... hints)
Writes object to the stream starting from the startPosition
|
void |
serializeInByteBufferObject(T object,
ByteBuffer buffer,
Object... hints)
Serializes binary presentation of object to
ByteBuffer . |
default byte[] |
serializeNativeAsWhole(T object,
Object... hints) |
void |
serializeNativeObject(T object,
byte[] stream,
int startPosition,
Object... hints)
Writes object to the stream starting from the startPosition using native acceleration.
|
int getObjectSize(T object, Object... hints)
object
- is the object to measure its sizehints
- List of parameters which may be used to choose appropriate serialization approach.int getObjectSize(byte[] stream, int startPosition)
stream
- Serialized content.startPosition
- Position from which serialized presentation of given object is stored.void serialize(T object, byte[] stream, int startPosition, Object... hints)
object
- is the object to serializestream
- is the stream where object will be writtenhints
- List of parameters which may be used to choose appropriate serialization approach.T deserialize(byte[] stream, int startPosition)
stream
- is the stream from object will be readstartPosition
- is the position to start reading frombyte getId()
boolean isFixedLength()
true
if binary presentation of object always has the same length.int getFixedLength()
isFixedLength()
method returns true
.
If isFixedLength()
method return false
returned value is undefined.void serializeNativeObject(T object, byte[] stream, int startPosition, Object... hints)
object
- is the object to serializestream
- is the stream where object will be writtenhints
- List of parameters which may be used to choose appropriate serialization approach.T deserializeNativeObject(byte[] stream, int startPosition)
#serializeNativeObject(T, byte[], int, Object...)
method.stream
- is the stream from object will be readstartPosition
- is the position to start reading fromint getObjectSizeNative(byte[] stream, int startPosition)
#serializeNativeObject(T, byte[], int, Object...)
method.stream
- Serialized content.startPosition
- Position from which serialized presentation of given object is stored.void serializeInByteBufferObject(T object, ByteBuffer buffer, Object... hints)
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...)
object
- Object to serialize.buffer
- Buffer which will contain serialized presentation of buffer.hints
- Type (types in case of composite object) of object.T deserializeFromByteBufferObject(ByteBuffer buffer)
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...)
buffer
- Buffer which contains serialized presentation of objectint getObjectSizeInByteBuffer(ByteBuffer buffer)
getObjectSize(Object, Object...)
on deserialized object.buffer
- Buffer which contains serialized version of objectT deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset)
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));
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.int getObjectSizeInByteBuffer(ByteBuffer buffer, OWALChanges walChanges, int offset)
OAtomicOperation
.
Result of call should be the same as result of call of getObjectSize(Object,
Object...)
on deserialized object.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.Copyright © 2009–2020 OrientDB. All rights reserved.