public DynamicCompositeParserImpl(ByteBuffer bb) { this.composite = DynamicComposite.fromByteBuffer(bb); }
@Override public DirectedEdge fromByteBuffer( final ByteBuffer byteBuffer ) { DynamicComposite composite = DynamicComposite.fromByteBuffer( byteBuffer ); Preconditions.checkArgument( composite.size() == 3, "Composite should have 3 elements" ); //return the version final long timestamp = composite.get( 0, LONG_SERIALIZER ); //parse our id final Id id = ID_COL_SERIALIZER.fromComposite( composite, 1 ); return new DirectedEdge( id, timestamp ); }
@Override public EntityVersion fromByteBuffer(final ByteBuffer byteBuffer) { // would use Composites.newDynamicCompositeParser(byteBuffer) but it is not implemented DynamicComposite composite = DynamicComposite.fromByteBuffer(byteBuffer); Preconditions.checkArgument(composite.size() == 3, "Composite should have 3 elements"); final UUID version = composite.get( 0, UUIDSerializer.get() ); final UUID entityId = composite.get( 1, UUIDSerializer.get() ); final String entityType = composite.get( 2, StringSerializer.get() ); return new EntityVersion( new SimpleId( entityId, entityType ), version); }
@Override public Shard fromByteBuffer( final ByteBuffer byteBuffer ) { DynamicComposite composite = DynamicComposite.fromByteBuffer( byteBuffer ); Preconditions.checkArgument( composite.size() == 5 || composite.size() == 6, "Composite should 5 elements" ); final byte version = composite.get(0, BYTE_SERIALIZER); final long shardIndex = composite.get( 1, LONG_SERIALIZER ); final long shardCreated = composite.get( 2, LONG_SERIALIZER ); final DirectedEdge shardEnd = composite.get( 3, EDGE_SERIALIZER); final boolean isCompacted = composite.get( 4, BOOLEAN_SERIALIZER); final Shard shard = new Shard(shardIndex, shardCreated, isCompacted); shard.setShardEnd(Optional.fromNullable(shardEnd)); if( composite.size() == 6){ final boolean isDeleted = composite.get( 5, BOOLEAN_SERIALIZER); shard.setDeleted(isDeleted); } return shard; }