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
struct-frame messages.proto --build-py
# Generate C code
struct-frame messages.proto --build-c
# Generate multiple languages
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 (kebab-case file names, e.g. pkg-test-a.structframe.ts)
--build-pyPython<name>.py (in the structframe/ package)
--build-jsJavaScript<name>.structframe.js (kebab-case file names)
--build-csharpC#<PackageName>/Messages/*.cs, <PackageName>/Enums/*.cs
--build-gqlGraphQL<package>.graphql per package, plus a combined schema.graphql
--build-rustRust<name>.structframe.rs

GraphQL type mapping

uint8/int8/uint16/int16/int32 map to Int, float/double to Float, bool to Boolean and string/bytes to String. GraphQL’s Int is a signed 32-bit integer, so uint32, int64 and uint64 map to the custom scalars UInt32, Int64 and UInt64, which every generated schema document declares (scalar UInt32, …); serialize them as strings or numbers in your resolvers as appropriate. Types are named <Package><Type>, message-scoped enums <Package><Message><Enum>.

Output Paths

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

Terminal window
# Custom C output
struct-frame messages.proto --build-c --c-path src/generated/
# Multiple languages, different paths
struct-frame messages.proto \
--build-c --c-path firmware/generated/ \
--build-py --py-path server/generated/

Common Patterns

Single Language

Terminal window
struct-frame robot.proto --build-cpp --cpp-path include/

Embedded + Server

Terminal window
struct-frame messages.proto \
--build-c --c-path embedded/messages/ \
--build-py --py-path server/messages/

Frontend + Backend

Terminal window
struct-frame api.proto \
--build-ts --ts-path frontend/src/generated/ \
--build-py --py-path backend/generated/

All Languages

Terminal window
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.