Quick Start
This guide shows you how to create a simple message, generate code, and use it in C++.
1. Create a Schema File
Create a file called status.sf (.sf is the usual extension; a .proto file with the same content works too):
package example;
message Status { option msgid = 1; uint32 id = 1; float value = 2;}2. Generate Code
Generate C++ code from the schema:
struct-frame status.sf --build-cpp --cpp-path generated/This creates generated/example.structframe.hpp. In C++ the types live in the structframe::example namespace (in C the package name is prefixed to the type name instead, e.g. ExampleStatus).
3. Use the Generated Code
Here’s a simple C++ example that encodes and parses a message:
#include "example.structframe.hpp"#include <cstring>#include <iostream>
using structframe::example::Status;
int main() { // Create and populate a message Status status; status.id = 42; status.value = 3.14f;
// Serialize into a byte buffer (a plain copy of the packed struct) uint8_t buffer[Status::MAX_SIZE]; size_t size = status.serialize(buffer);
// Send buffer over serial, network, etc. // ...
// On the receiving side, deserialize from the buffer Status received; received.deserialize(buffer, size); std::cout << "ID: " << received.id << std::endl; std::cout << "Value: " << received.value << std::endl;
return 0;}Compile and run:
g++ -std=c++20 -I generated/ main.cpp -o main./mainThat’s it! The C/C++ implementation uses packed structs that map directly to memory, so serializing is a plain copy with no per-field encoding. (This relies on a little-endian host, which every mainstream target is; the headers refuse to compile on a big-endian one.)
Next Steps
- Message Definitions - Learn how to write proto files
- Language Examples - See examples for other languages
- Framing - Add framing for reliable communication