Interface ValueAccessor<V>

Type Parameters:
V - the backing type
All Known Implementing Classes:
ByteArrayAccessor, ByteBufferAccessor

public interface ValueAccessor<V>
ValueAccessor allows serializers and other code dealing with raw bytes to operate on different backing types (ie: byte arrays, byte buffers, etc) without requiring that the supported backing types share a common type ancestor and without incuring the allocation cost of a wrapper object. A note on byte buffers for implementors: the "value" of a byte buffer is always interpreted as beginning at it's Buffer.position() and having a length of Buffer.remaining(). ValueAccessor implementations need to maintain this internally. ValueAccessors should also never modify the state of the byte buffers view (ie: offset, limit). This would also apply to value accessors for simlilar types (ie: netty's ByteBuf}.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Creates db objects using the given accessors value type.
  • Method Summary

    Modifier and Type
    Method
    Description
    allocate(int size)
    Allocate and return a instance of bytes on the heap.
    static <L, R> int
    compare(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)
    lexicographically compare to
    <VR> int
    compare(V left, VR right, ValueAccessor<VR> accessorR)
    lexicographically compare to
    int
    compareByteArrayTo(byte[] left, V right)
    compare a byte array on the left with a on the right}
    int
    compare a byte buffer on the left with a on the right}
    <V2> V
    convert(V2 src, ValueAccessor<V2> accessor)
    Convert the data in to and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of
    int
    copyByteArrayTo(byte[] src, int srcOffset, V dst, int dstOffset, int size)
    copies a byte array into this accessors value.
    int
    copyByteBufferTo(ByteBuffer src, int srcOffset, V dst, int dstOffset, int size)
    copies a byte buffer into this accessors value.
    <V2> int
    copyTo(V src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)
    copy the bytes from the value, starting at the offset into the value, starting at the offset , using the accessor
    V[]
    createArray(int length)
    allocate an instance of the accessors backing type
    void
    digest(V value, int offset, int size, Digest digest)
    updates with bytes from the contents of starting at offset
    default void
    digest(V value, Digest digest)
    updates with te contents of
    return a value with a length of 0
    static <L, R> boolean
    equals(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)
     
    returns the ValueAccessor.ObjectFactory for the backing type
    default boolean
    getBoolean(V value, int offset)
    returns a boolean from offset
    byte
    getByte(V value, int offset)
    returns a byte from offset
    double
    getDouble(V value, int offset)
     
    float
    getFloat(V value, int offset)
     
    int
    getInt(V value, int offset)
    returns an int from offset
    long
    getLong(V value, int offset)
    returns a long from offset
    short
    getShort(V value, int offset)
    returns a short from offset
    int
    getUnsignedShort(V value, int offset)
    returns an unsigned short from offset
    default long
    getUnsignedVInt(V value, int offset)
     
    default int
    getUnsignedVInt32(V value, int offset)
     
    default long
    getVInt(V value, int offset)
     
    default int
    getVInt32(V value, int offset)
     
    default int
    hashCode(V value)
     
    default boolean
    isEmpty(V value)
     
    default boolean
    isEmptyFromOffset(V value, int offset)
     
    int
    putByte(V dst, int offset, byte value)
    writes the byte value to at offset
    default int
    putBytes(V dst, int offset, byte[] src)
     
    default int
    putBytes(V dst, int offset, byte[] src, int srcOffset, int length)
     
    int
    putFloat(V dst, int offset, float value)
    writes the float value to at offset
    int
    putInt(V dst, int offset, int value)
    writes the int value to at offset
    int
    putLong(V dst, int offset, long value)
    writes the long value to at offset
    int
    putShort(V dst, int offset, short value)
    writes the short value to at offset
    default int
    putUnsignedVInt(V dst, int offset, long value)
     
    default int
    putUnsignedVInt32(V dst, int offset, int value)
     
    default int
    putVInt(V dst, int offset, long value)
     
    default int
    putVInt32(V dst, int offset, int value)
     
    read(DataInputPlus in, int length)
    Reads a value of bytes from
    default int
    remaining(V value, int offset)
     
    int
    size(V value)
     
    default int
    sizeFromOffset(V value, int offset)
     
    default int
    serialized size including a short length prefix
    default int
    serializes size including a vint length prefix
    slice(V input, int offset, int length)
    Returns a value with the contents of from to .
    default V
    sliceWithShortLength(V input, int offset)
    same as slice(Object, int, int), except the length is taken from the first 2 bytes from the given offset (and not included in the return value)
    byte[]
    toArray(V value)
    returns a byte[] with the contents of Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]
    byte[]
    toArray(V value, int offset, int length)
    returns a byte[] with bytes copied from the contents of starting at offset .
    toBallot(V value)
    returns a TimeUUID from offset 0
    toBuffer(V value)
    returns a ByteBuffer with the contents of Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebuffer
    byte
    toByte(V value)
    returns a byte from offset 0
    double
    toDouble(V value)
    returns a double from offset 0
    float
    toFloat(V value)
    returns a float from offset 0
    float[]
    toFloatArray(V value, int dimension)
    returns a float[] from offset 0
    toHex(V value)
     
    int
    toInt(V value)
    returns an int from offset 0
    long
    toLong(V value)
    returns a long from offset 0
    short
    toShort(V value)
    returns a short from offset 0
    default String
    toString(V value)
     
    toString(V value, Charset charset)
     
    toTimeUUID(V value)
    returns a TimeUUID from offset 0
    toUUID(V value)
    returns a UUID from offset 0
    valueOf(boolean v)
    return a value with the bytes from
    valueOf(byte v)
    return a value with the bytes from
    valueOf(byte[] bytes)
    return a value containing the Caller should assume that modifying the returned value will also modify the contents of
    valueOf(double v)
    return a value with the bytes from
    valueOf(float v)
    return a value with the bytes from
    valueOf(int v)
    return a value with the bytes from
    valueOf(long v)
    return a value with the bytes from
    valueOf(short v)
    return a value with the bytes from
    valueOf(String s, Charset charset)
    return a value containing the bytes for the given string and charset
    return a value containing the and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of
    return a value with the bytes from
    void
    write(V value, ByteBuffer out)
    Write the contents of the given value into the ByteBuffer
    void
    write(V value, DataOutputPlus out)
    Write the contents of the given value into the a DataOutputPlus
    default void
     
  • Method Details

    • size

      int size(V value)
      Returns:
      the size of the given value
    • sizeWithVIntLength

      default int sizeWithVIntLength(V value)
      serializes size including a vint length prefix
    • sizeWithShortLength

      default int sizeWithShortLength(V value)
      serialized size including a short length prefix
    • remaining

      default int remaining(V value, int offset)
    • isEmpty

      default boolean isEmpty(V value)
      Returns:
      true if the size of the given value is zero, false otherwise
    • sizeFromOffset

      default int sizeFromOffset(V value, int offset)
      Returns:
      the number of bytes remaining in the value from the given offset
    • isEmptyFromOffset

      default boolean isEmptyFromOffset(V value, int offset)
      Returns:
      true if there are no bytes present after the given offset, false otherwise
    • createArray

      V[] createArray(int length)
      allocate an instance of the accessors backing type
      Parameters:
      length - size of backing typ to allocate
    • write

      void write(V value, DataOutputPlus out) throws IOException
      Write the contents of the given value into the a DataOutputPlus
      Throws:
      IOException
    • writeWithVIntLength

      default void writeWithVIntLength(V value, DataOutputPlus out) throws IOException
      Throws:
      IOException
    • write

      void write(V value, ByteBuffer out)
      Write the contents of the given value into the ByteBuffer
    • copyTo

      <V2> int copyTo(V src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)
      copy the bytes from the value, starting at the offset into the value, starting at the offset , using the accessor
      Type Parameters:
      V2 - the destination value type
      Returns:
      the number of bytes copied ()
    • copyByteArrayTo

      int copyByteArrayTo(byte[] src, int srcOffset, V dst, int dstOffset, int size)
      copies a byte array into this accessors value.
    • copyByteBufferTo

      int copyByteBufferTo(ByteBuffer src, int srcOffset, V dst, int dstOffset, int size)
      copies a byte buffer into this accessors value.
    • digest

      void digest(V value, int offset, int size, Digest digest)
      updates with bytes from the contents of starting at offset
    • digest

      default void digest(V value, Digest digest)
      updates with te contents of
    • read

      V read(DataInputPlus in, int length) throws IOException
      Reads a value of bytes from
      Throws:
      IOException
    • slice

      V slice(V input, int offset, int length)
      Returns a value with the contents of from to . Depending on the accessor implementation, this method may: * allocate a new object of , and copy data into it * return a view of where changes to one will be reflected in the other
    • sliceWithShortLength

      default V sliceWithShortLength(V input, int offset)
      same as slice(Object, int, int), except the length is taken from the first 2 bytes from the given offset (and not included in the return value)
    • compare

      <VR> int compare(V left, VR right, ValueAccessor<VR> accessorR)
      lexicographically compare to
      Type Parameters:
      VR - backing type of
    • compareByteArrayTo

      int compareByteArrayTo(byte[] left, V right)
      compare a byte array on the left with a on the right}
    • compareByteBufferTo

      int compareByteBufferTo(ByteBuffer left, V right)
      compare a byte buffer on the left with a on the right}
    • hashCode

      default int hashCode(V value)
    • toBuffer

      ByteBuffer toBuffer(V value)
      returns a ByteBuffer with the contents of Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebuffer
    • toArray

      byte[] toArray(V value)
      returns a byte[] with the contents of Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]
    • toArray

      byte[] toArray(V value, int offset, int length)
      returns a byte[] with bytes copied from the contents of starting at offset . Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[], offset is 0 and == size(value)
    • toString

      String toString(V value, Charset charset) throws CharacterCodingException
      Throws:
      CharacterCodingException
    • toString

      default String toString(V value) throws CharacterCodingException
      Throws:
      CharacterCodingException
    • toHex

      String toHex(V value)
    • getBoolean

      default boolean getBoolean(V value, int offset)
      returns a boolean from offset
    • toByte

      byte toByte(V value)
      returns a byte from offset 0
    • getByte

      byte getByte(V value, int offset)
      returns a byte from offset
    • toShort

      short toShort(V value)
      returns a short from offset 0
    • getShort

      short getShort(V value, int offset)
      returns a short from offset
    • getUnsignedShort

      int getUnsignedShort(V value, int offset)
      returns an unsigned short from offset
    • toInt

      int toInt(V value)
      returns an int from offset 0
    • getInt

      int getInt(V value, int offset)
      returns an int from offset
    • getUnsignedVInt

      default long getUnsignedVInt(V value, int offset)
    • getUnsignedVInt32

      default int getUnsignedVInt32(V value, int offset)
    • getVInt

      default long getVInt(V value, int offset)
    • getVInt32

      default int getVInt32(V value, int offset)
    • getFloat

      float getFloat(V value, int offset)
    • getDouble

      double getDouble(V value, int offset)
    • toLong

      long toLong(V value)
      returns a long from offset 0
    • getLong

      long getLong(V value, int offset)
      returns a long from offset
    • toFloat

      float toFloat(V value)
      returns a float from offset 0
    • toDouble

      double toDouble(V value)
      returns a double from offset 0
    • toUUID

      UUID toUUID(V value)
      returns a UUID from offset 0
    • toTimeUUID

      TimeUUID toTimeUUID(V value)
      returns a TimeUUID from offset 0
    • toBallot

      Ballot toBallot(V value)
      returns a TimeUUID from offset 0
    • toFloatArray

      float[] toFloatArray(V value, int dimension)
      returns a float[] from offset 0
    • putByte

      int putByte(V dst, int offset, byte value)
      writes the byte value to at offset
      Returns:
      the number of bytes written to
    • putShort

      int putShort(V dst, int offset, short value)
      writes the short value to at offset
      Returns:
      the number of bytes written to
    • putInt

      int putInt(V dst, int offset, int value)
      writes the int value to at offset
      Returns:
      the number of bytes written to
    • putLong

      int putLong(V dst, int offset, long value)
      writes the long value to at offset
      Returns:
      the number of bytes written to
    • putFloat

      int putFloat(V dst, int offset, float value)
      writes the float value to at offset
      Returns:
      the number of bytes written to
    • putBytes

      default int putBytes(V dst, int offset, byte[] src, int srcOffset, int length)
    • putBytes

      default int putBytes(V dst, int offset, byte[] src)
    • putUnsignedVInt

      default int putUnsignedVInt(V dst, int offset, long value)
    • putUnsignedVInt32

      default int putUnsignedVInt32(V dst, int offset, int value)
    • putVInt

      default int putVInt(V dst, int offset, long value)
    • putVInt32

      default int putVInt32(V dst, int offset, int value)
    • empty

      V empty()
      return a value with a length of 0
    • valueOf

      V valueOf(byte[] bytes)
      return a value containing the Caller should assume that modifying the returned value will also modify the contents of
    • valueOf

      V valueOf(ByteBuffer bytes)
      return a value containing the and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of
    • valueOf

      V valueOf(String s, Charset charset)
      return a value containing the bytes for the given string and charset
    • valueOf

      V valueOf(UUID v)
      return a value with the bytes from
    • valueOf

      V valueOf(boolean v)
      return a value with the bytes from
    • valueOf

      V valueOf(byte v)
      return a value with the bytes from
    • valueOf

      V valueOf(short v)
      return a value with the bytes from
    • valueOf

      V valueOf(int v)
      return a value with the bytes from
    • valueOf

      V valueOf(long v)
      return a value with the bytes from
    • valueOf

      V valueOf(float v)
      return a value with the bytes from
    • valueOf

      V valueOf(double v)
      return a value with the bytes from
    • convert

      <V2> V convert(V2 src, ValueAccessor<V2> accessor)
      Convert the data in to and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of
    • allocate

      V allocate(int size)
      Allocate and return a instance of bytes on the heap.
    • factory

      returns the ValueAccessor.ObjectFactory for the backing type
    • compare

      static <L, R> int compare(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)
      lexicographically compare to
    • equals

      static <L, R> boolean equals(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)