Skip to content

Parameters processing API#4

Merged
milyin merged 2 commits into
mainfrom
parameters-oracle
Jul 18, 2026
Merged

Parameters processing API#4
milyin merged 2 commits into
mainfrom
parameters-oracle

Conversation

@milyin

@milyin milyin commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Selector-parameters processing as regular zenoh-flat API — the translatable mirror of zenoh::query::Parameters, per the crate's charter of covering the main zenoh API in a form any language binding can consume. Parameters travel as the plain a=b;c=d|e;f=g string; every operation takes and returns strings, with exact zenoh semantics (construction ignores trailing ;/=/|, entries split on ;, key/value on the first =, no percent-decoding, first-match-wins lookup, normalized rebuild on mutation).

Dedicated src/base/query/parameters.rs module, full struct mirror:

fn mirrors
parameters_get(s, k) -> Option<String> Parameters::get
parameters_values(s, k) -> Vec<String> Parameters::values (|-split; empty when absent)
parameters_contains_key(s, k) -> bool Parameters::contains_key
parameters_insert(s, k, v) -> String Parameters::insert (resulting string; read the old value with parameters_get first — the tuple return does not translate)
parameters_remove(s, k) -> String Parameters::remove (ditto)
parameters_extend(s, other) -> String Parameters::extend (other's values win)
parameters_is_well_formed(s) -> bool is_well_formed

Consumers: zenoh-flat-c wraps these directly as its C parameters API; zenoh-flat-jni declares them, while the JVM SDKs run the same semantics in pure Kotlin on their production path (crossing JNI per string operation is expensive — a JNI adaptation, not a zenoh-flat design choice) and verify the correspondence against these functions in tests (which is how the remove bug fixed in eclipse-zenoh/zenoh#2687 was found).

Companions: ZettaScaleLabs/zenoh-flat-jni#9, zenoh-flat-c PR, eclipse-zenoh/zenoh-java#492, eclipse-zenoh/zenoh-kotlin#670.

🤖 Generated with Claude Code

parameters_get / parameters_insert / parameters_remove /
parameters_is_well_formed: thin #[prebindgen] wrappers over
zenoh::query::Parameters. They give downstream bindings a native oracle to
correspondence-test pure-JVM/pure-target parameter parsing against (the
production parse stays on the binding side with zero FFI crossings), and
mirror zenoh-c's parameter-utility surface.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…Parameters

Rework the parameters functions from a verification-only framing into
regular zenoh-flat API, in line with the crate's charter: cover the main
zenoh API in translatable form, usable from any language binding for real
parameter processing (zenoh-flat-c wraps them directly; the JVM bindings
reimplement the semantics in pure Kotlin because crossing JNI per string
operation is expensive — a JNI peculiarity, not a design choice — and verify
the correspondence against these functions in tests).

Move the functions to a dedicated src/base/query/parameters.rs module and
complete the struct mirror: parameters_values ('|'-separated value list),
parameters_contains_key, and parameters_extend join get/insert/remove/
is_well_formed. insert/remove return the resulting string; the replaced
value, when needed, is parameters_get before mutating (the Rust tuple return
does not translate).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@milyin milyin changed the title Expose native parameters oracle functions Parameters processing API Jul 18, 2026
@milyin
milyin merged commit 1ece3df into main Jul 18, 2026
26 checks passed
milyin added a commit to ZettaScaleLabs/zenoh-flat-jni that referenced this pull request Jul 18, 2026
* Shared string-backed Parameters + native oracle declarations

Selector parameters get ONE pure-Kotlin implementation in the shared tier
(kotlin/io/zenoh/jni/query/Parameters.kt), mirroring Rust's
zenoh-protocol/core/parameters.rs exactly: string-backed state, ';'-split
iteration skipping empty chunks, first-'=' key/value split, no
percent-decoding, infallible construction, first-match-wins get, insert and
remove normalizing the string, last-wins map conversion. Both SDKs
(zenoh-java, zenoh-kotlin) reduce their io.zenoh.query.Parameters to thin
facades over it — ending the duplicated (and Rust-divergent) per-SDK parsers.
No JNI crossing on any production path.

Declare the zenoh-flat parameters_get/insert/remove/is_well_formed oracle
externs (io.zenoh.jni.query free functions): used only by the SDKs'
correspondence tests, per the rule that a pure-JVM reimplementation of native
semantics must be validated against the native oracle.

Companions: ZettaScaleLabs/zenoh-flat#4 (oracle fns, merges first),
zenoh-java / zenoh-kotlin facade PRs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Parameters.remove: follow the documented Rust contract, note the upstream bug

Empirical probe of zenoh's parameters::remove shows an iterator-consumption
bug: 'find' advances past every entry up to and including the first match
before 'filter' builds the result, so entries PRECEDING the match are dropped
('b=2;a=1;c=3' remove 'a' -> 'c=3') and removing an absent key erases the
whole string. The shared implementation keeps the documented "preserving the
insertion order" semantics instead; the divergence is pinned by a canary in
zenoh-java's ParametersCorrespondenceTest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Parameters: trim trailing separators at construction, as Rust does

The correspondence test caught two divergences from the native oracle
(get("") on "=", insert after trailing '=' runs): Rust's Parameters::from
trim_end_matches ';', '=', '|' before storing the string. Mirror it in
fromString.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Declare the full zenoh-flat parameters API; reframe the JVM adaptation

parameters_values / parameters_contains_key / parameters_extend join the
declarations — the complete parameters-processing API of zenoh-flat, regular
any-language API (zenoh-flat-c wraps it directly). The JVM SDKs run the same
semantics in pure Kotlin on their production path because crossing JNI per
string operation is expensive — a JNI peculiarity, not a zenoh-flat design
choice — and verify the correspondence in tests; build.rs comment and the
shared Parameters KDoc now say exactly that.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: pin zenoh-flat to merged main (parameters API, #4)

The previous pin (bb410ccb) long predates the parameters functions, so the
new declarations could not resolve in CI. Local regen against 1ece3df is
byte-identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant