Skip to content

56 context aware deserializers#81

Merged
lxsaah merged 11 commits intomainfrom
56-context-aware-deserializers
Apr 10, 2026
Merged

56 context aware deserializers#81
lxsaah merged 11 commits intomainfrom
56-context-aware-deserializers

Conversation

@lxsaah
Copy link
Copy Markdown
Contributor

@lxsaah lxsaah commented Apr 8, 2026

Added

  • Context-Aware Deserializers (Design 026): Inbound connector deserializers can now receive a RuntimeContext<R> for platform-independent timestamps and logging
    • New .with_deserializer(|ctx, bytes| ...) API on InboundConnectorBuilder provides RuntimeContext<R> to deserialization closures
    • New .with_deserializer_raw(|bytes| ...) for plain bytes-only deserialization when context is unnecessary
    • DeserializerKind enum enforces mutual exclusivity between raw and context-aware deserializers
    • Router::route() propagates optional runtime context to context-aware routes
  • Design document: 026 (Context-Aware Deserializers)

Changed

  • aimdb-core: Breaking API changes to InboundConnectorLink, Router, and RouterBuilder to support DeserializerKind (see aimdb-core/CHANGELOG.md)
  • aimdb-mqtt-connector: Updated router dispatch for new route() signature
  • aimdb-knx-connector: Updated router dispatch for new route() signature
  • aimdb-websocket-connector: Updated router dispatch for new route() signature
  • All connector examples updated to use new .with_deserializer(|_ctx, bytes| ...) signature

lxsaah added 3 commits April 8, 2026 20:05
- Added support for context-aware deserialization by introducing `ContextDeserializerFn`.
- Updated `InboundConnectorBuilder` to include a context-aware deserializer method (`with_deserializer`).
- Renamed existing deserializer method to `with_deserializer_raw` for raw byte deserialization.
- Modified `Router::route` to accept an optional context parameter, allowing deserializers to access runtime context.
- Updated all relevant connectors (MQTT, KNX, WebSocket) to pass runtime context during message routing.
- Enhanced documentation to reflect the new deserialization capabilities and usage examples.
- Added a design document outlining the rationale and implementation details for context-aware deserializers.
…s and compatibility updates across connectors
@lxsaah lxsaah requested a review from Copilot April 8, 2026 20:24
@lxsaah lxsaah self-assigned this Apr 8, 2026
@lxsaah lxsaah added the 🏗️ core Core engine work label Apr 8, 2026
@lxsaah lxsaah linked an issue Apr 8, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements Design 026 (Context-Aware Deserializers), extending inbound connector deserialization so it can optionally receive a RuntimeContext<R> (for platform-independent time + logging) while retaining a raw bytes-only deserializer escape hatch.

Changes:

  • Adds DeserializerKind (Raw / Context) and updates routing/link plumbing to store and dispatch the appropriate deserializer variant.
  • Introduces .with_deserializer(|ctx, bytes| ...) (context-aware) and .with_deserializer_raw(|bytes| ...) (bytes-only) on InboundConnectorBuilder.
  • Updates connectors, tests, examples, and changelogs for the new API + Router::route(..., ctx) signature.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
