Actually, you can use Bytes.readByteArray(in) and Bytes.writeByteArray(out, keyBytes) and this uses vints.