Documentation
¶
Overview ¶
Package idl provides an OMG IDL parser and Go source code generator for go-DDS (Milestone M2 — Developer Experience).
ParseFile and ParseString parse a subset of OMG IDL 4.x:
- module declarations (may be nested)
- struct declarations with nested struct references
- enum declarations
- basic types: boolean, octet, short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, string
- sequence types: sequence<T> and bounded sequence<T, N>
- bounded strings: string<N>
- fixed-size arrays: T name[N]
- qualified type names: Module::TypeName
Generate produces a Go source file containing:
- A Go struct for every IDL struct (fields exported, names converted to Go style)
- A codec type (e.g., SpeedCodec) implementing dds.Codec[T] using CDR/XCDR1 encoding
- A package declaration derived from the top-level module name (or "idlgen" if absent)
Usage ¶
m, err := idl.ParseFile("vehicle.idl")
if err != nil {
log.Fatal(err)
}
src, err := idl.Generate(m)
if err != nil {
log.Fatal(err)
}
os.WriteFile("vehicle_gen.go", []byte(src), 0o644)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Enum ¶ added in v0.13.2
type Enum struct {
Name string // enum name
Values []string // enumerator names in declaration order
}
Enum is an IDL enum declaration.
type Field ¶
type Field struct {
Name string // IDL identifier (original case)
Type TypeSpec // field type
Key bool // true when the field carries an @key annotation
}
Field is one field within an IDL struct.
type Module ¶
type Module struct {
Name string // module name (empty for file-level scope)
Typedefs []Typedef // typedef aliases defined in this module
Enums []Enum // enums defined in this module
Structs []Struct // structs defined in this module
Modules []*Module // nested sub-modules
}
Module is the top-level container returned by ParseString / ParseFile. It may contain both structs defined directly at module scope and sub-modules.
func ParseString ¶
ParseString parses src as IDL source and returns the top-level Module.
type TypeKind ¶
type TypeKind int
TypeKind identifies a primitive or compound IDL type.
const ( KindBoolean TypeKind = iota // IDL: boolean → Go: bool KindOctet // IDL: octet → Go: uint8 KindShort // IDL: short → Go: int16 KindUShort // IDL: unsigned short → Go: uint16 KindLong // IDL: long → Go: int32 KindULong // IDL: unsigned long → Go: uint32 KindLongLong // IDL: long long → Go: int64 KindULongLong // IDL: unsigned long long → Go: uint64 KindFloat // IDL: float → Go: float32 KindDouble // IDL: double → Go: float64 KindString // IDL: string → Go: string KindSequence // IDL: sequence<T> → Go: []ElemType KindStruct // IDL: struct T (cross-reference by name) KindArray // IDL: T name[N] → Go: [N]T KindEnum // IDL: enum E { A, B } → Go: type E int32 )
type TypeSpec ¶
type TypeSpec struct {
Kind TypeKind
ElemType *TypeSpec // non-nil for KindSequence and KindArray
ArraySize int // non-zero for KindArray: number of elements
RefName string // non-empty for KindStruct and KindEnum: IDL name (may be Module::Name)
}
TypeSpec describes the type of a field.
Click to show internal directories.
Click to hide internal directories.