public final class CodecUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
fromCqlDateToDaysSinceEpoch(long raw)
Convert from a raw CQL long representing a numeric DATE literal to the number of days since the
Epoch.
|
static long |
fromDaysSinceEpochToCqlDate(int days)
Convert the number of days since the Epoch into a raw CQL long representing a numeric DATE
literal.
|
static int |
fromSignedToUnsignedInt(int signed)
Converts an int into an "unsigned" int suitable to be written as a DATE value.
|
static int |
fromUnsignedToSignedInt(int unsigned)
Converts an "unsigned" int read from a DATE value into a signed int.
|
static ByteBuffer |
pack(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)
Read
length bytes from bb into a new ByteBuffer. |
static int |
readSize(ByteBuffer input,
ProtocolVersion version)
Utility method that reads a size value.
|
static ByteBuffer |
readValue(ByteBuffer input,
ProtocolVersion version)
Utility method that reads a value.
|
static void |
writeSize(ByteBuffer output,
int size,
ProtocolVersion version)
Utility method that writes a size value.
|
static void |
writeValue(ByteBuffer output,
ByteBuffer value,
ProtocolVersion version)
Utility method that writes a value.
|
public static ByteBuffer pack(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 readSize(ByteBuffer input, ProtocolVersion version)
input
- The ByteBuffer to read from.version
- The protocol version to use.public static void writeSize(ByteBuffer output, int size, ProtocolVersion version)
output
- The ByteBuffer to write to.size
- The collection size.version
- The protocol version to use.public static ByteBuffer readValue(ByteBuffer input, ProtocolVersion version)
input
- The ByteBuffer to read from.version
- The protocol version to use.public static void writeValue(ByteBuffer output, ByteBuffer value, ProtocolVersion version)
output
- The ByteBuffer to write to.value
- The value to write.version
- The protocol version to use.public static ByteBuffer readBytes(ByteBuffer bb, int length)
length
bytes from bb
into a new ByteBuffer.bb
- The ByteBuffer to read.length
- The number of bytes to read.public static int fromUnsignedToSignedInt(int unsigned)
The protocol encodes DATE values as unsigned ints with the Epoch in the middle of the range (2^31). This method handles the conversion from an "unsigned" to a signed int.
public static int fromSignedToUnsignedInt(int signed)
The protocol encodes DATE values as unsigned ints with the Epoch in the middle of the range (2^31). This method handles the conversion from a signed to an "unsigned" int.
public static int fromCqlDateToDaysSinceEpoch(long raw)
raw
- The CQL date value to convert.IllegalArgumentException
- if the value is out of range.public static long fromDaysSinceEpochToCqlDate(int days)
In CQL, numeric DATE literals are longs (unsigned integers actually) between 0 and 2^32 - 1, with the epoch in the middle; this method re-centers the epoch at 2^31.
days
- The number of days since the Epoch convert.Copyright © 2012–2023. All rights reserved.