Skip to content

feat: construct Zenoh IDs from byte arrays - #819

Closed
milyin wants to merge 2 commits into
mainfrom
feat/id-from-bytes
Closed

milyin wants to merge 2 commits into
mainfrom
feat/id-from-bytes

Conversation

@milyin

@milyin milyin commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Add a validated, idiomatic constructor for reconstructing zenoh::Id from decoded bytes. The existing interop::into_copyable_cpp_obj<Id>(z_id_t) conversion remains available; the new explicit Id(const std::array<uint8_t, 16>&, ZResult* = nullptr) constructor provides validation through the usual C++ error convention.

The constructor copies the 16 bytes in the same least-significant-byte-first order returned by bytes(). It rejects all-zero IDs with Z_EINVAL, matching Rust's non-zero ID requirement. With an error pointer, a failed construction leaves a zero placeholder that must not be used as a valid ID. The constructor is documented as unstable, consistent with Id. This adds no members and preserves the wrapper's size and alignment.

Add operator!= alongside operator== so C++17 callers can compare decoded identities directly, for example token.subject != remote.

Universal tests cover byte round trips, source-storage independence, copy/equality/inequality behavior, byte order and boundary values, and zero-ID errors with and without an error pointer. Existing CI automatically builds the new test for both backends.

Validation on macOS: ID tests and strict-warning checks passed with zenoh-c and zenoh-pico, each with exceptions enabled and with -fno-exceptions. clang-format 18 and git diff --check passed.

milyin added 2 commits October 3, 2026 17:50
Signed-off-by: Michael Ilyin <milyin@gmail.com>
Signed-off-by: Michael Ilyin <milyin@gmail.com>
@milyin milyin closed this Oct 3, 2026
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