@Override
  public ScopedRowKey<K> fromByteBuffer(final ByteBuffer byteBuffer) {
    final CompositeParser parser = Composites.newCompositeParser(byteBuffer);

    // read back the id
    final Id orgId = ID_SER.fromComposite(parser);

    final K value = keySerializer.fromComposite(parser);

    return new ScopedRowKey<K>(orgId, value);
  }
  @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();
  }
/**
 * Serializer for serializing CollectionScope + any type into row keys
 *
 * @author tnine
 */
public class ScopedRowKeySerializer<K> extends AbstractSerializer<ScopedRowKey<K>> {

  private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();

  /** The delegate serializer for the key */
  private final CompositeFieldSerializer<K> keySerializer;

  public ScopedRowKeySerializer(final CompositeFieldSerializer<K> keySerializer) {
    this.keySerializer = keySerializer;
  }

  @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 ScopedRowKey<K> fromByteBuffer(final ByteBuffer byteBuffer) {
    final CompositeParser parser = Composites.newCompositeParser(byteBuffer);

    // read back the id
    final Id orgId = ID_SER.fromComposite(parser);

    final K value = keySerializer.fromComposite(parser);

    return new ScopedRowKey<K>(orgId, value);
  }
}