T
- The Java primitive array type this codec handlespublic abstract class AbstractPrimitiveArrayCodec<T> extends AbstractArrayCodec<T>
serialize(Object, ProtocolVersion)
and deserialize(ByteBuffer, ProtocolVersion)
for primitive arrays.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
Constructor and Description |
---|
AbstractPrimitiveArrayCodec(DataType.CollectionType cqlType,
Class<T> javaClass) |
Modifier and Type | Method and Description |
---|---|
T |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type handled by this
codec. |
protected abstract void |
deserializeElement(ByteBuffer input,
T array,
int index,
ProtocolVersion protocolVersion)
Read the
index th element of array from input . |
ByteBuffer |
serialize(T array,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type handled by this codec.
|
protected abstract void |
serializeElement(ByteBuffer output,
T array,
int index,
ProtocolVersion protocolVersion)
Write the
index th element of array to output . |
protected abstract int |
sizeOfComponentType()
Return the size in bytes of the array component type.
|
format, formatElement, newInstance, parse, parseElement
accepts, 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
public AbstractPrimitiveArrayCodec(DataType.CollectionType cqlType, Class<T> javaClass)
cqlType
- The CQL type. Must be a list type.javaClass
- The Java type. Must be an array class.public ByteBuffer serialize(T array, ProtocolVersion protocolVersion) throws InvalidTypeException
TypeCodec
Implementation notes:
null
input as the equivalent of an
empty collection.
serialize
in class TypeCodec<T>
array
- 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 TInvalidTypeException
- if the given value does not have the expected typepublic T deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException
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).InvalidTypeException
- if the given ByteBuffer
instance cannot be deserializedprotected abstract int sizeOfComponentType()
protected abstract void serializeElement(ByteBuffer output, T array, int index, ProtocolVersion protocolVersion)
index
th element of array
to output
.output
- The ByteBuffer to write to.array
- The array to read from.index
- The element index.protocolVersion
- The protocol version to use.protected abstract void deserializeElement(ByteBuffer input, T array, int index, ProtocolVersion protocolVersion)
index
th element of array
from input
.input
- The ByteBuffer to read from.array
- The array to write to.index
- The element index.protocolVersion
- The protocol version to use.Copyright © 2012–2020. All rights reserved.