encodeKey static method

Uint8List encodeKey(
  1. String key
)

Encodes a user key, rejecting the reserved internal key space.

Implementation

static Uint8List encodeKey(String key) {
  if (key.isEmpty) {
    throw const InvalidKeyException('Database keys must not be empty');
  }
  final Uint8List bytes = Uint8List.fromList(utf8.encode(key));
  if (bytes[0] == 0x00) {
    throw InvalidKeyException(
      'Key ${Redaction.key(key)} starts with the reserved byte 0x00, which '
      'is used by ReaxDB internal keys',
    );
  }
  return bytes;
}