Skip to content

Code Generation

Generate serialization code from proto files using the struct-frame command-line tool.

Basic Usage

Terminal window
# Generate Python code
python -m struct_frame messages.proto --build_py
# Generate C code
python -m struct_frame messages.proto --build_c
# Generate multiple languages
python -m struct_frame messages.proto --build_c --build_cpp --build_py --build_ts

Language Flags

FlagLanguageOutput
--build_cC<name>.structframe.h
--build_cppC++<name>.structframe.hpp
--build_tsTypeScript<name>.structframe.ts
--build_pyPython<name>.py (in struct_frame/generated/)
--build_jsJavaScript<name>.structframe.js
--build_csharpC#<PackageName>/Messages/*.cs, <PackageName>/Enums/*.cs
--build_gqlGraphQL<name>.structframe.graphql

Output Paths

Default output is generated/<language>/. Customize with path options:

Terminal window
# Custom C output
python -m struct_frame messages.proto --build_c --c_path src/generated/
# Multiple languages, different paths
python -m struct_frame messages.proto \
--build_c --c_path firmware/generated/ \
--build_py --py_path server/generated/

Common Patterns

Single Language

Terminal window
python -m struct_frame robot.proto --build_cpp --cpp_path include/

Embedded + Server

Terminal window
python -m struct_frame messages.proto \
--build_c --c_path embedded/messages/ \
--build_py --py_path server/messages/

Frontend + Backend

Terminal window
python -m struct_frame api.proto \
--build_ts --ts_path frontend/src/generated/ \
--build_py --py_path backend/generated/

All Languages

Terminal window
python -m struct_frame messages.proto \
--build_c --build_cpp --build_ts --build_py --build_js --build_csharp --build_gql

Generated Files

Each language generates:

  • Message/struct definitions
  • Serialization code (where applicable)
  • Frame parsing utilities (if using framing)
  • SDK files (if --sdk flag used)

See CLI Reference for complete details.