zerodds-idl-python
IDL4 → Python codegen for ZeroDDS. Emits @idl_struct(...) +
@dataclass classes usable directly with zerodds.IdlTopic(MyClass)
— the encoder/decoder comes from the zerodds-py
runtime, this codegen only delivers the annotated classes.
Part of the ZeroDDS project. Safety class
STANDARD — forbid(unsafe_code), deterministic codegen.
Status RC phase: phase-2 coverage complete — struct (with inheritance), enum, bitmask, bitset, union, typedef, exception, module nesting, primitives, string, sequence. Not supported remain:
valuetype,interface,fixed,map,any— these return a cleanIdlPythonError::Unsupported.
Quick Start
use ParserConfig;
use ;
let ast = parse?;
let py_src =
generate_python_module?;
assert!;
assert!;
assert!;
# Ok::
In the CLI, zerodds-idlc --python -o <dir> <file.idl> handles the
codegen. Output lands as <basename>.py and imports the brands
from zerodds.idl.
Generated code
Input:
module sensors {
enum Quality { GOOD, DEGRADED, FAILED };
struct Reading {
long sensor_id;
double value;
Quality quality;
sequence<double> history;
};
};
Output (abbreviated):
# SPDX-License-Identifier: Apache-2.0
# Auto-generated by `zerodds-idl-python`. Do not edit by hand.
= 0
= 1
= 2
:
:
:
:
Application usage:
=
=
=
Construct mapping
| IDL | Python |
|---|---|
struct |
@idl_struct(typename=...) + @dataclass class |
struct Foo : Base |
class Foo(Base): (dataclass inheritance) |
enum |
class X(IntEnum) |
bitmask |
class X(IntFlag) with member = 1 << position |
bitset |
X: TypeAlias = Int64 + class X_Bits: with _SHIFT/_WIDTH/_MASK constants per bitfield |
union |
X = idl_union(typename=..., discriminator=..., cases={...}, default=...) |
typedef T name |
name: TypeAlias = T |
exception |
@idl_struct(typename=...) + @dataclass class X(Exception): |
module M { ... } |
flat class name M_Inner (Python PSM, Annex B) |
boolean |
bool |
octet |
Octet (zerodds.idl brand) |
short/long/long long |
Int16 / Int32 / Int64 |
unsigned short/unsigned long/unsigned long long |
UInt16 / UInt32 / UInt64 |
int8 / uint8 |
Int8 / UInt8 |
float / double / long double |
Float32 / Float64 / LongDouble |
char / wchar |
Char / WChar |
string / wstring (bounded or unbounded) |
String / WString |
sequence<T> |
List[T] |
T[N] (array) |
List[T] (multi-dim nested) |
| Python reserved word as field name | escaped with a _ suffix (class → class_) |
Phase 3 (today IdlPythonError::Unsupported)
valuetype,interfacefixed,map,any- union cases with
case ENUM_MEMBER:(scoped const expression — follow-up iteration) - union cases with binary const expressions (
case A | B:etc.)
Spec mapping
| Spec document | Section |
|---|---|
| OMG IDL 4.2 (ISO/IEC 19516) | §7 — construct mapping |
| OMG XTypes 1.3 Annex B (Python PSM) | class naming convention, discriminator layout |
ZeroDDS zerodds-py-1.0 (vendor spec) |
@idl_struct decorator API, type-brand names |
Features
default = []— std-only.
Stability
1.0.0-rc.2. The CLI and library API are stable; emitted code may still
change in details before 1.0.0-final (brand imports could be consolidated
after a code review).
Tests
26 smoke tests (phase 1 + phase 2: typedef, exception, bitmask, bitset, union, struct inheritance, module nesting for phase-2 constructs) + 1 doc-test.
See also
zerodds-idl— parser + AST.zerodds-py— Python runtime with@idl_struct+IdlTopic.zerodds-idlc— CLI with the--pythonflag.packaging/docker/py-runtime/— sandbox image.