MoonPack is a MoonBit-native schema-first binary serialization toolkit.
It uses a compact tag-based wire format inspired by protobuf, but keeps the
schema language intentionally small so MoonBit projects can generate predictable
types and encoders without pulling in a large compatibility surface.
Highlights
MoonBit-native schema parser, validator, code generator, and CLI.
Compact tag-based binary wire format with unknown-field skipping.
Generated MoonBit structs, enums, defaults, sample fixtures, encode/decode,
equality helpers, enum mappings, and value round-trip tests.
Supports scalar fields, optional fields, List[T], enums, nested messages,
reserved field/tag numbers, reserved ranges such as reserved 10..20, and
field-level deprecated markers.
Includes schema compatibility checks and Markdown schema documentation for
safe version evolution.
Designed as reusable infrastructure for tools, games, caches, and data
exchange in the MoonBit ecosystem.
Why Not Just Protobuf
MoonPack borrows the proven field_number + wire_type idea from protobuf, but
does not try to be protoc-compatible. The goal is a smaller MoonBit-first
library that is easier to inspect, extend, and use in contest-sized projects.
Area
MoonPack
Protobuf
Schema
Small .mpack language
Full .proto language
Codegen
MoonBit-only MVP
Multi-language ecosystem
Wire format
Tag-based, protobuf-inspired
Protobuf-compatible
Scope
4k-10k LOC target
Large mature ecosystem
Goal
MoonBit ecosystem building block
Cross-language standard
Use Cases
Game save files and deterministic simulation snapshots.
CLI/toolchain cache records.
Local configuration or project metadata.
Network message definitions for small MoonBit services.
Test fixtures that need compact binary round-trips.
Status
This repository contains a working MVP. It can parse .mpack schemas, validate
them, generate MoonBit code, and run generated round-trip tests.
Installation
Install the MoonBit toolchain first, then clone and verify this repository:
git clone https://github.com/001-Elsa/Moonbit-Submit.git
cd Moonbit-Submit
moon update
moon check
moon build
moon test
moon run src/cli -- check examples/auth/auth.mpack
moon run src/cli -- compat examples/compat/savegame_v1.mpack examples/compat/savegame_v2.mpack
moon run src/cli -- gen examples/savegame/savegame.mpack -o generated
moon run src/cli -- doc examples/savegame/savegame.mpack -o docs/generated
moon check
moon test
gen writes:
generated/demo/savegame/moon.pkg
generated/demo/savegame/vec2.mbt
generated/demo/savegame/vec2_test.mbt
generated/demo/savegame/inventory_item.mbt
generated/demo/savegame/inventory_item_test.mbt
generated/demo/savegame/save_game.mbt
generated/demo/savegame/save_game_test.mbt
Example output:
ok: demo.auth
ok: compatible
generated: generated/demo/savegame (7 files)
documented: docs/generated/demo/savegame.md
Total tests: 43, passed: 43, failed: 0.
error: examples/invalid/reserved.mpack:5:3: field number 1 is reserved in message User
error: compat failed: message Save removed field 2 without reserving it
Minimal Runnable Example
Validate the small auth schema:
moon run src/cli -- check examples/auth/auth.mpack
Generate MoonBit code and tests for the savegame schema:
moon run src/cli -- gen examples/savegame/savegame.mpack -o generated
moon test
flowchart LR
A[".mpack schema"] --> B["lexer + parser"]
B --> C["AST"]
C --> D["validator"]
D --> E["MoonBit codegen"]
E --> F["structs + enums"]
E --> G["encode/decode"]
E --> H["round-trip tests"]
Packages
src/core: wire format, varint, reader, writer, errors.
MoonPack targets a reusable infrastructure gap in the MoonBit ecosystem:
schema-driven binary data exchange. A finished version can be used by command
line tools, game save files, local caches, RPC message definitions, and test
fixtures.
MoonPack
MoonPack is a MoonBit-native schema-first binary serialization toolkit.
It uses a compact tag-based wire format inspired by protobuf, but keeps the schema language intentionally small so MoonBit projects can generate predictable types and encoders without pulling in a large compatibility surface.
Highlights
List[T], enums, nested messages, reserved field/tag numbers, reserved ranges such asreserved 10..20, and field-leveldeprecatedmarkers.Why Not Just Protobuf
MoonPack borrows the proven
field_number + wire_typeidea from protobuf, but does not try to be protoc-compatible. The goal is a smaller MoonBit-first library that is easier to inspect, extend, and use in contest-sized projects..mpacklanguage.protolanguageUse Cases
Status
This repository contains a working MVP. It can parse
.mpackschemas, validate them, generate MoonBit code, and run generated round-trip tests.Installation
Install the MoonBit toolchain first, then clone and verify this repository:
On Windows, the full local acceptance run is:
On Unix-like shells:
Pass
-Updateon PowerShell or--updateon Bash to force a registry update; CI does this automatically.Acceptance Status
001-Elsa/moonpack@0.1.2moon check,moon build,moon test, CLI smoke tests, generated-output reproducibility checks, and package listing.scripts/check.ps1andscripts/check.shFetch the published package with:
Example Schema
CLI
From a cloned workspace:
genwrites:generated/demo/savegame/moon.pkggenerated/demo/savegame/vec2.mbtgenerated/demo/savegame/vec2_test.mbtgenerated/demo/savegame/inventory_item.mbtgenerated/demo/savegame/inventory_item_test.mbtgenerated/demo/savegame/save_game.mbtgenerated/demo/savegame/save_game_test.mbtExample output:
Minimal Runnable Example
Validate the small auth schema:
Generate MoonBit code and tests for the savegame schema:
The generated package exposes helpers such as:
Flow
Packages
src/core: wire format, varint, reader, writer, errors.src/schema: schema tokens, lexer, AST, parser, validator.src/codegen: MoonBit source emitter.src/cli: command entry point.MVP Scope
Bool,Int,Int64,Double,String,Bytes.message,enum,List[T], optionalT?.deprecated,reserved <n>, andreserved <start>..<end>.moonpack doc.Current Verification
moon check: passing.moon build: passing.moon test: passing with package tests and generated value round-trip tests.scripts/check.ps1/scripts/check.sh: cover check, build, tests, CLI success paths, CLI failure diagnostics, compatibility checks, generated demo refreshes, documentation generation, formatting, and package listing.The generated MVP supports scalar fields, optional fields, repeated fields via
List[T], enums, nested messages, and Double via fixed64.Schema evolution supports marking fields as deprecated before reserving and removing their field numbers in later versions.
Demo Schema
Repository Layout
Competition Value
MoonPack targets a reusable infrastructure gap in the MoonBit ecosystem: schema-driven binary data exchange. A finished version can be used by command line tools, game save files, local caches, RPC message definitions, and test fixtures.