idl

package
v0.52.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

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

func Generate

func Generate(m *Module) (string, error)

Generate produces a Go source file from m. The returned string is a complete, gofmt-formatted Go source file ready to be written to disk.

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 ParseFile

func ParseFile(path string) (*Module, error)

ParseFile parses path as an IDL file and returns the top-level Module.

func ParseString

func ParseString(src string) (*Module, error)

ParseString parses src as IDL source and returns the top-level Module.

type Struct

type Struct struct {
	Name   string  // struct name
	Fields []Field // ordered fields
}

Struct is an IDL struct declaration.

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.

type Typedef added in v0.14.0

type Typedef struct {
	Name string   // alias name
	Type TypeSpec // underlying type
}

Typedef is an IDL typedef declaration: typedef BaseType AliasName.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL