Class KeyListEncoder

java.lang.Object
io.permazen.kv.util.KeyListEncoder

public final class KeyListEncoder extends Object
Serializes a sequence of byte[] arrays, or byte[] key/value pairs, using a simple key prefix compression scheme.

Keys are encoded/decoded by read() and write() in one of two forms:

  • total-length bytes...
  • -prefix-length suffix-length suffix-bytes ...
In the first form, the total-length is encoded using LongEncoder as a positive number and is followed by that many bytes consituting the key. In the second form, the length of the key prefix that matches the previous key is encoded as a negative value using LongEncoder, followed by the number of suffix bytes encoded via UnsignedIntEncoder, followed by that many suffix bytes.

Support for encoding and decoding an entire iteration of key/value pairs is supported via readPairs() and writePairs().