Files
6f0dfd20c5 docs: complete tooling story (pb2zap + zap2pb), zip server, ZAP-only production case (#1)
* docs: tools section (pb2zap, zap2pb), zip server page, ZAP-only production story

- content/docs/tools/: new Tooling nav group — the complete pb<->ZAP
  interop boundary. pb2zap (go/ast codemod off protobuf), zap2pb
  (the one sanctioned protobuf import: Marshal/Unmarshal/Equal/
  AppendMessage, v0.2.0), and the migration path over the existing
  schema/codegen pages.
- content/docs/zip.mdx: the ZAP-native application server — one
  Listen verb (ZAP primary, HTTP secondary), typed handlers with
  REST/OpenAPI/MCP projections, Mount composition, and the
  hanzoai/cloud case: sub-1,000-line compose root hosting ~75K LOC
  of subsystems (76:1).
- why-zap: scrub the unmeasured benchmark tables (per the
  benchmarks-page policy), replace with mechanism arguments and the
  ZAP-only-in-production account: zero gRPC, protobuf confined to
  the four-function zap2pb boundary at the OTLP edge.
- ecosystem: add zip/pb2zap/zap2pb rows; quick-start + index: link
  the new pages, drop the unmeasured 5-20x claim.

* fix(build): alias MDX collections to regenerated docs/, drop frozen .docs snapshot

next.config.mjs and tsconfig.json pointed @hanzo/docs-mdx:collections/*
at .docs/ — a snapshot frozen on Jun 1 — while the MDX plugin
regenerates docs/ on every build. Result: no page added since the
snapshot (schema, codegen, rpc, capabilities, and this PR%27s tools/zip)
was ever emitted; the site silently served 37 routes instead of 45.
Alias both resolvers at docs/ and remove .docs.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-07 17:58:42 -07:00

155 lines
5.4 KiB
Plaintext

---
title: Introduction
description: ZAP — Infinitely faster. Zero-copy Application Protocol for the age of AI & crypto.
---
# ZAP
**ZAP** (Zero-copy Application Protocol) is an insanely fast data interchange format and capability-based RPC system built for the age of AI & crypto.
Think JSON, except binary. Think Protocol Buffers, except faster. In fact, in benchmarks, ZAP is **∞ TIMES** faster than Protocol Buffers.
## Why Infinitely Faster?
This benchmark is, of course, unfair. It only measures the time to encode and decode a message in memory. ZAP gets a perfect score because **there is no encoding/decoding step**.
The ZAP encoding is appropriate both as a data interchange format AND an in-memory representation. Once your structure is built, you can simply write the bytes straight out to disk!
## Platform Independent
The encoding is defined byte-for-byte independent of any platform. However, it is designed to be efficiently manipulated on common modern CPUs:
- **Struct-like layout** — fixed widths, fixed offsets, proper alignment
- **Pointer-based** — variable-sized elements embedded as offset pointers
- **Position independent** — pointers are relative, not absolute
- **Little-endian** — most CPUs are little-endian; big-endian CPUs have conversion instructions
## Backwards Compatible
New fields are always added to the end of a struct (or replace padding space), so existing field positions are unchanged. The recipient simply does a bounds check when reading each field.
Fields are numbered in the order they were added, so ZAP always knows how to arrange them for compatibility.
## Smart Compression
Fixed-width integers, unset optional fields, and padding do add zeros on the wire. However, ZAP applies an extremely fast packing scheme to remove them:
- Achieves similar (often better) message sizes than protobuf
- Still faster than protobuf encoding
- For bandwidth-critical paths, apply general compression (zlib, LZ4) on top
## Security
ZAP does NOT just cast a buffer pointer to a struct pointer. That would be dangerous.
ZAP generates classes with accessor methods that validate pointers before following them. Invalid pointers (out-of-bounds, etc.) throw exceptions or return defaults — your choice.
ZAP powers **Hanzo AI**'s distributed inference infrastructure and **Lux Network**'s consensus layer — environments where both security and microsecond-level performance are paramount. ZAP has undergone fuzzing and expert security review.
## Superpowers
### Incremental Reads
Start processing a ZAP message before receiving all of it. Outer objects appear entirely before inner objects.
### Random Access
Read just one field without parsing the whole message. Jump directly to the data you need.
### Memory Mapping
Read large ZAP files via `mmap`. The OS won't even read the parts you don't access.
### Inter-Language Communication
Java, Python, C++, Rust — all operate on the same in-memory structure. No slow serialization between languages.
### Shared Memory IPC
Multiple processes share ZAP messages via shared memory. No kernel pipes. Calling another process is as fast as calling another thread.
### Arena Allocation
All objects allocated in arenas. Faster than protobuf's scattered allocations. Better cache locality.
### Tiny Generated Code
Just inline accessor methods. Order of magnitude smaller than protobuf's parsing/serialization code.
### Tiny Runtime
Simple format = tiny library. Less code to ship, audit, and maintain.
### Time-Travel RPC
ZAP's RPC system implements promise pipelining — call results return to clients **before** requests arrive at the server!
## Quick Example
Define your schema:
<SchemaTabs
zap={`struct Person
name Text
birthdate Date # Field numbers = addition order
email Text # for backwards compatibility
phones List(PhoneNumber)
interface AddressBook
lookup (id UInt64) -> (person Person)
search (query Text) -> stream (person Person)`}
capnp={`@0xa1b2c3d4e5f6a7b8; # file ID required
struct Person {
name @0 :Text;
birthdate @3 :Date; # Field numbers = addition order
email @1 :Text; # for backwards compatibility
phones @2 :List(PhoneNumber);
}
interface AddressBook {
lookup @0 (id :UInt64) -> (person :Person);
search @1 (query :Text) -> stream (person :Person);
}`}
/>
Generate and implement your server (Go):
```go
type addressBookServer struct{}
func (s *addressBookServer) Lookup(ctx context.Context, id uint64) (*Person, error) {
return db.FindPerson(id)
}
func main() {
server := zap.NewServer()
server.Register(&addressBookServer{})
server.ListenAndServe(":9000")
}
```
Use the generated client:
```go
client, _ := zap.Dial("localhost:9000")
defer client.Close()
person, _ := client.AddressBook().Lookup(ctx, 12345)
fmt.Println(person.Name()) // Zero-copy access!
```
## Next Steps
<Cards>
<Card title="Quick Start" href="/docs/quick-start">
Get up and running in 5 minutes
</Card>
<Card title="Schema Language" href="/docs/schema">
Learn the ZAP schema language
</Card>
<Card title="Code Generation" href="/docs/codegen">
Generate type-safe code for your language
</Card>
<Card title="RPC System" href="/docs/rpc">
Build services with ZAP RPC
</Card>
<Card title="zip" href="/docs/zip">
The ZAP-native application server
</Card>
<Card title="Tools" href="/docs/tools">
pb2zap and zap2pb — the complete migration path off protobuf
</Card>
</Cards>