Interface ObjectStrategy<T>

All Superinterfaces:
Comparator<T>
All Known Implementing Classes:
DecompressingByteBufferObjectStrategy, ImmutableRTreeObjectStrategy

public interface ObjectStrategy<T> extends Comparator<T>
  • Method Details

    • getClazz

      Class<? extends T> getClazz()
    • fromByteBuffer

      @Nullable T fromByteBuffer(ByteBuffer buffer, int numBytes)
      Convert values from their underlying byte representation. Implementations of this method may change the given buffer's mark, or limit, and position. Implementations of this method may not store the given buffer in a field of the "deserialized" object, need to use ByteBuffer.slice(), ByteBuffer.asReadOnlyBuffer() or ByteBuffer.duplicate() in this case.
      Parameters:
      buffer - buffer to read value from
      numBytes - number of bytes used to store the value, starting at buffer.position()
      Returns:
      an object created from the given byte buffer representation
    • toBytes

      @Nullable byte[] toBytes(@Nullable T val)
    • canCompare

      default boolean canCompare()
      Whether Comparator.compare(T, T) is valid or not.
    • readRetainsBufferReference

      default boolean readRetainsBufferReference()
      Whether the fromByteBuffer(ByteBuffer, int), fromByteBufferWithSize(ByteBuffer), and fromByteBufferSafe(ByteBuffer, int) methods return an object that may retain a reference to the underlying memory provided by a ByteBuffer. If a reference is sometimes retained, this method returns true. It returns false if, and only if, a reference is *never* retained.

      If this method returns true, and the caller does not control the lifecycle of the underlying memory or cannot ensure that it will not change over the lifetime of the returned object, callers should copy the memory to a new location that they do control the lifecycle of and will be available for the duration of the returned object.

      See Also:
    • fromByteBufferWithSize

      default T fromByteBufferWithSize(ByteBuffer buffer)
      Reads 4-bytes numBytes from the given buffer, and then delegates to fromByteBuffer(ByteBuffer, int).
    • writeTo

      default void writeTo(T val, WriteOutBytes out) throws IOException
      Throws:
      IOException
    • fromByteBufferSafe

      @Nullable default T fromByteBufferSafe(ByteBuffer buffer, int numBytes)
      Convert values from their underlying byte representation, when the underlying bytes might be corrupted or maliciously constructed Implementations of this method absolutely must never perform any sun.misc.Unsafe based memory read or write operations from instructions contained in the data read from this buffer without first validating the data. If the data cannot be validated, all read and write operations from instructions in this data must be done directly with the ByteBuffer methods, or using SafeWritableMemory if Memory is employed to materialize the value. Implementations of this method may change the given buffer's mark, or limit, and position. Implementations of this method may not store the given buffer in a field of the "deserialized" object, need to use ByteBuffer.slice(), ByteBuffer.asReadOnlyBuffer() or ByteBuffer.duplicate() in this case.
      Parameters:
      buffer - buffer to read value from
      numBytes - number of bytes used to store the value, starting at buffer.position()
      Returns:
      an object created from the given byte buffer representation