Files
zap/rust/Cargo.toml
zeekay 07cc875d57 zap: rewrite with our own zapc compiler — drop capnp dependency entirely
Per user direction: "no capnp we DON'T use that" + "must use zapc"
+ "must be our fork". The runtime now has zero capnp footprint —
schema bindings come from our own hand-rolled compiler.

Workspace layout:

  zap/
  ├── Cargo.toml          workspace root
  ├── zapc-rs/            zapc — schema compiler
  │   ├── Cargo.toml
  │   └── src/
  │       ├── lib.rs       Public compile_to_rust API
  │       ├── parser.rs    .zap → Schema IR (file id + structs)
  │       ├── codegen.rs   Schema → Rust readers/writers
  │       └── main.rs      `zapc <schema.zap>` CLI
  └── rust/               hanzo-zap — runtime
      ├── Cargo.toml      build-deps: zapc (path)
      ├── build.rs        invokes zapc::compile_to_rust
      ├── schema/
      │   └── zap.zap     canonical schema (was zap.capnp)
      ├── src/
      │   ├── wire.rs      ZAP framing + io
      │   ├── schema.rs    include!() generated bindings
      │   ├── server.rs    raw TCP listener + Handler trait
      │   ├── msg.rs       canonical type ids
      │   └── lib.rs
      └── benches/
          └── wire.rs      criterion bench: ZAP vs JSON

Wire format unchanged — still byte-for-byte aligned with
github.com/luxfi/zap (Go) and @zap-proto/zap (TS). Each struct in the
schema becomes a `<name>::Reader<'a>` (zero-copy view into the slot
region) plus a `<name>::Writer` (owning builder). Variable-length
fields (Text/Data) use the standard i32 LE relative offset + u32 LE
length pair at the slot, payload appended to the tail.

Tests: 6/6 pass — header roundtrip, bad magic reject, bad version
reject, raw frame io, generated proto roundtrip, KeysSnapshot with
2 KiB payload.

Bench (single core, criterion):
  decode/keys_subscribe   zap=19 ns   json_scan=591 ns      (31× win)
  encode/keys_snapshot    zap=736 ns                         (~1 GiB/s)
  encode/keys_subscribe   zap=436 ns   json_format=134 ns    (-3.3×)

Decode dominates the JWT-validation hot path (every consumer decodes
KeysRotate / KeysSnapshot from the IAM publisher), so the 31× decode
win is what matters. Encode-side regression on tiny messages is from
allocating two Vecs (slot + tail); will fold into one pre-sized buf
in a follow-up.

The user-flagged JSON encoding from the previous v1 prototype is
gone: `cargo tree -p hanzo-zap | grep -i serde_json` returns empty.
2026-05-06 22:44:16 -07:00

45 lines
1.3 KiB
TOML

[package]
name = "hanzo-zap"
version = "1.0.1"
edition = "2021"
description = "ZAP — Zero-copy Application Protocol. Hand-rolled little-endian binary, schema bindings via zapc."
license = "MIT"
repository = "https://github.com/hanzoai/zap"
keywords = ["zap", "rpc", "binary-protocol", "zero-copy"]
categories = ["network-programming", "encoding"]
# 1.0.0 was a JSON-payload-in-binary-frame WebSocket prototype that
# never shipped. 1.0.1 is the canonical Rust impl: hand-rolled
# little-endian binary, byte-for-byte aligned with the Go reference at
# github.com/luxfi/zap and the TS @zap-proto/zap. Schema-generated
# readers/writers come from our own zapc compiler (path = ../zapc-rs)
# — no upstream Cap'n Proto dependency.
[dependencies]
tokio = { version = "1", features = ["net", "io-util", "rt-multi-thread", "macros", "sync", "signal", "time"] }
futures-util = "0.3"
async-trait = "0.1"
log = "0.4"
anyhow = "1.0"
thiserror = "2"
env_logger = "0.11"
[build-dependencies]
zapc = { path = "../zapc-rs" }
[dev-dependencies]
tokio = { version = "1", features = ["full", "test-util"] }
criterion = { version = "0.5", features = ["html_reports"] }
[[bench]]
name = "wire"
harness = false
[[bin]]
name = "hanzo-zap"
path = "src/main.rs"
[lib]
name = "hanzo_zap"
path = "src/lib.rs"