hdds_gen Code Generator
hdds_gen (CLI: hddsgen) is a high-performance IDL 4.2 code generator that produces type support code for multiple languages from a single IDL source.
Features
- Full IDL 4.2 compliance - 100% support for basic types, templates, constructs
- 7 target languages - Rust, C++, C, Python, TypeScript, Micro (embedded Rust), C-Micro
- Zero dependencies - Generated code is self-contained
- CDR2 serialization - Automatic encode/decode implementation
- XTypes support - Type evolution and compatibility
- CI/CD ready - JSON diagnostics, deterministic output
Quick Start
# Install
cargo install hdds-gen
# Generate Rust code
hddsgen gen rust MyTypes.idl -o my_types.rs
# Generate C++ with namespace
hddsgen gen cpp MyTypes.idl --namespace-cpp "MyApp::Types" -o my_types.hpp
# Generate TypeScript
hddsgen gen typescript MyTypes.idl -o my_types.ts
# Generate full example project
hddsgen gen rust MyTypes.idl --example --out-dir ./my_project
Subcommands
| Command | Purpose |
|---|---|
gen | Generate code in target language |
parse | Validate IDL and pretty-print AST |
check | Validate with structural checks (CI-friendly) |
fmt | Reformat IDL to canonical style |
Target Languages
| Language | Output | Use Case |
|---|---|---|
rust | Idiomatic Rust with derives | Native Rust DDS applications |
cpp | Modern C++ headers (.hpp) | C++ DDS applications |
c | Header-only C99 | Embedded systems, FFI |
python | Dataclasses with type hints | Scripting, prototyping |
typescript | Interfaces + CDR2 encode/decode | Web apps, Node.js, Deno |
micro | no_std Rust | Embedded Rust (ESP32, ARM) |
c-micro | Header-only MCU C | STM32, AVR, PIC, ESP32 |
Feature Support Matrix
Not all backends support all IDL features. Here's the honest breakdown:
| Feature | Rust | C++ | C | Python | TS | micro | c-micro |
|---|---|---|---|---|---|---|---|
| Primitives | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Struct | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| @key | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| @optional | ✅ | ✅ | ⚠️ | ✅ | ✅ | ❌ | ❌ |
| Nested structs | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Enum | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Union | ✅ | ✅ | ⚠️ | ✅ | ✅ | ✅ | ✅ |
| Typedef | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| Sequence | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Array | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Map | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| Bitset | ✅ | ✅ | ✅ | ⚠️ | ✅ | ❌ | ❌ |
| Bitmask | ✅ | ✅ | ✅ | ⚠️ | ✅ | ❌ | ❌ |
| Modules | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Inheritance | ✅ | ✅ | ✅ | ✅ | ⚠️ | ❌ | ❌ |
| @extensibility | ✅ | ✅ | ⚠️ | ✅ | ✅ | ❌ | ❌ |
Legend: ✅ Full support (def + codec) | ⚠️ Partial | ❌ Not supported
Coverage Score
| Backend | Score | Notes |
|---|---|---|
| Rust | 100% | Full IDL 4.2 compliance |
| C++ | 100% | Full IDL 4.2 compliance |
| TypeScript | 97% | Inheritance codec partial |
| Python | 94% | Bitset/Bitmask codec partial |
| C | 88% | Legacy C89 constraints |
| micro | 63% | Embedded constraints (no_std) |
| c-micro | 63% | Embedded constraints (MCU) |
Known Gaps by Design
| Backend | Missing Features | Reason |
|---|---|---|
| C | @optional, Union decode, @extensibility | Legacy C89 compatibility |
| micro/c-micro | Map, Bitset, Bitmask, Typedef, @optional | no_std/embedded constraints |
| Python | Bitset/Bitmask codec | Planned improvement |
| TypeScript | Inheritance codec | Interface extends OK, codec to verify |
Example
Input: Temperature.idl
module sensors {
@topic
struct Temperature {
@key string sensor_id;
float value;
unsigned long long timestamp;
};
};
Output: Rust
#[derive(Debug, Clone, Serialize, Deserialize, Topic)]
pub struct Temperature {
#[key]
pub sensor_id: String,
pub value: f32,
pub timestamp: u64,
}
Output: C
typedef struct {
char* sensor_id;
float value;
uint64_t timestamp;
} sensors_Temperature;
int32_t sensors_Temperature_encode(const sensors_Temperature* p, uint8_t* buf, uint32_t len);
int32_t sensors_Temperature_decode(sensors_Temperature* p, const uint8_t* buf, uint32_t len);
Next Steps
- Installation - Install hdds_gen
- CLI Reference - All command options
- IDL Syntax - Supported IDL features