@foxglove/omgidl-parser

中文文档
1.2.2发布于 2025/10/14MITTypeScriptCommonJS构建来源已验证近 30 天下载 19.1万

Parse OMG IDL to flattened definitions for serialization

原始使用文档
文档目录3 节
  1. Example
  2. API
  3. OMG IDL Subset Support

OMG IDL schema parser

OMG IDL parser to flattened message definitions for (de)serialization

npm version

This package provides functions to parse raw .idl schemas into resolved, flattened message definitions.

Output definitions can be passed to serializers along with a specified root schema name string in @foxglove/omgidl-serialization to read and write CDR, XCDR1 and XCDR2 messages.

Example


const schemaString = `
// Generated by https://github.com/foxglove/schemas

module foxglove {
// A vector in 3D space that represents a direction only
struct Vector3 {
  double x;
  double y;
  double z;
};
};

module foxglove {
struct Quaternion {
  double x;
  double y;
  double z;
  @default(1.0)
  double w;
};
};

module foxglove {
// A position and orientation for an object or reference frame in 3D space
struct Pose {
  // Point denoting position in 3D space
  Vector3 position;
  // Quaternion denoting orientation in 3D space
  Quaternion orientation;
};
};
`;

const definitions = parseIDL(schemaString);

definitions results in:

[
  {
    name: "foxglove::Vector3",
    aggregatedKind: "struct",
    definitions: [
      {
        name: "x",
        isComplex: false,
        type: "float64",
      },
      {
        name: "y",
        isComplex: false,
        type: "float64",
      },
      {
        name: "z",
        isComplex: false,
        type: "float64",
      },
    ],
  },
  {
    name: "foxglove::Quaternion",
    aggregatedKind: "struct",
    definitions: [
      {
        name: "x",
        isComplex: false,
        type: "float64",
      },
      {
        name: "y",
        isComplex: false,
        type: "float64",
      },
      {
        name: "z",
        isComplex: false,
        type: "float64",
      },
      {
        name: "w",
        annotations: {
          default: {
            name: "default",
            type: "const-param",
            value: 1,
          },
        },
        defaultValue: 1,
        isComplex: false,
        type: "float64",
      },
    ],
  },
  {
    name: "foxglove::Pose",
    aggregatedKind: "struct",
    definitions: [
      {
        isComplex: true,
        name: "position",
        type: "foxglove::Vector3",
      },
      {
        isComplex: true,
        name: "orientation",
        type: "foxglove::Quaternion",
      },
    ],
  },
]

API

parseIDL(schema: string) - parses raw .idl schema string to resolved, flattened definitions.

TypeScript types for the output definitions are also available.

OMG IDL Subset Support

NOTE: numbers like 7.4.1 refer to sections of the OMG IDL specification.

  • Generally supported features

    • 7.4.1 Building Block Core Data Types (with exceptions below)
    • support for extended numeric types uint8, int8 ... uint64, int64
      • Note 7.4.13 Building Block Extended Data-Types is not fully supported
    • Literals (with some hexadecimal, character and wide-type exceptions)
    • Blanks, horizontal and vertical tabs, newlines, form feeds, and comments (collective, "white space") as described below are ignored except as they serve to separate tokens
    • Parse generic annotations (only defaultValue is read in to AST)
    • unions and cases
    • enumerator overrides with @value annotation
    • All XCDR extensibility types: @final, @appendable, and @mutable
    • const Color color = RED; and const Color color = Color::RED; are supported.
  • Unsupported features

    • native declarations
    • forward declarations
    • Constant expressions
    • unary operators (outside of positive/negative numbers)
    • default value annotation type checking
    • identifiers prefixed with :: scope
    • aggregated type inheritance
    • Annotation definitions
    • Built-in enums from annotations (like @autoid's HASH and SEQUENTIAL enums)
    • Map types
    • @autoid(HASH) on mutable aggregated types
    • 7.2.6.1 - Octal integers are not supported (014)
    • 7.2.6.2.1 wide character and wide string has limited support
      • can be read in to schema but only considered uint8
      • wide character and string literals are not supported (L'X')
    • 7.2.6.3 - wide string literals are not supported
    • 7.2.3.1 - we do not check collision explicitly and we use case-sensitive identifiers whereas IDL requires identifiers to be case insensitive. WARNING: This can cause incorrect reading of messages.
    • 7.4.2-7.4.16 extended IDL building blocks not supported
    • Composing variable-sized array typedefs with other array typedefs or struct member nodes.
  • Unsupported reference and type resolution features

    • numeric type checking for constant usage. This means that if you use a mis-typed constant it could cause message read errors or the mismatched type will show up in the deserialized message.
    • we do not enforce type-based value ranges on constants in schema

版本与发布记录

@foxglove/omgidl-parser 共发布 13 个版本,首次发布于 2023/07/14;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.2latest2025/10/141.1 年前
1.2.12025/08/151.3 年前
1.2.02025/05/221.5 年前
1.1.02024/11/082 年前
1.0.52024/05/152 年前
1.0.42024/04/112 年前

关于 @foxglove/omgidl-parser 的常见问题

@foxglove/omgidl-parser 是什么?

Parse OMG IDL to flattened definitions for serialization

如何安装 @foxglove/omgidl-parser?

在项目目录运行 npm install @foxglove/omgidl-parser,或使用 pnpm add / yarn add / bun add。

@foxglove/omgidl-parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@foxglove/omgidl-parser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@foxglove/omgidl-parser 可以商用吗?

@foxglove/omgidl-parser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@foxglove/omgidl-parser 的下载量有多少?

根据 npm 官方下载统计,@foxglove/omgidl-parser 在 2026/10/16 – 2026/11/14 这 30 天内被下载 190,619 次,日均约 6,354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@foxglove/omgidl-parser 还在维护吗?

最新版本 1.2.2 发布于 2025/10/14(1.1 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。