Language Basics
This page introduces the core elements of the XIDL language: basic and container types, structs, enums, interfaces, and unions.
Basic Types
Section titled “Basic Types”The following basic types are available:
| Type Name | Description |
|---|---|
| uint8 | 8-bit unsigned integer |
| uint16 | 16-bit unsigned integer |
| uint32 | 32-bit unsigned integer |
| uint64 | 64-bit unsigned integer |
| int8 | 8-bit signed integer |
| int16 | 16-bit signed integer |
| int32 | 32-bit signed integer |
| int64 | 64-bit signed integer |
| float32 | 32-bit single-precision floating-point number |
| float64 | 64-bit double-precision floating-point number |
| boolean | Boolean value |
| string | String |
Container Types
Section titled “Container Types”| Type Name | Description |
|---|---|
| sequence<T> | Variable-length array with elements of type T |
| map<K, V> | Key-value pair collection with keys of type K and values of type V |
Structs
Section titled “Structs”struct Point { uint32 x; uint32 y;};Struct Inheritance
Section titled “Struct Inheritance”A struct may inherit from exactly one other struct. Inheritance is a data contract, not a class hierarchy: the base members are flattened into the derived struct’s JSON shape.
struct UserRef { string id;};
struct Participant : UserRef { string role;};Both UserRef and Participant serialize id at the top level. A
Participant value is { "id": "...", "role": "..." }, never
{ "base": { "id": "..." }, "role": "..." }.
The rules are:
- A struct has at most one base struct.
- The base must be a complete struct declaration.
- An inheritance cycle is rejected.
- A derived struct may not declare a field that an ancestor already declares.
@rename,@rename_all,@optional, and@skipon base fields keep their meaning in the derived wire shape.
Targets keep their native type relation while using the same flat JSON shape:
Rust stores the base in a flattened base field, TypeScript uses extends,
Go embeds the base struct, OpenAPI emits an allOf composition, and the
remaining JSON schemas and validators declare the inherited members directly.
Version adapters treat a changed inherited model as an explicit application
decision and require a conversion hook instead of guessing a field layout.
enum Color { Red, Green, Blue};Interfaces
Section titled “Interfaces”interface ILogger { void log(string message);};enum Color { Red, Green, Blue};
struct Coordinates { uint32 x; uint32 y;};
union ColorPoint switch(Color) { case Color::Red: Coordinates red; case Color::Green: Coordinates green; case Color::Blue: Coordinates blue; default: Coordinates other;};Enum case labels must include the enum name, such as Color::Red. Declared
constants can be referenced directly. Each case has one payload; use a struct
when it needs multiple fields.
Annotations
Section titled “Annotations”struct Point { uint32 x; @optional uint32 y;};See Annotations for the full built-in annotation reference, and Compiler Pragmas for compiler-level directives.