Thrifty - a Gleamourous Apache Thrift Compact Protocol Library.

CIHex License Built with Gleam Gleam Version

Thrifty is a pure Gleam implementation of the Apache Thrift Compact Protocol. It targets predictable behaviour, strict boolean semantics, and interoperability with golden payloads produced by official Thrift stacks.

Use caseWhat Thrifty provides
Runtime decodingImmutable reader with configurable limits, compatibility with legacy booleans, schema-agnostic skip support
EncodingWriter helpers for primitives, containers, and struct headers
Testing harnessDeterministic fuzzing CLI, property tests, and golden vector validation

Features

Getting Started

Prerequisites

Installation (Hex)

Add Thrifty as a dependency once published:

// gleam.toml
[dependencies]
thrifty = "~> 1.0"

Local Development

gleam deps download
gleam test           # run unit, property, and golden tests
gleam run -m thrifty # execute example entrypoint (if configured)

Golden payloads live under artifact/golden/; tests read directly from this directory. If you regenerate payloads out of band, keep filenames stable so golden tests discover them automatically.

Explore hands-on guides under docs/examples/ for decoding, encoding, skipping unknown fields, strict-boolean enforcement, and fuzz harness walkthroughs.

Project Layout

artifact/
  golden/              # canonical Compact Protocol payloads used in tests
  fuzz-failures/       # failing fuzz cases (enabled on demand)
src/                   # library implementation modules
test/                  # gleeunit test suites (unit, property, golden)
.github/workflows/     # GitHub Actions CI pipelines

Key Modules

Fuzz Harness & Failure Persistence

The fuzz CLI mutates golden payloads deterministically. Set the internal toggle or expose a CLI flag to enable persistence:

const save_failures_enabled = True
const save_failures_dir = "artifact/fuzz-failures"

When enabled, failing payloads and slim metadata (seed, iteration, reason) are written to the target directory for later triage. Tests under test/thrifty/fuzz_persistence_test.gleam exercise this pipeline.

For long-running fuzz jobs in CI, upload artifact/fuzz-failures/ as a build artifact so failures can be replayed locally.

Testing & Tooling

Regenerating Golden Payloads

Golden payloads are sourced from reference implementations (e.g., thriftpy2 or Apache Thrift Java). A typical workflow is:

  1. Produce binaries with the upstream tool of choice (store generator scripts alongside other tooling if you add them).
  2. Copy the resulting Compact payloads into artifact/golden/.
  3. Extend test/thrifty/golden_test.gleam or other suites to assert the expected decoding behaviour.
  4. Run gleam test to validate compatibility.

License

Licensed under the Apache License, Version 2.0.

Search Document