Merged
Conversation
- 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.
…improved flexibility
…s and compatibility updates across connectors
Contributor
There was a problem hiding this comment.
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) onInboundConnectorBuilder. - 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… simplify context creation
… routes and missing routes
…t-aware deserializers
- 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.
Contributor
There was a problem hiding this comment.
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_deserializerexpects 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.
…across connectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
RuntimeContext<R>for platform-independent timestamps and logging.with_deserializer(|ctx, bytes| ...)API onInboundConnectorBuilderprovidesRuntimeContext<R>to deserialization closures.with_deserializer_raw(|bytes| ...)for plain bytes-only deserialization when context is unnecessaryDeserializerKindenum enforces mutual exclusivity between raw and context-aware deserializersRouter::route()propagates optional runtime context to context-aware routesChanged
InboundConnectorLink,Router, andRouterBuilderto supportDeserializerKind(see aimdb-core/CHANGELOG.md)route()signatureroute()signatureroute()signature.with_deserializer(|_ctx, bytes| ...)signature