Skip to content

Expose sequence length encoding and decoding in C++ - #817

Merged
milyin merged 4 commits into
mainfrom
feat/deserialize-sequence-length
Oct 22, 2026
Merged

milyin merged 4 commits into
mainfrom
feat/deserialize-sequence-length

Conversation

@milyin

@milyin milyin commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Applications can now write a sequence prefix with ext::Serializer::serialize_sequence_length() and read it with ext::Deserializer::deserialize_sequence_length(), then process elements individually. Decoders can enforce an application-defined limit before allocating a container.

Both methods process only the length prefix and follow the existing ZResult*/exception convention. With an error pointer, decoding failures return zero and set the result code; a successful empty sequence also returns zero with Z_OK. The serializer caller is responsible for writing the advertised number of elements. Existing container serializers and deserializers reuse these methods. The wire format is unchanged.

Tests cover manual sequence encoding compatible with container encoding, sequence elements and a following value, empty sequences, large length-only prefixes, and missing/truncated prefixes. Encoding is exercised with and without an error pointer; malformed prefixes are checked through both decoding error-reporting modes.

Validation

  • The original decoding changes passed serialization CTests on macOS with the repository's pinned zenoh-c and zenoh-pico dependencies, with and without exceptions.
  • The encoding addition passed serialization CTests on macOS for both backends, with and without -fno-exceptions, using cached Zetta dependencies. For zenoh-c, unstable APIs were disabled to avoid an unrelated Link API mismatch between the cached dependency and this revision.
  • clang-format 18.1.3 and git diff --check passed.

Signed-off-by: Michael Ilyin <milyin@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation preserves existing behavior and comprehensively tests the new API contract.

Review effort: Balanced
Findings: None

What changed in this PR

Adds safe sequence-length prefix decoding to the C++ deserialization API.

Changes:

  • Exposes Deserializer::deserialize_sequence_length().
  • Reuses it across container deserializers.
  • Tests normal, empty, large, missing, and truncated prefixes.
File Description
include/​zenoh/​api/​ext/​serialization.hxx Adds the API and integrates it with container decoding.
tests/​universal/​serialization.cxx Covers successful and failing prefix decoding.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@milyin milyin changed the title Expose sequence length decoding in C++ Deserializer Expose sequence length encoding and decoding in C++ Oct 22, 2026
@milyin
milyin merged commit e531522 into main Oct 22, 2026
27 checks passed
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.

3 participants