use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class PartitionTest method testSingleColumn.
@Test
public void testSingleColumn() throws IOException {
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1);
PartitionUpdate update = new RowUpdateBuilder(cfs.metadata(), 5, "key1").clustering("c").add("val", "val1").buildUpdate();
CachedBTreePartition partition = CachedBTreePartition.create(update.unfilteredIterator(), FBUtilities.nowInSeconds());
DataOutputBuffer bufOut = new DataOutputBuffer();
CachedPartition.cacheSerializer.serialize(partition, bufOut);
CachedPartition deserialized = CachedPartition.cacheSerializer.deserialize(new DataInputBuffer(bufOut.getData()));
assert deserialized != null;
assert deserialized.metadata().name.equals(CF_STANDARD1);
assert deserialized.partitionKey().equals(partition.partitionKey());
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class ReadResponseTest method roundTripSerialization.
private void roundTripSerialization(ReadResponse response, int version) {
try {
DataOutputBuffer out = new DataOutputBuffer();
ReadResponse.serializer.serialize(response, out, version);
DataInputBuffer in = new DataInputBuffer(out.buffer(), false);
ReadResponse deser = ReadResponse.serializer.deserialize(in, version);
if (version < MessagingService.VERSION_40) {
assertFalse(deser.mayIncludeRepairedDigest());
// even though that means they should never be used, verify that the default values are present
assertEquals(ByteBufferUtil.EMPTY_BYTE_BUFFER, deser.repairedDataDigest());
assertTrue(deser.isRepairedDigestConclusive());
} else {
assertTrue(deser.mayIncludeRepairedDigest());
assertEquals(response.repairedDataDigest(), deser.repairedDataDigest());
assertEquals(response.isRepairedDigestConclusive(), deser.isRepairedDigestConclusive());
}
} catch (IOException e) {
fail("Caught unexpected IOException during SerDe: " + e.getMessage());
}
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class StandardAnalyzer method reset.
public void reset(ByteBuffer input) {
this.next = null;
Reader reader = new InputStreamReader(new DataInputBuffer(input, false), StandardCharsets.UTF_8);
scanner.yyreset(reader);
this.inputReader = reader;
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class DurationSerializer method deserialize.
public <V> Duration deserialize(V value, ValueAccessor<V> accessor) {
if (accessor.isEmpty(value))
return null;
try (// TODO: make a value input buffer
DataInputBuffer in = new DataInputBuffer(accessor.toBuffer(value), true)) {
int months = (int) in.readVInt();
int days = (int) in.readVInt();
long nanoseconds = in.readVInt();
return Duration.newInstance(months, days, nanoseconds);
} catch (IOException e) {
// this should never happen with a DataInputBuffer
throw new AssertionError("Unexpected error", e);
}
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class DurationSerializer method validate.
public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException {
if (accessor.size(value) < 3)
throw new MarshalException(String.format("Expected at least 3 bytes for a duration (%d)", accessor.size(value)));
try (// FIXME: value input buffer
DataInputBuffer in = new DataInputBuffer(accessor.toBuffer(value), true)) {
long monthsAsLong = in.readVInt();
long daysAsLong = in.readVInt();
long nanoseconds = in.readVInt();
if (!canBeCastToInt(monthsAsLong))
throw new MarshalException(String.format("The duration months must be a 32 bits integer but was: %d", monthsAsLong));
if (!canBeCastToInt(daysAsLong))
throw new MarshalException(String.format("The duration days must be a 32 bits integer but was: %d", daysAsLong));
int months = (int) monthsAsLong;
int days = (int) daysAsLong;
if (!((months >= 0 && days >= 0 && nanoseconds >= 0) || (months <= 0 && days <= 0 && nanoseconds <= 0)))
throw new MarshalException(String.format("The duration months, days and nanoseconds must be all of the same sign (%d, %d, %d)", months, days, nanoseconds));
} catch (IOException e) {
// this should never happen with a DataInputBuffer
throw new AssertionError("Unexpected error", e);
}
}
Aggregations