Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

BinaryObjects

BinaryObject(Impl)s have the different structurestructures:

Code Block
languagejava
titleBinaryObjectImpl
private Object obj; // Deserialized value.
private byte[] arr; // Serialized bytes.

...

In a lucky circumstance, BinaryObjectImpl require requires no marshalling, serialization already generates byte which can be used as marshalled bytes.

...

It's not possible to just replace arr with valBytes because, unlike, for example, from CacheObjectImpl arr is not just a mashalled bytes, it's a an object's value required, for example, to provide hashCode/schemaId/typeId/objectField.

...

So, we must provide a simple way to append any transformation.

API

Simplest The simplest way is to use Service Provider Interface (IgniteSpi):

Code Block
languagejava
titleSPI
public interface CacheObjectTransformerSpi extends IgniteSpi {
    /** Additional space required to store the transformed data. */
    public int OVERHEAD = 6;

    /**
     * Transforms the data.
     *
     * @param bytes  Byte array contains the data.
     * @param offset Data offset.
     * @param length Data length.
     * @return Byte array contains the transformed data started with non-filled area with {@link #OVERHEAD} size.
     * @throws IgniteCheckedException when transformation is not possible/suitable.
     */
    public byte[] transform(byte[] bytes, int offset, int length) throws IgniteCheckedException;

    /**
     * Restores the data.
     *
     * @param bytes  Byte array ending with the transformed data.
     * @param offset Transformed data offset.
     * @param length Original data length.
     * @return Byte array contains the restored data.
     */
    public byte[] restore(byte[] bytes, int offset, int length);
}

This API is known about for the overhead used to store transformed data and allows it to work with byte arrays with custom offsets, which is necessary to guarantee performance.

...