Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enumType to MessageDefinitionField #7

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually do this in a follow-up PR don't we? In case theres some other things merging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 I don't think we're consistent about it.

"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