examples/weather-mesh-demo/weather-hub/src/main.rs Updates example deserializers to new `
examples/tokio-mqtt-connector-demo/src/main.rs Updates example deserializers to new context-aware closure signature.
examples/tokio-knx-connector-demo/src/main.rs Updates example deserializers to accept _ctx.
examples/embassy-mqtt-connector-demo/src/main.rs Updates example deserializers to accept _ctx.
examples/embassy-knx-connector-demo/src/main.rs Updates example deserializers to accept _ctx.
docs/design/026-context-aware-deserializers.md Adds the design document describing the new API and plumbing.
CHANGELOG.md Documents the new feature and breaking changes at the repo level.
Cargo.lock Updates stm32-metapac git source reference.
aimdb-websocket-connector/src/session.rs Updates Router::route() call to new signature (currently passes None).
aimdb-websocket-connector/src/client/connector.rs Updates Router::route() call to new signature (currently passes None).
aimdb-websocket-connector/CHANGELOG.md Notes the router signature update.
aimdb-mqtt-connector/tests/topic_provider_tests.rs Updates test deserializer closure to accept _ctx.
aimdb-mqtt-connector/src/tokio_client.rs Updates router dispatch signature (currently passes None).
aimdb-mqtt-connector/src/embassy_client.rs Updates router dispatch signature (currently passes None).
aimdb-mqtt-connector/CHANGELOG.md Notes the router signature update.
aimdb-knx-connector/tests/topic_provider_tests.rs Updates test deserializer closure to accept _ctx.
aimdb-knx-connector/src/tokio_client.rs Updates router dispatch signature (currently passes None).
aimdb-knx-connector/src/embassy_client.rs Updates router dispatch signature (currently passes None).
aimdb-knx-connector/CHANGELOG.md Notes the router signature update.
aimdb-core/src/typed_api.rs Adds with_deserializer_raw, adds context-aware with_deserializer, and resolves DeserializerKind in finish().
aimdb-core/src/router.rs Routes via DeserializerKind and adds optional runtime context parameter to route(), plus new tests.
aimdb-core/src/connector.rs Introduces ContextDeserializerFn + DeserializerKind, updates InboundConnectorLink to store DeserializerKind.
aimdb-core/src/builder.rs Updates collect_inbound_routes() return type to include DeserializerKind.
aimdb-core/CHANGELOG.md Documents the new feature and breaking API changes in core.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aimdb-mqtt-connector/src/tokio_client.rs
Comment thread aimdb-mqtt-connector/src/embassy_client.rs
Comment thread aimdb-knx-connector/src/tokio_client.rs
Comment thread aimdb-knx-connector/src/embassy_client.rs
Comment thread aimdb-websocket-connector/src/session.rs
Comment thread aimdb-websocket-connector/src/client/connector.rs
Comment thread aimdb-core/src/router.rs
Comment thread aimdb-core/src/typed_api.rs
Comment thread docs/design/026-context-aware-deserializers.md Outdated
Comment thread aimdb-core/src/typed_api.rs
@lxsaah lxsaah marked this pull request as draft April 8, 2026 21:29
lxsaah and others added 7 commits April 8, 2026 21:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Updated outbound publishers in both Tokio and Embassy clients to utilize `SerializerKind`, enabling context-aware serialization with `db.runtime_any()`.
- Refactored serializer calls to support both raw and context-aware serializers, enhancing flexibility in serialization logic.
- Adjusted tests and examples to reflect the new serializer API, ensuring compatibility with the updated design.
@lxsaah lxsaah marked this pull request as ready for review April 10, 2026 13:29
@lxsaah lxsaah requested a review from Copilot April 10, 2026 13:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

aimdb-websocket-connector/src/lib.rs:58

  • The doc example in the client quick start still uses the old bytes-only .with_deserializer(|data| ...) signature. After this PR, .with_deserializer expects a (ctx, bytes) closure, so this example will not compile as written; update it to |_ctx, data| or switch to .with_deserializer_raw(|data| ...) depending on which behavior you want to demonstrate.
//!         reg.buffer(BufferCfg::SpmcRing { capacity: 100 })
//!             .link_to("ws-client://sensors/temp")
//!             .with_serializer_raw(|t| serde_json::to_vec(t).map_err(Into::into))
//!             .finish()
//!             .link_from("ws-client://config/threshold")
//!             .with_deserializer(|data| serde_json::from_slice(data))
//!             .finish();

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aimdb-core/src/router.rs
Comment thread aimdb-knx-connector/src/lib.rs
Comment thread aimdb-knx-connector/src/lib.rs
Comment thread aimdb-core/src/typed_api.rs
@lxsaah lxsaah merged commit b44abab into main Apr 10, 2026
7 checks passed
@lxsaah lxsaah deleted the 56-context-aware-deserializers branch April 10, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏗️ core Core engine work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context-aware deserializers

2 participants