Moon Proto Lab is a MoonBit protobuf ecosystem lab for dynamic schema parsing, compatibility testing, JSON mapping, code generation experiments, and AI-generated schema/code verification.
The repository name remains moon_proto, but the project is now deliberately positioned as an ecosystem companion instead of a replacement for the existing MoonBit protobuf implementation.
Moon Proto Lab therefore does not claim to replace the official/runtime-oriented protobuf stack. Its independent value is the verification and tooling layer around protobuf usage in MoonBit:
parse and validate .proto schemas before code generation;
provide a dynamic descriptor/message runtime for debugging and schema experiments;
check protobuf binary and JSON mapping behavior against Python/Go official protobuf oracles;
provide conformance-lite fixtures for scalar, repeated, packed repeated, enum, nested, map, oneof and upstream-style wire-decode edge cases;
compile-check generated MoonBit source so AI-generated schema/code changes are not only syntactically plausible but actually buildable;
keep the door open for future adapters to official MoonBit protobuf packages.
This makes the project fit the contest theme of improving MoonBit open-source infrastructure and addressing the problem that AI-generated code is hard to verify and maintain over time.
Current scope
The project has a small but end-to-end verifiable protobuf laboratory pipeline:
protobuf wire type model;
key packing/parsing;
UInt64 varint encode/decode;
zig-zag signed integer mapping;
fixed32/fixed64 little-endian helpers;
length-delimited bytes/string helpers;
field-level helpers for uint64, bool, sint64, string, bytes;
proto3 schema model for messages, fields, labels, scalar types, enums, named messages, maps and oneof groups;
.proto lexer/parser for syntax, edition declaration tolerance, dotted package names, import, top-level/message/enum option, real reserved number/name descriptors, extensions, message, enum, nested message/enum definitions, qualified nested type references, scalar/named fields, field/enum options, signed enum values and enum reserved ranges, enum allow_alias duplicate-number semantics, single-quoted/escaped string literals, empty statements, optional, repeated, map, oneof, oneof options, block comments, and ignored service/rpc/extend blocks;
schema validator for field numbers, duplicate names/numbers, proto3 enum invariants, top-level conflicts, map constraints, and field/enum reserved-number/name reuse;
schema-driven dynamic message encode/decode for scalar, repeated, packed repeated, enum, nested message, map and oneof fields;
unknown-field skipping during decode;
protobuf-style JSON writer/parser for scalar/repeated/map/nested/oneof dynamic messages, including enum-name schema mapping for fields and map values, numeric map-key normalization with canonical duplicate detection, URL-safe/unpadded bytes base64 input, standard JSON string escapes with Unicode/surrogate-pair decoding, strict JSON number grammar, exponent-notation integer input with overflow-safe range checks, null-as-absent parsing semantics and lowerCamelCase input/output helpers;
MoonBit source generator for message structs, enums, descriptor registries and helper functions;
file-based generator wrapper for .proto input and generated .mbt output;
file-based Schema Doctor CLI for stable diagnostics on valid and invalid schemas;
AI verification CLI that runs doctor, schema inspection, codegen, generated-code compile checks, and Markdown/HTML/JUnit XML report generation;
old/new schema compatibility checker for detecting field, enum, package, type and reserved-contract breaking changes;
official MoonBit protobuf differential harness manifest/report for schemas overlapping with moonbitlang/protoc-gen-mbt, including manifest feature coverage gates, scalar-matrix adapter coverage, source-contract, pre-generated output and installed-plugin live-generator smoke paths;
FileDescriptorSet descriptor/reflection bridge for .pb/.hex/.json descriptor imports, proto reconstruction, verification reports, old/new descriptor-set compatibility reports, descriptor-registry release gates, JSON release-policy checks with rule-based severity/warning support, and file/HTTP/authenticated/profile/GitHub Contents managed-backend registry adapter publish/push/pull verification;
Python and Go official protobuf oracle fixtures for cross-language compatibility checks, including 32-bit numeric boundary values, float/double values, special NaN/Infinity JSON values, and upstream-style wire-decode edge vectors;
conformance-lite evidence report with Markdown/JSON/JUnit output for scalar/repeated/packed, map, oneof, numeric-boundary, float/double, special-float, wire-decode edge cases and an imported upstream-lite conformance manifest, expected-fail mutation self-checks, and coverage-gate taxonomy;
deterministic property-style roundtrip corpora for binary and JSON paths;
generated-code compile checks and GitHub Actions CI.
Engineering records
For contest traceability, the repository keeps public engineering records in.
Early work is primarily evidenced by the commit log and CI history; issues #2-#5
are explicitly retrospective records, while new work should use the live issue/PR
workflow.
GitHub Issues and Pull Requests for future task/bug tracking;
GitHub Actions for reproducible CI evidence.
Reviewer quick demo
For a short contest-review walkthrough, see docs/DEMO.md. It provides copy/paste commands for schema doctor, JSON roundtrip normalization, generated-code compile checks, compatibility checks, conformance-lite evidence and official differential reports.
Example
Encode a small hand-written message:
let user = concat_bytes([
encode_uint64_field(1, 150UL),
encode_string_field(2, "Alice"),
encode_bool_field(3, true),
])
// b"\x08\x96\x01\x12\x05Alice\x18\x01"
Parse a small schema:
let src = #|syntax = "proto3";
#|package demo;
#|message User {
#| uint32 id = 1;
#| string name = 2;
#| repeated string tags = 3;
#|}
let ast = parse_proto(src)
Encode/decode through a descriptor:
let desc = MessageDescriptor::{
name : "User",
fields : [
FieldDescriptor::{ name : "id", typ : UInt64Type, number : 1, label : Singular },
FieldDescriptor::{ name : "name", typ : StringType, number : 2, label : Singular },
],
}
let msg = message_value([
message_field("id", UInt64Value(150UL)),
message_field("name", StringValue("Alice")),
])
let encoded = encode_message(desc, msg)
Moon Proto Lab
Moon Proto Lab is a MoonBit protobuf ecosystem lab for dynamic schema parsing, compatibility testing, JSON mapping, code generation experiments, and AI-generated schema/code verification.
The repository name remains
moon_proto, but the project is now deliberately positioned as an ecosystem companion instead of a replacement for the existing MoonBit protobuf implementation.Repository links
Ecosystem positioning
Before submission we checked the MoonBit package ecosystem and found existing protobuf-related packages, including
moonbitlang/protobuf(https://mooncakes.io/docs/moonbitlang/protobuf) andmoonbitlang/protoc-gen-mbt(https://github.com/moonbitlang/protoc-gen-mbt).Moon Proto Lab therefore does not claim to replace the official/runtime-oriented protobuf stack. Its independent value is the verification and tooling layer around protobuf usage in MoonBit:
.protoschemas before code generation;This makes the project fit the contest theme of improving MoonBit open-source infrastructure and addressing the problem that AI-generated code is hard to verify and maintain over time.
Current scope
The project has a small but end-to-end verifiable protobuf laboratory pipeline:
uint64,bool,sint64,string,bytes;.protolexer/parser forsyntax,editiondeclaration tolerance, dottedpackagenames,import, top-level/message/enumoption, realreservednumber/name descriptors,extensions,message,enum, nested message/enum definitions, qualified nested type references, scalar/named fields, field/enum options, signed enum values and enum reserved ranges, enumallow_aliasduplicate-number semantics, single-quoted/escaped string literals, empty statements,optional,repeated,map,oneof, oneof options, block comments, and ignoredservice/rpc/extendblocks;null-as-absent parsing semantics and lowerCamelCase input/output helpers;.protoinput and generated.mbtoutput;moonbitlang/protoc-gen-mbt, including manifest feature coverage gates, scalar-matrix adapter coverage, source-contract, pre-generated output and installed-plugin live-generator smoke paths;.pb/.hex/.jsondescriptor imports, proto reconstruction, verification reports, old/new descriptor-set compatibility reports, descriptor-registry release gates, JSON release-policy checks with rule-based severity/warning support, and file/HTTP/authenticated/profile/GitHub Contents managed-backend registry adapter publish/push/pull verification;Engineering records
For contest traceability, the repository keeps public engineering records in. Early work is primarily evidenced by the commit log and CI history; issues #2-#5 are explicitly retrospective records, while new work should use the live issue/PR workflow.
CHANGELOG.mdfor release-level changes;docs/ENGINEERING_RECORD.mdfor work-package traceability and verification policy;Reviewer quick demo
For a short contest-review walkthrough, see
docs/DEMO.md. It provides copy/paste commands for schema doctor, JSON roundtrip normalization, generated-code compile checks, compatibility checks, conformance-lite evidence and official differential reports.Example
Encode a small hand-written message:
Parse a small schema:
Encode/decode through a descriptor:
Generate MoonBit source from a parsed proto:
Run the bundled CLI smoke generator and schema tools:
Generate from a
.protofile into a project directory:Run the file-based Schema Doctor and AI verification report workflow:
Convert a dynamic message to protobuf-style JSON:
Validate parsed schemas before codegen:
Verify
Documentation
output/pdf/MoonProto_王越的战队_项目申报书.pdfRoadmap
moon_proto gen schema.proto -o generated/. Done..protofiles. Done.moonbitlang/protoc-gen-mbt. Done.allow_aliasparser, validation and generated-code verify coverage. Done..protostring literal parser tolerance with generated-code verify coverage. Done.extendcustom-option block parser tolerance with generated-code verify coverage. Done.edition = "2023"declaration parser tolerance with generated-code verify coverage. Done.nullparsing as absent fields, with duplicate-field and repeated-element guards. Done.\uXXXXsequences and UTF-16 surrogate pairs while rejecting malformed escapes/control characters. Done.json-roundtripcommand normalizes protobuf JSON and smoke-tests lowerCamel/numeric map-key duplicate behavior. Done.License
MIT.