Embedded Systems
Minimal protocols optimized for memory-constrained devices
Status: ✅ Full Support
Examples:
C++ support includes the complete Protocol Buffer ecosystem with gRPC, CMake integration, and embedded-friendly alternatives like nanopb.
| Plugin | Description | Generated Files |
|---|---|---|
protoc | Base message generation | *.pb.cc, *.pb.h |
grpc_cpp_plugin | gRPC service generation | *.grpc.pb.cc, *.grpc.pb.h |
| Plugin | Description | Generated Files |
|---|---|---|
nanopb | Embedded C/C++ (minimal RAM) | *.pb.c, *.pb.h |
protobuf-c | Pure C code generation | *.pb-c.c, *.pb-c.h |
languages.cpp = { enable = true; outputPath = "gen/cpp"; standard = "c++17"; optimizeFor = "SPEED";};languages.cpp = { enable = true; outputPath = "gen/cpp";
# Protobuf version selection protobufVersion = "latest"; # Options: "3.21", "3.25", "3.27", "4.25", "5.29", "latest"
# C++ standard and optimization standard = "c++17"; # Options: "c++17", "c++20", "c++23" optimizeFor = "SPEED"; # Options: "SPEED", "CODE_SIZE", "LITE_RUNTIME" runtime = "full"; # Options: "full", "lite"
# Build system integration cmakeIntegration = true; pkgConfigIntegration = true;
# Performance options arenaAllocation = false; # Enable arena allocation for better performance
# Additional include paths includePaths = [ "/usr/local/include" "./third_party" ];
# gRPC support grpc = { enable = true; generateMockCode = true; # Generate mock code for testing options = [ "generate_mock_code=true" ]; };
# Embedded C/C++ support nanopb = { enable = true; options = [ "max_size=1024" "max_count=16" ]; };
# Pure C support protobuf-c = { enable = false; options = []; };};Control exactly which proto files C++ processes using files and additionalFiles:
Use Case: C++ embedded application needs only core protocol definitions.
languages.cpp = { enable = true; outputPath = "embedded/proto"; # Override: Only embedded-friendly, minimal protocols files = [ "./proto/common/v1/types.proto" "./proto/embedded/v1/sensor_data.proto" "./proto/embedded/v1/control_messages.proto" "./proto/embedded/v1/status_reports.proto" # No complex APIs or large message definitions ]; nanopb.enable = true; optimizeFor = "CODE_SIZE"; runtime = "lite";};Use Case: Include system-level and third-party protocol definitions.
languages.cpp = { enable = true; standard = "c++20"; # Use global files + additional system-level dependencies additionalFiles = [ "./proto/system/v1/logging.proto" "./proto/third_party/opencensus/trace.proto" "./proto/monitoring/v1/performance.proto" "./proto/networking/v1/tcp_stats.proto" ]; grpc.enable = true; arenaAllocation = true;};Use Case: C++ game engine processes only game-related protocols.
languages.cpp = { enable = true; outputPath = "game_engine/proto"; # Override: Only game engine protocols files = [ "./proto/common/v1/types.proto" "./proto/game/v1/player_state.proto" "./proto/game/v1/world_updates.proto" "./proto/game/v1/input_events.proto" "./proto/networking/v1/multiplayer.proto" # No web APIs or mobile-specific protocols ]; grpc.enable = true; optimizeFor = "SPEED"; arenaAllocation = true;};| Option | Type | Description | Example |
|---|---|---|---|
files | list | Override global files completely | Embedded system protocols |
additionalFiles | list | Extend global files | Add system monitoring protos |
Embedded Systems
Minimal protocols optimized for memory-constrained devices
High-Performance Computing
System-level protocols with performance optimizations
Game Development
Real-time protocols for game engines and multiplayer
System Programming
OS-level and network protocol definitions
Bufrnix supports all modern C++ standards:
| Mode | Description | Use Case |
|---|---|---|
SPEED | Optimize for execution speed (default) | Server applications |
CODE_SIZE | Optimize for smaller binary size | Mobile/embedded devices |
LITE_RUNTIME | Use lite runtime (smaller binary, fewer features) | Resource-constrained |
When cmakeIntegration is enabled, Bufrnix generates CMake configuration files:
# FindProtobuf.cmake generated contentfind_package(Protobuf REQUIRED)find_package(gRPC REQUIRED)
# Include generated proto headersinclude_directories(${CMAKE_CURRENT_SOURCE_DIR}/gen/cpp)
# Link against protobuf librariestarget_link_libraries(myapp protobuf::libprotobuf gRPC::grpc++)When pkgConfigIntegration is enabled, .pc files are generated for easy library discovery.
Enable gRPC to generate service stubs and client code:
grpc = { enable = true; generateMockCode = true; # Generate Google Mock compatible mocks};Generated files include:
*.grpc.pb.h)*.grpc.pb.cc)For embedded systems with limited RAM:
nanopb = { enable = true; options = [ "max_size=1024" # Maximum message size "max_count=16" # Maximum repeated field count "long_names=false" # Use shorter field names ];};For pure C environments:
protobuf-c = { enable = true; options = [];};{ languages.cpp = { enable = true; outputPath = "src/proto"; standard = "c++17"; };}#include "example.pb.h"
int main() { example::v1::User user; user.set_id(123); user.set_name("Alice");
std::string serialized; user.SerializeToString(&serialized);
return 0;}{ languages.cpp = { enable = true; grpc.enable = true; standard = "c++20"; };}#include "service.grpc.pb.h"#include <grpcpp/grpcpp.h>
class MyServiceImpl final : public MyService::Service { grpc::Status GetUser(grpc::ServerContext* context, const GetUserRequest* request, GetUserResponse* response) override { response->mutable_user()->set_id(request->id()); response->mutable_user()->set_name("User " + std::to_string(request->id())); return grpc::Status::OK; }};{ languages.cpp = { enable = true; nanopb.enable = true; nanopb.options = [ "max_size=256" "max_count=8" ]; };}#include "pb_encode.h"#include "pb_decode.h"#include "message.pb.h"
void encode_message(uint8_t *buffer, size_t buffer_size) { Message msg = Message_init_zero; msg.value = 42;
pb_ostream_t stream = pb_ostream_from_buffer(buffer, buffer_size); pb_encode(&stream, Message_fields, &msg);}SPEED for servers, CODE_SIZE for embeddedProtobuf Version Mismatch
# Ensure consistent versionsprotobufVersion = "3.27"; # Match your system protobufMissing Headers
# Add include pathsincludePaths = [ "${pkgs.protobuf}/include" "./third_party/protobuf"];gRPC Compilation Errors
# Ensure gRPC is enabled with matching protobuf versiongrpc.enable = true;protobufVersion = "3.27"; # Must match gRPC's protobuf dependency