Package com.marksayson.deletionchecker
Class IdentifierCodec
java.lang.Object
com.marksayson.deletionchecker.IdentifierCodec
Converts identifier strings to the raw bytes used for storage and lookup, enforcing the dataset
format's identifier constraints in the process.
An identifier is valid when it is non-null, non-empty, encodes to at most
64 bytes in UTF-8, and contains no unpaired UTF-16 surrogate. A
surrogate is one half of the two-char pair Java uses to hold a code point above U+FFFF;
a half without its partner is unpaired and represents no character. Unpaired surrogates are
rejected rather than encoded: the UTF-8 encoder would substitute U+FFFD for them, so two distinct
caller identifiers could otherwise collide onto the same stored bytes.
No Unicode normalization is performed — comparison is exact-byte, so callers must supply identifiers exactly as issued by the authoritative source.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum length, in UTF-8 encoded bytes, of a valid identifier. -
Method Summary
-
Field Details
-
MAX_IDENTIFIER_BYTES
public static final int MAX_IDENTIFIER_BYTESMaximum length, in UTF-8 encoded bytes, of a valid identifier. Comfortably fits a canonical hyphenated UUID (36 bytes) with headroom for namespaced or composite keys; matches the entity-type name cap. Nothing in the binary format or lookup path depends on the value.- See Also:
-
-
Method Details
-
encode
Validatesidentifierand returns its UTF-8 encoding.- Parameters:
identifier- the identifier to encode- Returns:
- the UTF-8 bytes of
identifier, never more than 64 bytes long - Throws:
IllegalArgumentException- ifidentifieris null, empty, contains an unpaired surrogate, or encodes to more than 64 bytes
-