Documentation
¶
Overview ¶
Package events-nested-binary demonstrates the Phase 2 "one struct, one call" merge-field convenience for MQTT/event channels (api/events + adapters/mqtt5) — the pub/sub mirror of examples/rest-nested-binary.
Two things worth proving here, exactly like the REST case:
- Nested struct composition — the payload is built from sub-structs (Meta for the topic-derived field, Value for the body) instead of flat top-level fields. events.NewTopicParam's get/set are plain closures, so nested access needs zero framework changes.
- Non-JSON payload formats — format.Gob composes with topic merge fields exactly like JSON/YAML/TOML would, since payload decode/ encode is completely orthogonal to var-merge.
This example is transport-agnostic — it calls the same primitives adapters/mqtt5's Subscribe/PublishHandle call internally (ChannelHandle.DecodeMerged and codex.EncodeVars via MergeFields), so it runs without a broker connection. See adapters/mqtt5/adapter_test.go's TestPublishHandleSubscribe_NestedGobPayload_RoundTrip for the full live-wiring version (via Subscribe/PublishHandle against a fake broker).
Run with: go run ./examples/events-nested-binary