@Override public void toComposite( final CompositeBuilder builder, final EdgeIdTypeKey value ) { ID_SER.toComposite( builder, value.node ); builder.addString( value.edgeType ); }
@Override public void toComposite( final CompositeBuilder builder, final EdgeRowKey key ) { //add the row id to the composite ID_SER.toComposite( builder, key.sourceId ); builder.addString( key.edgeType ); ID_SER.toComposite( builder, key.targetId ); builder.addLong( key.shardId ); }
@Override public void toComposite( final CompositeBuilder builder, final EdgeIdTypeKey value ) { ID_SER.toComposite( builder, value.node ); builder.addString( value.edgeType ); }
@Override public void toComposite( final CompositeBuilder builder, final RowKey key ) { //add the row id to the composite ID_SER.toComposite( builder, key.nodeId ); builder.addString( key.edgeType ); builder.addLong( key.shardId ); }
@Override public void toComposite( final CompositeBuilder builder, final RowKeyType keyType ) { //add the row id to the composite ID_SER.toComposite( builder, keyType.nodeId ); builder.addString( keyType.edgeType ); builder.addString( keyType.idType ); builder.addLong( keyType.shardId ); }
@Override public ByteBuffer toByteBuffer( final ScopedRowKey<K> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); //add the key type keySerializer.toComposite( builder, scopedRowKey.getKey() ); return builder.build(); }
@Override public ByteBuffer toByteBuffer( final ScopedRowKey<CollectionPrefixedKey<K>> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); final CollectionPrefixedKey<K> key = scopedRowKey.getKey(); //add the scope's owner id to the composite ID_SER.toComposite( builder, key.getOwner() ); //add the scope's name builder.addString( key.getCollectionName() ); //add the key type keySerializer.toComposite( builder, key.getSubKey() ); //addOtherComponents( builder, scopedRowKey ); return builder.build(); }
@Override public ByteBuffer toByteBuffer( final BucketScopedRowKey<K> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); //add the bucket builder.addInteger( scopedRowKey.getBucketNumber() ); //add the key type keySerializer.toComposite( builder, scopedRowKey.getKey() ); return builder.build(); }
@Override public void toComposite( final CompositeBuilder builder, final DirectedEdgeMeta meta ) { final DirectedEdgeMeta.NodeMeta[] nodeMeta = meta.getNodes(); //add the stored value builder.addInteger( meta.getType().getStorageValue() ); final int length = nodeMeta.length; builder.addInteger( length ); for ( DirectedEdgeMeta.NodeMeta node : nodeMeta ) { ID_SER.toComposite( builder, node.getId() ); builder.addInteger( node.getNodeType().getStorageValue() ); } final String[] edgeTypes = meta.getTypes(); builder.addInteger( edgeTypes.length ); for ( String type : edgeTypes ) { builder.addString( type ); } }
@Test public void testSerialization() { Id testId = new SimpleId( "test" ); IdRowCompositeSerializer rowSerializer = IdRowCompositeSerializer.get(); final CompositeBuilder builder = Composites.newCompositeBuilder(); rowSerializer.toComposite( builder, testId ); final CompositeParser parser = Composites.newCompositeParser( builder.build() ); //now convert it back Id deserialized = rowSerializer.fromComposite( parser ); assertEquals( "Serialization works correctly", testId, deserialized ); }