Skip to main content

Crate zapc

Crate zapc 

Source
Expand description

zapc — ZAP schema compiler.

Parses .zap schema files into an in-memory IR (Schema) and emits Rust readers/writers via codegen::emit_rust. Hand-rolled parser — no dependency on upstream Cap’n Proto tooling.

§Schema syntax

@0xc0a8b5e0e5f0a000;     // file id (random 64-bit, hex)

struct KeysSnapshot {
    application @0 :Text;
    seq         @1 :UInt64;
    jwksJson    @2 :Data;
}

struct Ping { nonce @0 :UInt64; }

Supported types: Bool, UInt8/16/32/64, Int8/16/32/64, Float32/64, Text (UTF-8 string), Data (byte slice).

Each field has a stable index. The on-wire layout is the canonical ZAP packing (matches Go luxfi/zap):

  • Fixed-size primitives are packed at the field offset (computed from field index × max(field-size, alignment)).
  • Text and Data store an i32 LE relative offset + u32 LE length at the field offset; payload bytes follow the struct.
  • Structs are 8-byte aligned.

Re-exports§

pub use codegen::emit_rust;
pub use parser::Field;
pub use parser::FieldType;
pub use parser::Schema;
pub use parser::Struct;

Modules§

codegen
Codegen — emit Rust readers/writers from a parsed Schema.
parser
.zap schema parser. Produces a Schema IR consumed by codegen.

Enums§

Error

Functions§

compile_to_rust
Convenience for build.rs callers — parse + emit in one shot.

Type Aliases§

Result