idl

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MPL-2.0 Imports: 5 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
  • basic types: boolean, octet, short, unsigned short, long, unsigned long, long long, unsigned long long, float, double, string
  • sequence types: sequence<T>

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 Go source file ready to be written to disk (run gofmt over it for canonical formatting).

Types

type Field

type Field struct {
	Name string   // IDL identifier (original case)
	Type TypeSpec // field type
}

Field is one field within an IDL struct.

type Module

type Module struct {
	Name    string    // module name (empty for file-level scope)
	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)
)

type TypeSpec

type TypeSpec struct {
	Kind     TypeKind
	ElemType *TypeSpec // non-nil for KindSequence: element type
	RefName  string    // non-empty for KindStruct: referenced struct name
}

TypeSpec describes the type of a field (primitive, sequence, or named struct).

Jump to

Keyboard shortcuts

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