Skip to main content

Crate zerodds_idl_python

Crate zerodds_idl_python 

Source
Expand description

Crate zerodds-idl-python. Safety classification: STANDARD.

IDL4 → Python code generator for ZeroDDS data types. Reads the IDL AST from zerodds-idl and emits @idl_struct(...) + @dataclass classes that meet the convention of the zerodds-py crate.

Build-time tool — forbid(unsafe_code), std-only.

§Layer position

Layer 3 (schema) — analogous to zerodds-idl-cpp / -csharp / -java / -rust / -ts, but emits Python code that runs against the zerodds Python library at runtime.

§Public API

§What is emitted

Per IDL construct:

IDLPython
struct (any extensibility)@idl_struct(typename=...) + @dataclass class
enumclass X(IntEnum)
module M { ... }flat class name M_Inner (Python-PSM convention)
booleanbool
short/long/long longInt16 / Int32 / Int64 (zerodds.idl brands)
unsigned short/…UInt16 / UInt32 / UInt64
octetOctet
float / double / long doubleFloat32 / Float64 / LongDouble
char / wcharChar / WChar
string / wstringString / WString
sequence<T>List[T]
T[N]List[T] (multi-dim → nested)

§Phase-2 material (today Unsupported)

  • union with a discriminator
  • bitset / bitmask
  • typedef T name (for now without a comment; phase 2: typing.TypeAlias)
  • valuetype, interface, exception
  • fixed, map, any

§Example

use zerodds_idl::config::ParserConfig;
use zerodds_idl_python::{generate_python_module, PythonGenOptions};

let ast = zerodds_idl::parse(
    "struct Greeting { long id; string<128> text; };",
    &ParserConfig::default(),
)
.expect("parse");
let py_src =
    generate_python_module(&ast, &PythonGenOptions::default()).expect("gen");
assert!(py_src.contains("@dataclass"));
assert!(py_src.contains("class Greeting:"));
assert!(py_src.contains("id: Int32"));
assert!(py_src.contains("text: String"));

Re-exports§

pub use emitter::PythonGenOptions;
pub use emitter::generate_python_module;
pub use error::IdlPythonError;
pub use error::Result;

Modules§

emitter
IDL → Python codegen — emit logic.
error
Error family for the zerodds-idl-python codegen.