Search in sources :

Example 1 with Identifiable

use of com.yahoo.vespa.objects.Identifiable in project vespa by vespa-engine.

the class AggregationTestCase method serializeDeserialize1.

// --------------------------------------------------------------------------------
// 
// Everything below this point is helper functions.
// 
// --------------------------------------------------------------------------------
private static Identifiable serializeDeserialize1(Identifiable a) {
    BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer());
    a.serializeWithId(buf);
    buf.flip();
    Identifiable b = Identifiable.create(buf);
    assertEquals(a.getClass(), b.getClass());
    assertEquals(buf.getBuf().hasRemaining(), false);
    Identifiable c = b.clone();
    assertEquals(b.getClass(), c.getClass());
    BufferSerializer bb = new BufferSerializer(new GrowableByteBuffer());
    BufferSerializer cb = new BufferSerializer(new GrowableByteBuffer());
    b.serializeWithId(bb);
    c.serializeWithId(cb);
    assertEquals(bb.getBuf().limit(), cb.getBuf().limit());
    assertEquals(bb.position(), cb.position());
    bb.getBuf().flip();
    cb.getBuf().flip();
    for (int i = 0; i < bb.getBuf().limit(); i++) {
        assertEquals(bb.getBuf().get(), cb.getBuf().get());
    }
    return b;
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Identifiable(com.yahoo.vespa.objects.Identifiable)

Example 2 with Identifiable

use of com.yahoo.vespa.objects.Identifiable in project vespa by vespa-engine.

the class ExpressionTestCase method assertSerialize.

private static Identifiable assertSerialize(Identifiable node) {
    BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer());
    node.serializeWithId(buf);
    buf.flip();
    Identifiable created = Identifiable.create(buf);
    assertEquals(node, created);
    assertEquals(buf.getBuf().hasRemaining(), false);
    Identifiable cloned = created.clone();
    assertEquals(node, cloned);
    BufferSerializer createdBuffer = new BufferSerializer(new GrowableByteBuffer());
    BufferSerializer clonedBuffer = new BufferSerializer(new GrowableByteBuffer());
    created.serializeWithId(createdBuffer);
    cloned.serializeWithId(clonedBuffer);
    assertEquals(createdBuffer.getBuf().limit(), clonedBuffer.getBuf().limit());
    assertEquals(createdBuffer.position(), clonedBuffer.position());
    createdBuffer.getBuf().flip();
    clonedBuffer.getBuf().flip();
    for (int i = 0; i < createdBuffer.getBuf().limit(); i++) {
        assertEquals(createdBuffer.getBuf().get(), clonedBuffer.getBuf().get());
    }
    return created;
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Identifiable(com.yahoo.vespa.objects.Identifiable)

Aggregations

GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)2 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)2 Identifiable (com.yahoo.vespa.objects.Identifiable)2