Package org.apache.cassandra.db.marshal
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'sBuffer.position()and having a length ofBuffer.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 interfaceValueAccessor.ObjectFactory<V>Creates db objects using the given accessors value type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Vallocate(int size)Allocate and return a {@param} instance of {@param size} bytes on the heap. static <L,R>
intcompare(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)lexicographically compare {@param left} to {@param right}<VR> intcompare(V left, VR right, ValueAccessor<VR> accessorR)lexicographically compare {@param left} to {@param right}intcompareByteArrayTo(byte[] left, V right)compare a byte array on the left with a {@param} on the right} intcompareByteBufferTo(java.nio.ByteBuffer left, V right)compare a byte buffer on the left with a {@param} on the right} <V2> Vconvert(V2 src, ValueAccessor<V2> accessor)Convert the data in {@param src} to {@param} {@param src} 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 {@param src} intcopyByteArrayTo(byte[] src, int srcOffset, V dst, int dstOffset, int size)copies a byte array into this accessors value.intcopyByteBufferTo(java.nio.ByteBuffer src, int srcOffset, V dst, int dstOffset, int size)copies a byte buffer into this accessors value.<V2> intcopyTo(V src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)copy the {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}V[]createArray(int length)allocate an instance of the accessors backing typevoiddigest(V value, int offset, int size, Digest digest)updates {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}default voiddigest(V value, Digest digest)updates {@param digest} with te contents of {@param value}Vempty()return a value with a length of 0static <L,R>
booleanequals(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)ValueAccessor.ObjectFactory<V>factory()returns theValueAccessor.ObjectFactoryfor the backing type {@param} default booleangetBoolean(V value, int offset)returns a boolean from offset {@param offset}bytegetByte(V value, int offset)returns a byte from offset {@param offset}intgetInt(V value, int offset)returns an int from offset {@param offset}longgetLong(V value, int offset)returns a long from offset {@param offset}shortgetShort(V value, int offset)returns a short from offset {@param offset}intgetUnsignedShort(V value, int offset)returns an unsigned short from offset {@param offset}default inthashCode(V value)default booleanisEmpty(V value)default booleanisEmptyFromOffset(V value, int offset)intputByte(V dst, int offset, byte value)writes the byte value {@param value} to {@param dst} at offset {@param offset}intputInt(V dst, int offset, int value)writes the int value {@param value} to {@param dst} at offset {@param offset}intputLong(V dst, int offset, long value)writes the long value {@param value} to {@param dst} at offset {@param offset}intputShort(V dst, int offset, short value)writes the short value {@param value} to {@param dst} at offset {@param offset}Vread(DataInputPlus in, int length)Reads a value of {@param length} bytes from {@param in}intsize(V value)default intsizeFromOffset(V value, int offset)default intsizeWithShortLength(V value)serialized size including a short length prefixdefault intsizeWithVIntLength(V value)serializes size including a vint length prefixVslice(V input, int offset, int length)Returns a value with the contents of {@param input} from {@param offset} to {@param length}.default VsliceWithShortLength(V input, int offset)same asslice(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 {@param value} 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 {@param length} bytes copied from the contents of {@param value} starting at offset {@param offset}.BallottoBallot(V value)returns a TimeUUID from offset 0java.nio.ByteBuffertoBuffer(V value)returns a ByteBuffer with the contents of {@param value} 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 bytebufferbytetoByte(V value)returns a byte from offset 0doubletoDouble(V value)returns a double from offset 0floattoFloat(V value)returns a float from offset 0java.lang.StringtoHex(V value)inttoInt(V value)returns an int from offset 0longtoLong(V value)returns a long from offset 0shorttoShort(V value)returns a short from offset 0default java.lang.StringtoString(V value)java.lang.StringtoString(V value, java.nio.charset.Charset charset)TimeUUIDtoTimeUUID(V value)returns a TimeUUID from offset 0java.util.UUIDtoUUID(V value)returns a UUID from offset 0VvalueOf(boolean v)return a value with the bytes from {@param v}VvalueOf(byte v)return a value with the bytes from {@param v}VvalueOf(byte[] bytes)return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}VvalueOf(double v)return a value with the bytes from {@param v}VvalueOf(float v)return a value with the bytes from {@param v}VvalueOf(int v)return a value with the bytes from {@param v}VvalueOf(long v)return a value with the bytes from {@param v}VvalueOf(short v)return a value with the bytes from {@param v}VvalueOf(java.lang.String s, java.nio.charset.Charset charset)return a value containing the bytes for the given string and charsetVvalueOf(java.nio.ByteBuffer bytes)return a value containing the {@param bytes} {@param src} 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 {@param src}VvalueOf(java.util.UUID v)return a value with the bytes from {@param v}voidwrite(V value, java.nio.ByteBuffer out)Write the contents of the given value into the ByteBuffervoidwrite(V value, DataOutputPlus out)Write the contents of the given value into the a DataOutputPlusdefault voidwriteWithVIntLength(V value, DataOutputPlus out)
-
-
-
Method Detail
-
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
-
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 java.io.IOException
Write the contents of the given value into the a DataOutputPlus- Throws:
java.io.IOException
-
writeWithVIntLength
default void writeWithVIntLength(V value, DataOutputPlus out) throws java.io.IOException
- Throws:
java.io.IOException
-
write
void write(V value, java.nio.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 {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}- Type Parameters:
V2- the destination value type- Returns:
- the number of bytes copied ({@param size})
-
copyByteArrayTo
int copyByteArrayTo(byte[] src, int srcOffset, V dst, int dstOffset, int size)copies a byte array into this accessors value.
-
copyByteBufferTo
int copyByteBufferTo(java.nio.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 {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}
-
digest
default void digest(V value, Digest digest)
updates {@param digest} with te contents of {@param value}
-
read
V read(DataInputPlus in, int length) throws java.io.IOException
Reads a value of {@param length} bytes from {@param in}- Throws:
java.io.IOException
-
slice
V slice(V input, int offset, int length)
Returns a value with the contents of {@param input} from {@param offset} to {@param length}. Depending on the accessor implementation, this method may: * allocate a new {@param} object of {@param length}, and copy data into it * return a view of {@param input} where changes to one will be reflected in the other
-
sliceWithShortLength
default V sliceWithShortLength(V input, int offset)
same asslice(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 {@param left} to {@param right}- Type Parameters:
VR- backing type of
-
compareByteArrayTo
int compareByteArrayTo(byte[] left, V right)compare a byte array on the left with a {@param} on the right}
-
compareByteBufferTo
int compareByteBufferTo(java.nio.ByteBuffer left, V right)compare a byte buffer on the left with a {@param} on the right}
-
hashCode
default int hashCode(V value)
-
toBuffer
java.nio.ByteBuffer toBuffer(V value)
returns a ByteBuffer with the contents of {@param value} 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 {@param value} 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 {@param length} bytes copied from the contents of {@param value} starting at offset {@param 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 {@param length} == size(value)
-
toString
java.lang.String toString(V value, java.nio.charset.Charset charset) throws java.nio.charset.CharacterCodingException
- Throws:
java.nio.charset.CharacterCodingException
-
toString
default java.lang.String toString(V value) throws java.nio.charset.CharacterCodingException
- Throws:
java.nio.charset.CharacterCodingException
-
toHex
java.lang.String toHex(V value)
-
getBoolean
default boolean getBoolean(V value, int offset)
returns a boolean from offset {@param offset}
-
toByte
byte toByte(V value)
returns a byte from offset 0
-
getByte
byte getByte(V value, int offset)
returns a byte from offset {@param offset}
-
toShort
short toShort(V value)
returns a short from offset 0
-
getShort
short getShort(V value, int offset)
returns a short from offset {@param offset}
-
getUnsignedShort
int getUnsignedShort(V value, int offset)
returns an unsigned short from offset {@param offset}
-
toInt
int toInt(V value)
returns an int from offset 0
-
getInt
int getInt(V value, int offset)
returns an int from offset {@param offset}
-
toLong
long toLong(V value)
returns a long from offset 0
-
getLong
long getLong(V value, int offset)
returns a long from offset {@param offset}
-
toFloat
float toFloat(V value)
returns a float from offset 0
-
toDouble
double toDouble(V value)
returns a double from offset 0
-
toUUID
java.util.UUID toUUID(V value)
returns a UUID from offset 0
-
putByte
int putByte(V dst, int offset, byte value)
writes the byte value {@param value} to {@param dst} at offset {@param offset}- Returns:
- the number of bytes written to {@param value}
-
putShort
int putShort(V dst, int offset, short value)
writes the short value {@param value} to {@param dst} at offset {@param offset}- Returns:
- the number of bytes written to {@param value}
-
putInt
int putInt(V dst, int offset, int value)
writes the int value {@param value} to {@param dst} at offset {@param offset}- Returns:
- the number of bytes written to {@param value}
-
putLong
int putLong(V dst, int offset, long value)
writes the long value {@param value} to {@param dst} at offset {@param offset}- Returns:
- the number of bytes written to {@param value}
-
empty
V empty()
return a value with a length of 0
-
valueOf
V valueOf(byte[] bytes)
return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}
-
valueOf
V valueOf(java.nio.ByteBuffer bytes)
return a value containing the {@param bytes} {@param src} 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 {@param src}
-
valueOf
V valueOf(java.lang.String s, java.nio.charset.Charset charset)
return a value containing the bytes for the given string and charset
-
valueOf
V valueOf(java.util.UUID v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(boolean v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(byte v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(short v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(int v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(long v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(float v)
return a value with the bytes from {@param v}
-
valueOf
V valueOf(double v)
return a value with the bytes from {@param v}
-
convert
<V2> V convert(V2 src, ValueAccessor<V2> accessor)
Convert the data in {@param src} to {@param} {@param src} 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 {@param src}
-
allocate
V allocate(int size)
Allocate and return a {@param} instance of {@param size} bytes on the heap.
-
factory
ValueAccessor.ObjectFactory<V> factory()
returns theValueAccessor.ObjectFactoryfor the backing type {@param}
-
compare
static <L,R> int compare(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)lexicographically compare {@param left} to {@param right}
-
equals
static <L,R> boolean equals(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor)
-
-