A generic, zero-allocation UDP game-networking stack in Zig. Reliable channels, real
congestion control, optional encryption, a derived bit-level serializer, and a complete
client-prediction / rollback replication layer - all monomorphized from one comptime
Config, and all sans-IO (the protocol never touches a socket, clock, or allocator).
const magnet = @import("magnet");
const Schema = magnet.proto.channels(.{
.chat = .{ .mode = .reliable_ordered, .Message = []const u8 },
});
const Server = magnet.Endpoint(.{ .channels = Schema, .protocol_id = 0x1234 });magnet is six layers, and you take only what you need:
| Stop at | You get | Add |
|---|---|---|
| L3 | secure-optional reliable UDP with typed channels | - |
| L4 | …plus a comptime, bit-level serializer | .Message types |
| L5 | …plus prediction, rollback, interpolation, interest, lag-comp | magnet.replication |
Unused machinery is compiled out, not skipped - an unreliable channel carries no
retransmit state and security.mode = .none links no crypto. Zig's lazy declaration
analysis likewise omits unused replication and runtime subsystems without a configuration
sentinel.
- getting-started - a working client + server from zero.
- concepts/sans-io - the one idea everything rests on.
- config - the comptime spine, every knob.
- channels - the reliability taxonomy.
- serialization - the derived serializer + quantization.
- delivery - acks, loss, congestion control, fragmentation.
- streaming - resumable files/blobs, storage callbacks, progress.
- security - AEAD, key rotation, forward secrecy, tokens, 0-RTT.
- runtime - drivers, the
std.Ioseam, the simulator. - connectivity - IPv6, STUN, ICE, relay, multipath.
- replication - the world-sync engine.
- observability - tracers, stats, record/replay.
- production - sizing, admission control, persistence, rollout.
- network validation lab - deterministic and real-path release evidence.
- public API inventory - canonical pre-stabilization surface.
- security review package - threat model, evidence, and audit checklist.
fps · rts / lockstep · mmo · p2p rollback · co-op
sans-io · comptime · type safety · layering · wire format · security model
config fields · errors ·
API docs: zig build docs → zig-out/docs/.
Every guide links a runnable example in ../examples/. Build them all
with zig build examples, run one with zig build run-<name> (e.g. zig build run-fps).