Skip to content

Commit

Permalink
Add enumType to MessageDefinitionField (#7)
Browse files Browse the repository at this point in the history
Adds an `enumType?: string` field to `MessageDefinitionField`.

Bumps package version to 0.4.0.
  • Loading branch information
jtbandes authored Nov 7, 2024
1 parent e799954 commit a33085e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# @foxglove/message-definition

[![@foxglove/message-definition on npm](https://shields.io/npm/v/@foxglove/message-definition)](https://www.npmjs.com/package/@foxglove/message-definition)

> Defines common TypeScript types for message definition schemas (ROS .msg, Protobuf, FlatBuffers, IDL, PX4 ULog, JSON Schema, etc).
## Why is this useful?

Several interface definition languages exist today for describing the structure of messages. These languages are often used to generate code for serialization and deserialization of messages. This package defines a common representation in TypeScript for interface definitions, sometimes referred to as message definitions, so they can be reasoned about in a generic way. A concrete example of this is in [Foxglove Studio](https://github.com/foxglove/studio), which supports many different message serializations but provides common functionality across all of them such as [Message Path Syntax](https://foxglove.dev/docs/studio/app-concepts/message-path-syntax) and structured message display.
Several interface definition languages exist today for describing the structure of messages. These languages are often used to generate code for serialization and deserialization of messages. This package defines a common representation in TypeScript for interface definitions, sometimes referred to as message definitions, so they can be reasoned about in a generic way. A concrete example of this is in [Foxglove](https://foxglove.dev/product), which supports many different message serializations but provides common functionality across all of them such as [Message Path Syntax](https://docs.foxglove.dev/docs/visualization/message-path-syntax/) and structured message display.

## Examples

Expand Down Expand Up @@ -55,4 +57,4 @@ Note that this package only provides type definitions, not any functionality for

## Stay in touch

Join our [Slack channel](https://foxglove.dev/slack) to ask questions, share feedback, and stay up to date on what our team is working on.
Join our [Discord community](https://foxglove.dev/chat) to ask questions, share feedback, and stay up to date on what our team is working on.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foxglove/message-definition",
"version": "0.3.1",
"version": "0.4.0",
"description": "Defines common types for message definition schemas (ROS .msg, Protobuf, FlatBuffers, IDL, PX4 ULog, JSON Schema, etc)",
"license": "MIT",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function isMsgDefFieldEqual(
lhs.type === rhs.type &&
lhs.name === rhs.name &&
(lhs.isComplex ?? false) === (rhs.isComplex ?? false) &&
lhs.enumType === rhs.enumType &&
(lhs.isArray ?? false) === (rhs.isArray ?? false) &&
lhs.arrayLength === rhs.arrayLength &&
(lhs.isConstant ?? false) === (rhs.isConstant ?? false) &&
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export type MessageDefinitionField = {
* primitive type, a custom struct).
*/
isComplex?: boolean;
/**
* Name of an enumeration type associated with this field. The field should contain a primitive
* value (`isComplex !== true`).
*/
enumType?: string;

/**
* Set to true if this field is an array. For example, the following Protobuf
Expand Down Expand Up @@ -122,6 +127,7 @@ export type MessageDefinitionField = {
* Would be represented as:
* ```typescript
* { type: "bool", name: "ALIVE", isConstant: true, value: true, valueText: "True" }
* ```
*/
valueText?: string;

Expand Down

0 comments on commit a33085e

Please sign in to comment.