Skip to main content

Local memory

LocalMemoryBroker is a complete broker that runs inside one firmware. It comes with the memory feature of ruststream next to embassy (or compio without tokio), and it is the bus of the embassy runtime, as the memory broker is of the tokio one. It runs on any executor, and it reads no clock. On embassy alone its types are not Send, and sharing its state costs no atomic. Next to compio it shares by Arc and guards its state with a critical section, so its types are Send, and each access to the bus takes that lock. The embassy-memory template of cargo generate starts on it.

ruststream = { version = "0.8", default-features = false, features = ["embassy", "memory", "macros", "postcard"] }

What it supports​

AreaLocalMemoryBroker
Subscriptionsa topic by name (#[subscriber("sensors/temp")] or LocalMemorySource)
Deliverya subscription receives what is published after it opened
Settlementack and nack with or without requeue; each delivery reports its delivery count; retry_after and dead letters go through copies the runtime publishes, held in the mount's .retry_capacity::<CAP>()
Batches&[T] handlers, up to the mount's batch size; a batch never holds more than one subscription holds
Publishingplain publishes and replies through LocalMemoryPublish
Capacityeach subscription holds N messages, the broker's const parameter, counting the ones in a handler's hands; a publish to a full subscription returns LocalMemoryError::Full
Testingthe bus is its own in-process mode: the embedded TestApp runs the service's app on it on the host

The bus has a form for each build of the framework:

With allocWithout alloc
Where the bus liveson the heapin a LocalMemoryBus the board declares as a static
ConstructorLocalMemoryBroker::<N>::new()LocalMemoryBroker::<N>::new(&BUS)
Payloadany sizeat most PAYLOAD bytes, 64 unless the bus names another
Subscriptions open at onceany numberat most SUBSCRIPTIONS, 8 unless the bus names another
A batcha Vec of deliveriesa fixed slot of at most N deliveries
Allocationsthe bus and its channelsnone: the build needs no allocator

The fixed bus sits behind a critical section, so the binary supplies the critical-section implementation. On a core without compare-and-swap, such as a Cortex-M0+, the firmware also gives portable-atomic its critical-section feature. A bus that holds no message, no byte or no subscription does not build.

How to use it is in the Local memory broker component, the Embedded runtime page and the embedded TestApp.