use of com.datastax.oss.driver.api.core.type.codec.PrimitiveByteCodec in project java-driver by datastax.
the class GettableByIndex method getByte.
/**
* Returns the {@code i}th value as a Java primitive byte.
*
* <p>By default, this works with CQL type {@code tinyint}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Byte.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default byte getByte(int i) {
DataType cqlType = getType(i);
TypeCodec<Byte> codec = codecRegistry().codecFor(cqlType, Byte.class);
if (codec instanceof PrimitiveByteCodec) {
return ((PrimitiveByteCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Byte value = get(i, codec);
return value == null ? 0 : value;
}
}
use of com.datastax.oss.driver.api.core.type.codec.PrimitiveByteCodec in project java-driver by datastax.
the class SettableByIndex method setByte.
/**
* Sets the {@code i}th value to the provided Java primitive byte.
*
* <p>By default, this works with CQL type {@code tinyint}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Boolean.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setByte(int i, byte v) {
DataType cqlType = getType(i);
TypeCodec<Byte> codec = codecRegistry().codecFor(cqlType, Byte.class);
return (codec instanceof PrimitiveByteCodec) ? setBytesUnsafe(i, ((PrimitiveByteCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
Aggregations