Skip to content

Repository files navigation

PAKT

PAKT — a typed data interchange format. Human-authorable. Streaming. Self-describing.

greeting:str = 'hello world'
count:int = 42
payload:bin = x'48656C6C6F'
active:bool = true
server:{host:str, port:int} = { 'localhost', 8080 }

What is PAKT?

PAKT is a typed data interchange format where every value carries its type. No inference, no ambiguity. Units are self-validating — type annotations are producer assertions checked at parse time.

The current Go library and CLI implement the PAKT v0 surface: ; map syntax, bin, raw strings, the first-content-line multi-line string rule, and top-level << pack statements. Duplicate statement names and map keys are preserved in decode order; higher-level consumers decide how to interpret them.

Repository Structure

pakt/
├── encoding/ # Canonical Go library (github.com/trippwill/pakt/encoding)
├── dotnet/ # .NET library, source generator, benchmarks
├── main.go # CLI entry point (go install github.com/trippwill/pakt@latest)
├── spec/ # Formal specification (PAKT v0 draft)
├── docs/ # User guide and documentation
├── site/ # Hugo website (usepakt.dev)
└── testdata/ # Sample .pakt files

Install

go install github.com/trippwill/pakt@latest

CLI Usage

# Parse a file and emit structured events
pakt parse data.pakt
# Validate only (exit 0/1)
pakt validate data.pakt

Library

import"github.com/trippwill/pakt/encoding"

Unmarshal

typeConfigstruct {
Hoststring`pakt:"host"`Portint`pakt:"port"`
}
cfg, err:= encoding.UnmarshalNew[Config](data)

Streaming (UnitReader)

ur:=encoding.NewUnitReader(reader)
deferur.Close()
forprop:=rangeur.Properties() {
switchprop.Name {
case"config":
cfg, err:= encoding.ReadValue[Config](ur)
case"events":
forevent:=range encoding.PackItems[LogEvent](ur) {
process(event)
}
}
}
iferr:=ur.Err(); err!=nil { ... }

Event-Level Decode

dec:=encoding.NewDecoder(reader)
deferdec.Close()
for {
ev, err:=dec.Decode()
iferr==io.EOF { break }
fmt.Println(ev.Kind, ev.Name, string(ev.Value))
}

.NET Library

The dotnet/ directory contains a high-performance .NET implementation with source-generated serialization. See dotnet/README.md for full details.

usingPakt;usingPakt.Serialization;[PaktSerializable(typeof(Server))]publicpartialclassAppPaktContext:PaktSerializerContext{}// Deserialize a unit with top-level statements matching CLR propertiesvarserver=PaktSerializer.Deserialize<Server>(paktBytes,AppPaktContext.Default);// Iterate pack statementsusingvarreader=PaktMemoryReader.Create(paktBytes,AppPaktContext.Default);while(reader.ReadStatement()){if(reader.IsPack&&reader.StatementType.IsList){foreach(variteminreader.ReadPack<Server>())Process(item);}elseif(reader.IsPack&&reader.StatementType.IsMap){foreach(variteminreader.ReadMapPack<string,Server>())Console.WriteLine($"{item.Key}: {item.Value.Host}:{item.Value.Port}");}else{varvalue=reader.ReadValue<Server>();Console.WriteLine($"{value.Host}:{value.Port}");}}

Documentation

License

MIT

About

PAKT — a typed data interchange format. Human-authorable. Stream-parseable. Spec-projected.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages