TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>>, TypeCodec.AbstractMapCodec<K,V>, TypeCodec.AbstractTupleCodec<T>, TypeCodec.AbstractUDTCodec<T>, TypeCodec.PrimitiveBooleanCodec, TypeCodec.PrimitiveByteCodec, TypeCodec.PrimitiveDoubleCodec, TypeCodec.PrimitiveFloatCodec, TypeCodec.PrimitiveIntCodec, TypeCodec.PrimitiveLongCodec, TypeCodec.PrimitiveShortCodec
Modifier and Type | Field and Description |
---|---|
protected TupleType |
definition |
Modifier | Constructor and Description |
---|---|
protected |
AbstractTupleCodec(TupleType definition,
Class<T> javaClass) |
protected |
AbstractTupleCodec(TupleType definition,
TypeToken<T> javaType) |
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(DataType cqlType)
Return
true if this codec is capable of deserializing the given cqlType . |
T |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type handled by this
codec. |
protected abstract T |
deserializeAndSetField(ByteBuffer input,
T target,
int index,
ProtocolVersion protocolVersion)
Deserialize an individual field and set it on an object, as part of deserializing the whole
object from a CQL tuple (see
deserialize(ByteBuffer, ProtocolVersion) ). |
String |
format(T value)
Format the given value as a valid CQL literal according to the CQL type handled by this codec.
|
protected abstract String |
formatField(T source,
int index)
Format an individual field in an object as a CQL literal, as part of formatting the whole
object (see
format(Object) ). |
protected abstract T |
newInstance()
Return a new instance of
T . |
T |
parse(String value)
Parse the given CQL literal into an instance of the Java type handled by this codec.
|
protected abstract T |
parseAndSetField(String input,
T target,
int index)
Parse an individual field and set it on an object, as part of parsing the whole object (see
parse(String) ). |
ByteBuffer |
serialize(T value,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type handled by this codec.
|
protected abstract ByteBuffer |
serializeField(T source,
int index,
ProtocolVersion protocolVersion)
Serialize an individual field in an object, as part of serializing the whole object to a CQL
tuple (see
serialize(Object, ProtocolVersion) ). |
accepts, accepts, accepts, ascii, bigint, blob, cboolean, cdouble, cfloat, cint, counter, custom, date, decimal, duration, getCqlType, getJavaType, inet, list, map, set, smallInt, time, timestamp, timeUUID, tinyInt, toString, tuple, userType, uuid, varchar, varint
protected final TupleType definition
public boolean accepts(DataType cqlType)
TypeCodec
true
if this codec is capable of deserializing the given cqlType
.public ByteBuffer serialize(T value, ProtocolVersion protocolVersion)
TypeCodec
Implementation notes:
null
input as the equivalent of an
empty collection.
serialize
in class TypeCodec<T>
value
- An instance of T; may be null
.protocolVersion
- the protocol version to use when serializing bytes
. In most
cases, the proper value to provide for this argument is the value returned by ProtocolOptions.getProtocolVersion()
(which is the protocol version in use by the driver).ByteBuffer
instance containing the serialized form of Tpublic T deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
TypeCodec
ByteBuffer
instance according to the CQL type handled by this
codec.
Implementation notes:
null
or a default value for the corresponding Java type, if
applicable;
null
; they should return
empty collections instead (the driver's default collection codecs all comply with this
rule).
ByteBuffer
should never be consumed by read operations that modify
its current position; if necessary, ByteBuffer.duplicate()
duplicate} it before
consuming.
deserialize
in class TypeCodec<T>
bytes
- A ByteBuffer
instance containing the serialized form of T; may be null
or empty.protocolVersion
- the protocol version to use when serializing bytes
. In most
cases, the proper value to provide for this argument is the value returned by ProtocolOptions.getProtocolVersion()
(which is the protocol version in use by the driver).public String format(T value)
TypeCodec
Implementors should take care of quoting and escaping the resulting CQL literal where
applicable. Null values should be accepted; in most cases, implementations should return the
CQL keyword "NULL"
for null
inputs.
Implementing this method is not strictly mandatory. It is used:
BuiltStatement
for a detailed explanation of when
this happens);
QueryLogger
, if parameter logging is enabled;
AggregateMetadata.asCQLQuery(boolean)
;
toString()
implementation of some objects (UDTValue
, TupleValue
, and the internal representation of a ROWS
response), which may
appear in driver logs.
public T parse(String value)
TypeCodec
Implementors should take care of unquoting and unescaping the given CQL string where
applicable. Null values and empty Strings should be accepted, as well as the string "NULL"
; in most cases, implementations should interpret these inputs has equivalent to a
null
reference.
Implementing this method is not strictly mandatory: internally, the driver only uses it to parse the INITCOND when building the metadata of an aggregate function (and in most cases it will use a built-in codec, unless the INITCOND has a custom type).
protected abstract T newInstance()
T
.T
.protected abstract ByteBuffer serializeField(T source, int index, ProtocolVersion protocolVersion)
serialize(Object, ProtocolVersion)
).source
- The object to read the field from.index
- The index of the field.protocolVersion
- The protocol version to use.null
if that field should be ignored.protected abstract T deserializeAndSetField(ByteBuffer input, T target, int index, ProtocolVersion protocolVersion)
deserialize(ByteBuffer, ProtocolVersion)
).input
- The serialized form of the field.target
- The object to set the field on.index
- The index of the field.protocolVersion
- The protocol version to use.target
, but if you're dealing with immutable types you'll need to return a different
instance.protected abstract String formatField(T source, int index)
format(Object)
).source
- The object to read the field from.index
- The index of the field.protected abstract T parseAndSetField(String input, T target, int index)
parse(String)
).input
- The String to parse the field from.target
- The value to write to.index
- The index of the field.target
, but if you're dealing with immutable types you'll need to return a different
instance.Copyright © 2012–2024. All rights reserved.