Recently, I’ve been thinking: how are we supposed to connect systems written in Zig?
Not everything is a web client, a broker-based system, or a part of some structured RPC flow.
Sometimes, you just want to exchange good old-fashioned messages—without worrying about transport-level details or heavyweight abstractions.
So I present to you tofu - a protocol and an asynchronous messaging library :
- Message-Based: Uses discrete messages for communication.
- Asynchronous: Enables non-blocking message exchanges.
- Duplex: Supports two-way communication.
- Peer-to-Peer: Allows equal roles after connection establishment.
- Streaming - "client", "server", bi-directional.
- Multithread-friendly - All APIs are safe for concurrent access.
- Memory management for messages - Internal message pool
- Backpressure management - Allows to control receive of messages
- Customizable application flows - Allows to build various application flows not restricted to request/response or pub/sub
- Simplest API - You do not have to bother with socket interfaces
- Callback enabled
All above implemented on plain Zig and std.posix. Nothing else.
Simplest way to got tofu approach - read tofu’s mantra
Do you have a (code) example of doing something useful with this? I’ve looked at your project multiple times and I don’t understand what problem is it solving.
I have built systems out of ZeroMQ with MessagPack as the data format, both have Zig libraries for it (zimq and mzg). What advantages does tofu have over using such an approach?