private int decodeKeyValue(DataInputStream source, ByteBuffer buffer, int prevKeyOffset)
    throws IOException, EncoderBufferTooSmallException {
    int keyLength = ByteBufferUtils.readCompressedInt(source);
    int valueLength = ByteBufferUtils.readCompressedInt(source);
    int commonLength = ByteBufferUtils.readCompressedInt(source);
    int keyOffset;
    keyLength += commonLength;

    ensureSpace(buffer, keyLength + valueLength + KeyValue.ROW_OFFSET);

    buffer.putInt(keyLength);
    buffer.putInt(valueLength);

    // copy the prefix
    if (commonLength > 0) {
      keyOffset = buffer.position();
      ByteBufferUtils.copyFromBufferToBuffer(buffer, buffer, prevKeyOffset, commonLength);
    } else {
      keyOffset = buffer.position();
    }

    // copy rest of the key and value
    int len = keyLength - commonLength + valueLength;
    ByteBufferUtils.copyFromStreamToBuffer(buffer, source, len);
    return keyOffset;
  }
Compress key by storing size of common prefix with previous KeyValue and storing raw size of
rest. Format: 1-5 bytes: compressed key length minus prefix (7-bit encoding) 1-5 bytes:
compressed value length (7-bit encoding) 1-3 bytes: compressed length of common key prefix ...
bytes: rest of key (including timestamp) ... bytes: value In a worst case compressed KeyValue
will be three bytes longer than original.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/PrefixKeyDeltaEncoder.java