events-nested-binary

command
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

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:

  1. 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.
  2. 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL