A key codec is used to encode and decode keys before they are stored
or returned to the client in a Key-Value store.
The codec transforms each token (part between dots) in a key string, allowing
for custom encoding/decoding while preserving the hierarchical structure of NATS subjects.
Purpose
Enables custom encoding of keys (e.g., base64, encryption, or custom mappings)
Preserves the ability to use NATS subject wildcards for filtering
Ensures proper storage and retrieval of keys with special characters
Requirements
Must preserve the dot-delimited structure of NATS subjects
Must handle wildcard tokens (* and >) without modification
Must be able to properly encode/decode each token independently
Must be deterministic (same input always produces same output)
Example
// Original key: "users.john.profile" // Encoded key: "dXNlcnM=.am9obg==.cHJvZmlsZQ=="
// With wildcards (these remain unchanged): // Original key: "users.*.profile" // Encoded key: "dXNlcnM=.*.cHJvZmlsZQ=="
Note: This codec is specifically for subject-compatible transformations of keys,
not for general data transformation or serialization. It operates at the token level
to preserve NATS subject semantics, ensuring that filtering, watches, and other
subject-based operations continue to work properly.
A key codec is used to encode and decode keys before they are stored or returned to the client in a Key-Value store.
The codec transforms each token (part between dots) in a key string, allowing for custom encoding/decoding while preserving the hierarchical structure of NATS subjects.
Purpose
Requirements
*and>) without modificationExample
Note: This codec is specifically for subject-compatible transformations of keys, not for general data transformation or serialization. It operates at the token level to preserve NATS subject semantics, ensuring that filtering, watches, and other subject-based operations continue to work properly.