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'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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceCreates db objects using the given accessors value type. -
Method Summary
Modifier and TypeMethodDescriptionallocate(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> intcompare(V left, VR right, ValueAccessor<VR> accessorR) lexicographically compare tointcompareByteArrayTo(byte[] left, V right) compare a byte array on the left with a on the right}intcompareByteBufferTo(ByteBuffer left, V right) compare a byte buffer on the left with a on the right}<V2> Vconvert(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 ofintcopyByteArrayTo(byte[] src, int srcOffset, V dst, int dstOffset, int size) copies a byte array into this accessors value.intcopyByteBufferTo(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 bytes from the value, starting at the offset into the value, starting at the offset , using the accessorV[]createArray(int length) allocate an instance of the accessors backing typevoidupdates with bytes from the contents of starting at offsetdefault voidupdates with te contents ofempty()return a value with a length of 0static <L,R> boolean equals(L left, ValueAccessor<L> leftAccessor, R right, ValueAccessor<R> rightAccessor) factory()returns theValueAccessor.ObjectFactoryfor the backing typedefault booleangetBoolean(V value, int offset) returns a boolean from offsetbytereturns a byte from offsetdoublefloatintreturns an int from offsetlongreturns a long from offsetshortreturns a short from offsetintgetUnsignedShort(V value, int offset) returns an unsigned short from offsetdefault longgetUnsignedVInt(V value, int offset) default intgetUnsignedVInt32(V value, int offset) default longdefault intdefault intdefault booleandefault booleanisEmptyFromOffset(V value, int offset) intwrites the byte value to at offsetdefault intdefault intintwrites the float value to at offsetintwrites the int value to at offsetintwrites the long value to at offsetintwrites the short value to at offsetdefault intputUnsignedVInt(V dst, int offset, long value) default intputUnsignedVInt32(V dst, int offset, int value) default intdefault intread(DataInputPlus in, int length) Reads a value of bytes fromdefault intintdefault 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 prefixReturns a value with the contents of from to .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[]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[]returns a byte[] with bytes copied from the contents of starting at offset .returns a TimeUUID from offset 0returns 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 bytebufferbytereturns a byte from offset 0doublereturns a double from offset 0floatreturns a float from offset 0float[]toFloatArray(V value, int dimension) returns a float[] from offset 0intreturns an int from offset 0longreturns a long from offset 0shortreturns a short from offset 0default StringtoTimeUUID(V value) returns a TimeUUID from offset 0returns a UUID from offset 0valueOf(boolean v) return a value with the bytes fromvalueOf(byte v) return a value with the bytes fromvalueOf(byte[] bytes) return a value containing the Caller should assume that modifying the returned value will also modify the contents ofvalueOf(double v) return a value with the bytes fromvalueOf(float v) return a value with the bytes fromvalueOf(int v) return a value with the bytes fromvalueOf(long v) return a value with the bytes fromvalueOf(short v) return a value with the bytes fromreturn a value containing the bytes for the given string and charsetvalueOf(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 ofreturn a value with the bytes fromvoidwrite(V value, 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 Details
-
size
- Returns:
- the size of the given value
-
sizeWithVIntLength
serializes size including a vint length prefix -
sizeWithShortLength
serialized size including a short length prefix -
remaining
-
isEmpty
- Returns:
- true if the size of the given value is zero, false otherwise
-
sizeFromOffset
- Returns:
- the number of bytes remaining in the value from the given offset
-
isEmptyFromOffset
- Returns:
- true if there are no bytes present after the given offset, false otherwise
-
createArray
allocate an instance of the accessors backing type- Parameters:
length- size of backing typ to allocate
-
write
Write the contents of the given value into the a DataOutputPlus- Throws:
IOException
-
writeWithVIntLength
- Throws:
IOException
-
write
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
copies a byte array into this accessors value. -
copyByteBufferTo
copies a byte buffer into this accessors value. -
digest
updates with bytes from the contents of starting at offset -
digest
updates with te contents of -
read
Reads a value of bytes from- Throws:
IOException
-
slice
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
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
lexicographically compare to- Type Parameters:
VR- backing type of
-
compareByteArrayTo
compare a byte array on the left with a on the right} -
compareByteBufferTo
compare a byte buffer on the left with a on the right} -
hashCode
-
toBuffer
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
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
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
- Throws:
CharacterCodingException
-
toString
- Throws:
CharacterCodingException
-
toHex
-
getBoolean
returns a boolean from offset -
toByte
returns a byte from offset 0 -
getByte
returns a byte from offset -
toShort
returns a short from offset 0 -
getShort
returns a short from offset -
getUnsignedShort
returns an unsigned short from offset -
toInt
returns an int from offset 0 -
getInt
returns an int from offset -
getUnsignedVInt
-
getUnsignedVInt32
-
getVInt
-
getVInt32
-
getFloat
-
getDouble
-
toLong
returns a long from offset 0 -
getLong
returns a long from offset -
toFloat
returns a float from offset 0 -
toDouble
returns a double from offset 0 -
toUUID
returns a UUID from offset 0 -
toTimeUUID
returns a TimeUUID from offset 0 -
toBallot
returns a TimeUUID from offset 0 -
toFloatArray
returns a float[] from offset 0 -
putByte
writes the byte value to at offset- Returns:
- the number of bytes written to
-
putShort
writes the short value to at offset- Returns:
- the number of bytes written to
-
putInt
writes the int value to at offset- Returns:
- the number of bytes written to
-
putLong
writes the long value to at offset- Returns:
- the number of bytes written to
-
putFloat
writes the float value to at offset- Returns:
- the number of bytes written to
-
putBytes
-
putBytes
-
putUnsignedVInt
-
putUnsignedVInt32
-
putVInt
-
putVInt32
-
empty
V empty()return a value with a length of 0 -
valueOf
return a value containing the Caller should assume that modifying the returned value will also modify the contents of -
valueOf
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
return a value containing the bytes for the given string and charset -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
valueOf
return a value with the bytes from -
convert
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
Allocate and return a instance of bytes on the heap. -
factory
ValueAccessor.ObjectFactory<V> factory()returns theValueAccessor.ObjectFactoryfor 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)
-