C++ guide
How to use C++ headers and sources generated by DeukPack in your project. For servers and native tools.
1. Code generation
Specify --cpp to generate C++ from IDL.
npx deukpack ./schema.deuk ./gen --cpp --protocol tbinary
Output goes under gen/cpp/ (or your specified folder) as <stem>_deuk.h and <stem>_deuk.cpp per IDL source file (the _deuk suffix avoids colliding with hand-written headers like Foo.h). An include-only .deuk emits an umbrella <stem>_deuk.h that forward-#includes the matching *_deuk.h headers (no outer C++ namespace wrapper). C++17 is assumed.
2. Including in the build
- Include path: Add the directory containing generated headers to your include path (e.g.
gen/cpp,gen/cpp/include— structure depends on generation output). - Sources: Add generated
*_deuk.cppfiles to your build targets.
CMake example:
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../gen/cpp)
set(GEN_SOURCES
../gen/cpp/DemoPoint_deuk.cpp
../gen/cpp/DemoUser_deuk.cpp
# or file(GLOB ...) to collect generated *_deuk.cpp
)
add_executable(demo main.cpp ${GEN_SOURCES})
Actual file names and paths depend on your IDL structure. For a working example, see core repo examples/consumer-cpp.
3. Serialization & deserialization
Generated C++ types serialize via Read / Write (or protocol-specific interfaces). Use buffers and streams as provided by the runtime.
Concept example:
#include "gen/cpp/DemoUser_deuk.h" // actual path/header depends on generation output
// Write
DemoUser user;
user.id = 1;
user.name = "Alice";
user.home.x = 10;
user.home.y = 20;
// call user.Write(...) with protocol-specific Writer → serializes to buffer/stream
// Read
// call DemoUser::Read(...) with Reader from buffer/stream → restores instance
See the generated code and core C++ runtime documentation for the exact API.
4. kFieldId · pack/binary write · extends
Each generated struct includes:
kFieldId_*—static constexpr intfield ID constants. UseStructName::kFieldId_PropertyName.- Emitted pack/binary (or Thrift interop) write helpers — same field-ID model as C#/JS; use them next to your types for fan-out and partial sends (no separate
apply_overridesstep). - struct extends — use
extendsin IDL to auto-merge parent fields into child. Generated as a flat struct.
Tutorial & comparison: Unified Write tutorial · API reference.
5. Protocol (Binary / Compact / JSON)
The Reader/Writer used depends on --protocol tbinary (or tcompact, tjson, pack, json, …) at generation time.
- binary: Binary format compatible with Thrift Binary protocol.
- compact: Space-efficient binary.
- json: Useful for debugging and REST integration.
For selection criteria, see Protocol & serialization.
6. Next steps
- Unified Write tutorial — Overrides, field selection, extends
- Protocol & serialization — Protocol differences and usage flow
- API reference — CLI options and generated artifacts overview
- Core examples/consumer-cpp — CMake + runnable C++ sample