Zenoh key expressions: validity, canonical form, and wildcard matching. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
npm install @pamoja/zenoh
This pulls in @pamoja/native, the compiled engine. npm install pamoja is the whole framework in one package.
The test that runs in CI, spliced here as it ran.
From bindings/node/guides/zenoh.ts:
import { keyexpr } from '@pamoja/zenoh'
// A key expression names a set of keys. `*` stands for exactly one chunk, so this selects
// the battery of any node, and not a battery nested deeper.
const anyNode = 'fleet/*/battery'
for (const key of ['fleet/n7/battery', 'fleet/n7/rack/battery']) {
console.log(`${anyNode} covers ${key}: ${keyexpr.matches(anyNode, key)}`)
}
// `**` stands for any number of chunks, including none, which is what a subscription
// covering a whole subtree wants.
console.log(`fleet/** covers a nested key: ${keyexpr.matches('fleet/**', 'fleet/n7/rack/battery')}`)
console.log(
`fleet/**/battery covers fleet/battery: ${keyexpr.matches('fleet/**/battery', 'fleet/battery')}`,
)
// Two expressions that select the same keys have one canonical form. Comparing or routing
// on the written form would treat these as different subscriptions.
const written = 'fleet/**/**/battery'
const canonical = keyexpr.canonize(written)
console.log(`${written} is canonical: ${keyexpr.isCanon(written)}, and canonizes to ${canonical}`)
// A malformed expression is rejected rather than canonized into something plausible.
const malformed = 'fleet//battery'
console.log(
`${malformed} is valid: ${keyexpr.isValid(malformed)},` +
` canonizes to ${keyexpr.canonize(malformed)}`,
)
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-zenoh |
reference, docs.rs, install |
| TypeScript | @pamoja/zenoh |
reference, install |
| Python | pamoja-zenoh |
reference, install |
| C# | Pamoja.Zenoh |
reference, install |
@pamoja/zenoh reference, every class, function, and type this package exports.MIT
Ergonomic facade over the generated Zenoh key-expression binding.
A key expression is how a Zenoh network addresses data: a slash-separated path that may carry the
*and**wildcards, so one subscriber names a whole subtree of a fleet rather than each node in it.Only the naming rules cross. Running a Zenoh session needs the std-only zenoh stack, which would land in every install, so it stays in the Rust crate.