Development
Setting Up Development Environment
Clone the repository and install dependencies:
git clone https://github.com/mylonics/struct-frame.gitcd struct-frame
# Install Python dependenciespip install proto-schema-parser
# Install Node.js dependencies (for TypeScript tests)npm installRunning from Source
# Using PYTHONPATHPYTHONPATH=src python src/main.py examples/basic/hello.sf --build_py
# Or install in editable modepip install -e .python -m struct_frame examples/basic/hello.sf --build_pyProject Structure
struct-frame/ src/ main.py # CLI entry point struct_frame/ generate.py # Proto parsing and validation language_facts.py # Primitive types, option names, limits (shared with the VS Code extension) c_gen.py # C code generator cpp_gen.py # C++ code generator ts_gen.py # TypeScript code generator py_gen.py # Python code generator js_gen.py # JavaScript code generator gql_gen.py # GraphQL code generator csharp_gen.py # C# code generator rust_gen.py # Rust code generator naming.py # Generated-name rules, reserved words, --name_overrides schema_diff.py # `struct_frame diff` wire-compatibility check boilerplate/ # Runtime library templates c/ cpp/ ts/ py/ js/ # compiled from ts/ (do not hand-edit; see below) csharp/ rust/ tests/ run_tests.py # Cross-language test runner (see `python test_all.py`) proto/ # Test schemas (.sf) c/, cpp/, py/, ts/, js/, csharp/, rust/ # Language-specific tests test_*.py # pytest suites for the generator itself examples/ # Example schemas and tested programs wireshark/ # Lua dissector (see wireshark/README.md) editors/vscode/ # VS Code extension + language server for .sf files docs/ # Documentation site sourcesAdding or changing a schema option
The compiler and the VS Code extension read the language’s primitive types, option names, accepted
values and numeric limits from one place, src/struct_frame/language_facts.py:
- Change the table in
language_facts.pyand the compiler code that uses it ingenerate.py. - Regenerate the extension’s copy:
python src/struct_frame/language_facts.py --write. CI runs--checkand fails if it is stale. - Add hover text for any new name in
editors/vscode/server/src/docs.ts, plus any new validation inserver.ts.npm testineditors/vscodefails until every name is documented. - The extension’s corpus test requires zero language-server errors on every schema the compiler
accepts (
tests/proto,examples,tests/benchmarks/schema,tests/docs/schemas).
Changes under editors/vscode are published as a new extension version with the next PyPI release
(see docs/dev/RELEASE.md).
Code Generation Pipeline
- Parsing: Read proto file using proto-schema-parser
- Validation: Check schema (unique IDs, field numbers, required options)
- Generation: Language-specific generators produce output files
- Boilerplate: Runtime libraries are copied to output directories
Making Changes
Editing the JavaScript runtime
boilerplate/js/ is compiled from boilerplate/ts/. Edit the TypeScript and rebuild; never edit the JavaScript by hand:
npm ci./node_modules/.bin/tsc -p src/struct_frame/boilerplate/ts/tsconfig.cjs.json(A type error about the optional serialport module is benign; the output is still emitted.) tests/test_generator_regressions.py fails if the compiled SDK lacks members the TypeScript SDK has.
Modifying Generators
Each language has a generator in src/struct_frame/<lang>_gen.py. Generators must implement:
- Type mapping from proto types to target language types
- Message struct/class generation
- Enum generation
- Array handling (fixed and bounded)
- String handling
- Serialization/deserialization code
Adding a New Target Language
- Create
<lang>_gen.pyinsrc/struct_frame/ - Implement the generator class
- Add boilerplate files to
src/struct_frame/boilerplate/<lang>/ - Add CLI flag in
src/main.py - Add tests in
tests/<lang>/ - Register the language in
tests/run_tests.py(_init_languages) and add it to the CI lanes in.github/workflows/test.yml
Building for Release
# Update version in pyproject.tomlpip install --upgrade build twinepython -m buildpython -m twine upload dist/*Common Development Tasks
Regenerate All Examples
PYTHONPATH=src python src/main.py examples/generic_robot.sf \ --build_c --build_cpp --build_ts --build_py --build_gqlRun Quick Validation
# Generate and check for errorsPYTHONPATH=src python src/main.py examples/array_test.sf --build_py --py_path generated/py
# Import generated codepython -c "import sys; sys.path.insert(0, 'generated/py'); from structframe.array_test import get_message_info"Running the Tests
python test_all.py # every language available on this machinepython test_all.py --require-langs c,cpp,py,ts,js,csharp,rust # fail instead of skipping a missing toolchainpython -m pytest tests # generator-level pytest suites onlyNew schema-validation behaviour should get a test in tests/test_generator_regressions.py (or tests/test_generator_validation.py); documentation samples that compile belong in examples/ so tests/test_examples.py builds and runs them.
Code Style
- Python: Follow existing style in codebase
- C: See
.clang-format - Generated code should be readable and debuggable