Search in sources :

Example 6 with DataInputBuffer

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());
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) Test(org.junit.Test)

Example 7 with DataInputBuffer

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());
    }
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) IOException(java.io.IOException)

Example 8 with DataInputBuffer

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;
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 9 with DataInputBuffer

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);
    }
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) IOException(java.io.IOException)

Example 10 with DataInputBuffer

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);
    }
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) IOException(java.io.IOException)

Aggregations

DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)54 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)33 Test (org.junit.Test)23 IOException (java.io.IOException)14 ByteBuffer (java.nio.ByteBuffer)13 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)13 TableMetadata (org.apache.cassandra.schema.TableMetadata)6 Mutation (org.apache.cassandra.db.Mutation)5 UUID (java.util.UUID)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 DataOutputPlus (org.apache.cassandra.io.util.DataOutputPlus)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 InputStreamReader (java.io.InputStreamReader)3 Reader (java.io.Reader)3 ArrayList (java.util.ArrayList)3 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)3 ByteBuf (io.netty.buffer.ByteBuf)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)2