A high-performance, Roslyn-powered code generation utility that compiles C# packet definitions into wire-compatible C and Rust bindings. Ensures identical byte layout, alignment, and serialization order across platforms.
To keep this project maintainable as we support additional target languages, detailed specifications are split into dedicated guides:
- 📐 Protogen Serialization & Type Specification: Primitive and complex type mappings (C/Rust), string formats, C# definition attributes (
[Packet],[SerializeOrder]), and generated code outputs.
- Roslyn-Powered Parser: Uses
MSBuildWorkspaceto parse.csprojsource trees or reflection to read compiled assemblies (.dll). - Multi-Language Bindings: Generates fully-typed native C structs (with MSVC pack pragmas) and safe Rust structs.
- Automatic Size Verification: Builds round-trip test suites (
packet_test.candpacket_tests.rs) to prove serialization/deserialization logic is identical across target languages.
Build the self-contained compiler binary from the repository root:
dotnet publish src/Nalix.Protogen.Cli -c Release -o ./binThe output compiles to a self-contained protogen executable in the ./bin directory.
# General CLI Command Syntax
protogen --project <path-to-csproj> --c-out <dir> [--rust-out <dir>] [options]
protogen --assembly <path-to-dll> --c-out <dir> [--rust-out <dir>] [options]| Flag | Long Flag | Description |
|---|---|---|
-p |
--project |
Path to the C# .csproj containing packet definitions. |
-a |
--assembly |
Path to the compiled C# .dll containing packet definitions. |
--c-out |
Output directory for C files (packets.h, packets.c, packet_test.c). |
|
--rust-out |
Output directory for Rust files (packets.rs, packets_tests.rs). |
|
-v |
--verbose |
Enable verbose logging for MSBuild warnings. |
# Generate C and Rust bindings from a csproj source
protogen -p ../Nalix.Codec/Nalix.Codec.csproj --c-out ./gen/c --rust-out ./gen/rs
# Generate C-only bindings from a compiled DLL assembly
protogen -a ../Nalix.Codec/bin/Release/net10.0/Nalix.Codec.dll --c-out ./gen/cNalix.Protogen.Abstractions # Shared models, interfaces, and options contracts.
Nalix.Protogen.Roslyn # MSBuild and Roslyn workspace packet code parser.
Nalix.Protogen.Cli # Console Application entry point (protogen).
Apache License 2.0. See LICENSE for details.