public final class CodecUtils extends Object
TypeToken
instances.
This class is public because it is accessed from BuiltStatement
but its use by client code is not supported.
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
compose(ByteBuffer... buffers)
Utility method to assemble different routing key components into a single
ByteBuffer . |
static ByteBuffer[] |
convert(Object[] values,
ProtocolVersion protocolVersion,
CodecRegistry codecRegistry)
Utility method to serialize user-provided values.
|
static <T> com.google.common.reflect.TypeToken<List<T>> |
listOf(Class<T> eltType) |
static <T> com.google.common.reflect.TypeToken<List<T>> |
listOf(com.google.common.reflect.TypeToken<T> eltType) |
static <K,V> com.google.common.reflect.TypeToken<Map<K,V>> |
mapOf(Class<K> keyType,
Class<V> valueType) |
static <K,V> com.google.common.reflect.TypeToken<Map<K,V>> |
mapOf(com.google.common.reflect.TypeToken<K> keyType,
com.google.common.reflect.TypeToken<V> valueType) |
static ByteBuffer |
pack(List<ByteBuffer> buffers,
int elements,
ProtocolVersion version)
Utility method that "packs" together a list of
ByteBuffer s containing
serialized collection elements. |
static ByteBuffer |
readBytes(ByteBuffer bb,
int length) |
static int |
readCollectionSize(ByteBuffer input,
ProtocolVersion version)
Utility method that reads the collection size.
|
static ByteBuffer |
readCollectionValue(ByteBuffer input,
ProtocolVersion version) |
static <T> com.google.common.reflect.TypeToken<Set<T>> |
setOf(Class<T> eltType) |
static <T> com.google.common.reflect.TypeToken<Set<T>> |
setOf(com.google.common.reflect.TypeToken<T> eltType) |
public static <T> com.google.common.reflect.TypeToken<List<T>> listOf(com.google.common.reflect.TypeToken<T> eltType)
public static <T> com.google.common.reflect.TypeToken<Set<T>> setOf(com.google.common.reflect.TypeToken<T> eltType)
public static <K,V> com.google.common.reflect.TypeToken<Map<K,V>> mapOf(Class<K> keyType, Class<V> valueType)
public static <K,V> com.google.common.reflect.TypeToken<Map<K,V>> mapOf(com.google.common.reflect.TypeToken<K> keyType, com.google.common.reflect.TypeToken<V> valueType)
public static ByteBuffer[] convert(Object[] values, ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
This method is useful in situations where there is no metadata available and the underlying CQL type for the values is not known.
This situation happens when a SimpleStatement
or a BuiltStatement
(Query Builder) contain values;
in these places, the driver has no way to determine the right CQL type to use.
This method performs a best-effort heuristic to guess which codec to use. Note that this is not particularly efficient as the codec registry needs to iterate over the registered codecs until it finds a suitable one.
values
- The values to convert.protocolVersion
- The protocol version to use.codecRegistry
- The CodecRegistry
to use.public static ByteBuffer compose(ByteBuffer... buffers)
ByteBuffer
.
Mainly intended for statements that need to generate a routing key out of their current values.buffers
- the components of the routing key.public static ByteBuffer pack(List<ByteBuffer> buffers, int elements, ProtocolVersion version)
ByteBuffer
s containing
serialized collection elements.
Mainly intended for use with collection codecs when serializing collections.buffers
- the collection elementselements
- the total number of elementsversion
- the protocol version to usepublic static int readCollectionSize(ByteBuffer input, ProtocolVersion version)
input
- A ByteBuffer containing a serialized CQL collectionversion
- The protocol version to use.public static ByteBuffer readBytes(ByteBuffer bb, int length)
public static ByteBuffer readCollectionValue(ByteBuffer input, ProtocolVersion version)
Copyright © 2012–2015. All rights reserved.