From 15c29ffc1c8d5537a56b32404dfdc8958cce00d8 Mon Sep 17 00:00:00 2001 From: snosenzo Date: Tue, 8 Nov 2022 21:14:40 +0100 Subject: [PATCH 01/15] - script for generating schemas complete need to test - tested compilation is successful --- internal/generateFlatbuffer.ts | 107 ++++++++++++++++++ .../flatbuffer/foxglove/ArrowPrimitive.fbs | 30 +++++ .../flatbuffer/foxglove/CameraCalibration.fbs | 77 +++++++++++++ .../flatbuffer/foxglove/CircleAnnotation.fbs | 31 +++++ schemas/flatbuffer/foxglove/Color.fbs | 21 ++++ .../flatbuffer/foxglove/CompressedImage.fbs | 23 ++++ schemas/flatbuffer/foxglove/CubePrimitive.fbs | 22 ++++ .../flatbuffer/foxglove/CylinderPrimitive.fbs | 28 +++++ schemas/flatbuffer/foxglove/Duration.fbs | 4 + .../flatbuffer/foxglove/FrameTransform.fbs | 28 +++++ schemas/flatbuffer/foxglove/GeoJSON.fbs | 12 ++ schemas/flatbuffer/foxglove/Grid.fbs | 41 +++++++ .../flatbuffer/foxglove/ImageAnnotations.fbs | 18 +++ schemas/flatbuffer/foxglove/KeyValuePair.fbs | 15 +++ schemas/flatbuffer/foxglove/LaserScan.fbs | 33 ++++++ schemas/flatbuffer/foxglove/LinePrimitive.fbs | 50 ++++++++ schemas/flatbuffer/foxglove/LocationFix.fbs | 35 ++++++ schemas/flatbuffer/foxglove/Log.fbs | 43 +++++++ .../flatbuffer/foxglove/ModelPrimitive.fbs | 34 ++++++ .../foxglove/PackedElementField.fbs | 38 +++++++ schemas/flatbuffer/foxglove/Point2.fbs | 15 +++ schemas/flatbuffer/foxglove/Point3.fbs | 18 +++ schemas/flatbuffer/foxglove/PointCloud.fbs | 31 +++++ .../flatbuffer/foxglove/PointsAnnotation.fbs | 46 ++++++++ schemas/flatbuffer/foxglove/Pose.fbs | 18 +++ schemas/flatbuffer/foxglove/PoseInFrame.fbs | 21 ++++ schemas/flatbuffer/foxglove/PosesInFrame.fbs | 21 ++++ schemas/flatbuffer/foxglove/Quaternion.fbs | 21 ++++ schemas/flatbuffer/foxglove/RawImage.fbs | 32 ++++++ schemas/flatbuffer/foxglove/SceneEntity.fbs | 63 +++++++++++ .../foxglove/SceneEntityDeletion.fbs | 28 +++++ schemas/flatbuffer/foxglove/SceneUpdate.fbs | 18 +++ .../flatbuffer/foxglove/SpherePrimitive.fbs | 22 ++++ schemas/flatbuffer/foxglove/TextPrimitive.fbs | 30 +++++ schemas/flatbuffer/foxglove/Time.fbs | 4 + .../foxglove/TriangleListPrimitive.fbs | 30 +++++ schemas/flatbuffer/foxglove/Vector2.fbs | 15 +++ schemas/flatbuffer/foxglove/Vector3.fbs | 18 +++ scripts/updateGeneratedFiles.ts | 16 +++ 39 files changed, 1157 insertions(+) create mode 100644 internal/generateFlatbuffer.ts create mode 100644 schemas/flatbuffer/foxglove/ArrowPrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/CameraCalibration.fbs create mode 100644 schemas/flatbuffer/foxglove/CircleAnnotation.fbs create mode 100644 schemas/flatbuffer/foxglove/Color.fbs create mode 100644 schemas/flatbuffer/foxglove/CompressedImage.fbs create mode 100644 schemas/flatbuffer/foxglove/CubePrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/CylinderPrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/Duration.fbs create mode 100644 schemas/flatbuffer/foxglove/FrameTransform.fbs create mode 100644 schemas/flatbuffer/foxglove/GeoJSON.fbs create mode 100644 schemas/flatbuffer/foxglove/Grid.fbs create mode 100644 schemas/flatbuffer/foxglove/ImageAnnotations.fbs create mode 100644 schemas/flatbuffer/foxglove/KeyValuePair.fbs create mode 100644 schemas/flatbuffer/foxglove/LaserScan.fbs create mode 100644 schemas/flatbuffer/foxglove/LinePrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/LocationFix.fbs create mode 100644 schemas/flatbuffer/foxglove/Log.fbs create mode 100644 schemas/flatbuffer/foxglove/ModelPrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/PackedElementField.fbs create mode 100644 schemas/flatbuffer/foxglove/Point2.fbs create mode 100644 schemas/flatbuffer/foxglove/Point3.fbs create mode 100644 schemas/flatbuffer/foxglove/PointCloud.fbs create mode 100644 schemas/flatbuffer/foxglove/PointsAnnotation.fbs create mode 100644 schemas/flatbuffer/foxglove/Pose.fbs create mode 100644 schemas/flatbuffer/foxglove/PoseInFrame.fbs create mode 100644 schemas/flatbuffer/foxglove/PosesInFrame.fbs create mode 100644 schemas/flatbuffer/foxglove/Quaternion.fbs create mode 100644 schemas/flatbuffer/foxglove/RawImage.fbs create mode 100644 schemas/flatbuffer/foxglove/SceneEntity.fbs create mode 100644 schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs create mode 100644 schemas/flatbuffer/foxglove/SceneUpdate.fbs create mode 100644 schemas/flatbuffer/foxglove/SpherePrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/TextPrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/Time.fbs create mode 100644 schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs create mode 100644 schemas/flatbuffer/foxglove/Vector2.fbs create mode 100644 schemas/flatbuffer/foxglove/Vector3.fbs diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts new file mode 100644 index 0000000..1be963f --- /dev/null +++ b/internal/generateFlatbuffer.ts @@ -0,0 +1,107 @@ +import { FoxgloveEnumSchema, FoxgloveMessageSchema, FoxglovePrimitive } from "./types"; + +export const TIME_FB = `struct Time { + sec:uint; + nsec:uint; +} +`; + +export const DURATION_FB = `struct Duration { + sec:uint; + nsec:uint; +} +`; + +function primitiveToFlatbuffer(type: Exclude) { + switch (type) { + case "uint32": + return "uint"; + case "bytes": + return "[byte]"; + case "string": + return "string"; + case "boolean": + return "bool"; + case "float64": + return "double"; + } +} + +export function generateFlatbuffer( + schema: FoxgloveMessageSchema, + nestedEnums: FoxgloveEnumSchema[], +): string { + const enumDefinitions: string[] = []; + for (const enumSchema of nestedEnums) { + const fields = enumSchema.values.map(({ name, value, description }) => { + if (description != undefined) { + return `/// ${description}\n ${name} = ${value},`; + } else { + return `${name} = ${value},`; + } + }); + enumDefinitions.push( + // `///` comments required to show up in compiled flatbuffer schemas + `/// ${enumSchema.description}\nenum ${enumSchema.name} : byte {\n ${fields.join( + "\n\n ", + )}\n}\n`, + ); + } + + const imports = new Set(); + const fields = schema.fields.map((field) => { + const isArray = field.array != undefined; + + let type; + switch (field.type.type) { + case "enum": + type = field.type.enum.name; + break; + case "nested": + type = `foxglove.${field.type.schema.name}`; + imports.add(`${field.type.schema.name}`); + break; + case "primitive": + if (field.type.name === "time") { + type = "Time"; + imports.add(`Time`); + } else if (field.type.name === "duration") { + type = "Duration"; + imports.add(`Duration`); + } else { + type = primitiveToFlatbuffer(field.type.name); + } + break; + } + let lengthComment; + + if (typeof field.array === "number") { + // can't have inline comments + lengthComment = ` /// length ${field.array}\n`; + } + return `${field.description + .trim() + .split("\n") + .map((line) => ` /// ${line}\n`) + .join("")}${lengthComment ?? ""} ${field.name}:${isArray ? `[${type}]` : type};`; + }); + + const definition = `${enumDefinitions.join("\n\n")}\n/// ${schema.description}\ntable ${ + schema.name + } {\n${fields.join("\n\n")}\n}\n\nroot_type ${schema.name};`; + + const outputSections = [ + `// Generated by https://github.com/foxglove/schemas`, + + Array.from(imports) + .sort() + .map((name) => `include "${name}.fbs";`) + .join("\n"), + + `namespace foxglove;`, + + definition, + ].filter(Boolean); + + return outputSections.join("\n\n") + "\n"; +} diff --git a/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs b/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs new file mode 100644 index 0000000..f7393d0 --- /dev/null +++ b/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs @@ -0,0 +1,30 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; + +namespace foxglove; + + +/// A primitive representing an arrow +table ArrowPrimitive { + /// Position of the arrow's tail and orientation of the arrow. Identity orientation means the arrow points in the +x direction. + pose:foxglove.Pose; + + /// Length of the arrow shaft + shaft_length:double; + + /// Diameter of the arrow shaft + shaft_diameter:double; + + /// Length of the arrow head + head_length:double; + + /// Diameter of the arrow head + head_diameter:double; + + /// Color of the arrow + color:foxglove.Color; +} + +root_type ArrowPrimitive; diff --git a/schemas/flatbuffer/foxglove/CameraCalibration.fbs b/schemas/flatbuffer/foxglove/CameraCalibration.fbs new file mode 100644 index 0000000..035477c --- /dev/null +++ b/schemas/flatbuffer/foxglove/CameraCalibration.fbs @@ -0,0 +1,77 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + + +/// Camera calibration parameters +table CameraCalibration { + /// Timestamp of calibration data + timestamp:Time; + + /// Frame of reference for the camera. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Image width + width:uint; + + /// Image height + height:uint; + + /// Name of distortion model + distortion_model:string; + + /// Distortion parameters + D:[double]; + + /// Intrinsic camera matrix (3x3 row-major matrix) + /// + /// A 3x3 row-major matrix for the raw (distorted) image. + /// + /// Projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx, fy) and principal point (cx, cy). + /// + /// ``` + /// [fx 0 cx] + /// K = [ 0 fy cy] + /// [ 0 0 1] + /// ``` + /// length 9 + K:[double]; + + /// Rectification matrix (3x3 row-major matrix) + /// + /// A rotation matrix aligning the camera coordinate system to the ideal stereo image plane so that epipolar lines in both stereo images are parallel. + /// length 9 + R:[double]; + + /// Projection/camera matrix (3x4 row-major matrix) + /// + /// ``` + /// [fx' 0 cx' Tx] + /// P = [ 0 fy' cy' Ty] + /// [ 0 0 1 0] + /// ``` + /// + /// By convention, this matrix specifies the intrinsic (camera) matrix of the processed (rectified) image. That is, the left 3x3 portion is the normal camera intrinsic matrix for the rectified image. + /// + /// It projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx', fy') and principal point (cx', cy') - these may differ from the values in K. + /// + /// For monocular cameras, Tx = Ty = 0. Normally, monocular cameras will also have R = the identity and P[1:3,1:3] = K. + /// + /// For a stereo pair, the fourth column [Tx Ty 0]' is related to the position of the optical center of the second camera in the first camera's frame. We assume Tz = 0 so both cameras are in the same stereo image plane. The first camera always has Tx = Ty = 0. For the right (second) camera of a horizontal stereo pair, Ty = 0 and Tx = -fx' * B, where B is the baseline between the cameras. + /// + /// Given a 3D point [X Y Z]', the projection (x, y) of the point onto the rectified image is given by: + /// + /// ``` + /// [u v w]' = P * [X Y Z 1]' + /// x = u / w + /// y = v / w + /// ``` + /// + /// This holds for both images of a stereo pair. + /// length 12 + P:[double]; +} + +root_type CameraCalibration; diff --git a/schemas/flatbuffer/foxglove/CircleAnnotation.fbs b/schemas/flatbuffer/foxglove/CircleAnnotation.fbs new file mode 100644 index 0000000..b5894ae --- /dev/null +++ b/schemas/flatbuffer/foxglove/CircleAnnotation.fbs @@ -0,0 +1,31 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point2.fbs"; +include "Time.fbs"; + +namespace foxglove; + + +/// A circle annotation on a 2D image +table CircleAnnotation { + /// Timestamp of circle + timestamp:Time; + + /// Center of the circle in 2D image coordinates + position:foxglove.Point2; + + /// Circle diameter + diameter:double; + + /// Line thickness + thickness:double; + + /// Fill color + fill_color:foxglove.Color; + + /// Outline color + outline_color:foxglove.Color; +} + +root_type CircleAnnotation; diff --git a/schemas/flatbuffer/foxglove/Color.fbs b/schemas/flatbuffer/foxglove/Color.fbs new file mode 100644 index 0000000..1eef339 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Color.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A color in RGBA format +table Color { + /// Red value between 0 and 1 + r:double; + + /// Green value between 0 and 1 + g:double; + + /// Blue value between 0 and 1 + b:double; + + /// Alpha value between 0 and 1 + a:double; +} + +root_type Color; diff --git a/schemas/flatbuffer/foxglove/CompressedImage.fbs b/schemas/flatbuffer/foxglove/CompressedImage.fbs new file mode 100644 index 0000000..f9f0c7b --- /dev/null +++ b/schemas/flatbuffer/foxglove/CompressedImage.fbs @@ -0,0 +1,23 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + + +/// A compressed image +table CompressedImage { + /// Timestamp of image + timestamp:Time; + + /// Frame of reference for the image. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Compressed image data + data:[byte]; + + /// Image format + format:string; +} + +root_type CompressedImage; diff --git a/schemas/flatbuffer/foxglove/CubePrimitive.fbs b/schemas/flatbuffer/foxglove/CubePrimitive.fbs new file mode 100644 index 0000000..33212e8 --- /dev/null +++ b/schemas/flatbuffer/foxglove/CubePrimitive.fbs @@ -0,0 +1,22 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A primitive representing a cube or rectangular prism +table CubePrimitive { + /// Position of the center of the cube and orientation of the cube + pose:foxglove.Pose; + + /// Size of the cube along each axis + size:foxglove.Vector3; + + /// Color of the arrow + color:foxglove.Color; +} + +root_type CubePrimitive; diff --git a/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs b/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs new file mode 100644 index 0000000..4ae5c49 --- /dev/null +++ b/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs @@ -0,0 +1,28 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A primitive representing a cylinder, elliptic cylinder, or truncated cone +table CylinderPrimitive { + /// Position of the center of the cylinder and orientation of the cylinder. The flat face(s) are perpendicular to the z-axis. + pose:foxglove.Pose; + + /// Size of the cylinder's bounding box + size:foxglove.Vector3; + + /// 0-1, ratio of the diameter of the cylinder's bottom face (min z) to the bottom of the bounding box + bottom_scale:double; + + /// 0-1, ratio of the diameter of the cylinder's top face (max z) to the top of the bounding box + top_scale:double; + + /// Color of the cylinder + color:foxglove.Color; +} + +root_type CylinderPrimitive; diff --git a/schemas/flatbuffer/foxglove/Duration.fbs b/schemas/flatbuffer/foxglove/Duration.fbs new file mode 100644 index 0000000..162eda1 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Duration.fbs @@ -0,0 +1,4 @@ +struct Duration { + sec:uint; + nsec:uint; +} diff --git a/schemas/flatbuffer/foxglove/FrameTransform.fbs b/schemas/flatbuffer/foxglove/FrameTransform.fbs new file mode 100644 index 0000000..f7a6a1a --- /dev/null +++ b/schemas/flatbuffer/foxglove/FrameTransform.fbs @@ -0,0 +1,28 @@ +// Generated by https://github.com/foxglove/schemas + +include "Quaternion.fbs"; +include "Time.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A transform between two reference frames in 3D space +table FrameTransform { + /// Timestamp of transform + timestamp:Time; + + /// Name of the parent frame + parent_frame_id:string; + + /// Name of the child frame + child_frame_id:string; + + /// Translation component of the transform + translation:foxglove.Vector3; + + /// Rotation component of the transform + rotation:foxglove.Quaternion; +} + +root_type FrameTransform; diff --git a/schemas/flatbuffer/foxglove/GeoJSON.fbs b/schemas/flatbuffer/foxglove/GeoJSON.fbs new file mode 100644 index 0000000..c7110b6 --- /dev/null +++ b/schemas/flatbuffer/foxglove/GeoJSON.fbs @@ -0,0 +1,12 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// GeoJSON data for annotating maps +table GeoJSON { + /// GeoJSON data encoded as a UTF-8 string + geojson:string; +} + +root_type GeoJSON; diff --git a/schemas/flatbuffer/foxglove/Grid.fbs b/schemas/flatbuffer/foxglove/Grid.fbs new file mode 100644 index 0000000..dff9b04 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Grid.fbs @@ -0,0 +1,41 @@ +// Generated by https://github.com/foxglove/schemas + +include "PackedElementField.fbs"; +include "Pose.fbs"; +include "Time.fbs"; +include "Vector2.fbs"; + +namespace foxglove; + + +/// A 2D grid of data +table Grid { + /// Timestamp of grid + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Origin of grid's corner relative to frame of reference; grid is positioned in the x-y plane relative to this origin + pose:foxglove.Pose; + + /// Number of grid columns + column_count:uint; + + /// Size of single grid cell along x and y axes, relative to `pose` + cell_size:foxglove.Vector2; + + /// Number of bytes between rows in `data` + row_stride:uint; + + /// Number of bytes between cells within a row in `data` + cell_stride:uint; + + /// Fields in `data` + fields:[foxglove.PackedElementField]; + + /// Grid cell data, interpreted using `fields`, in row-major (y-major) order + data:[byte]; +} + +root_type Grid; diff --git a/schemas/flatbuffer/foxglove/ImageAnnotations.fbs b/schemas/flatbuffer/foxglove/ImageAnnotations.fbs new file mode 100644 index 0000000..fac3173 --- /dev/null +++ b/schemas/flatbuffer/foxglove/ImageAnnotations.fbs @@ -0,0 +1,18 @@ +// Generated by https://github.com/foxglove/schemas + +include "CircleAnnotation.fbs"; +include "PointsAnnotation.fbs"; + +namespace foxglove; + + +/// Array of annotations for a 2D image +table ImageAnnotations { + /// Circle annotations + circles:[foxglove.CircleAnnotation]; + + /// Points annotations + points:[foxglove.PointsAnnotation]; +} + +root_type ImageAnnotations; diff --git a/schemas/flatbuffer/foxglove/KeyValuePair.fbs b/schemas/flatbuffer/foxglove/KeyValuePair.fbs new file mode 100644 index 0000000..5529310 --- /dev/null +++ b/schemas/flatbuffer/foxglove/KeyValuePair.fbs @@ -0,0 +1,15 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A key with its associated value +table KeyValuePair { + /// Key + key:string; + + /// Value + value:string; +} + +root_type KeyValuePair; diff --git a/schemas/flatbuffer/foxglove/LaserScan.fbs b/schemas/flatbuffer/foxglove/LaserScan.fbs new file mode 100644 index 0000000..bdb16b5 --- /dev/null +++ b/schemas/flatbuffer/foxglove/LaserScan.fbs @@ -0,0 +1,33 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + + +/// A single scan from a planar laser range-finder +table LaserScan { + /// Timestamp of scan + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Origin of scan relative to frame of reference; points are positioned in the x-y plane relative to this origin; angles are interpreted as counterclockwise rotations around the z axis with 0 rad being in the +x direction + pose:foxglove.Pose; + + /// Bearing of first point, in radians + start_angle:double; + + /// Bearing of last point, in radians + end_angle:double; + + /// Distance of detections from origin; assumed to be at equally-spaced angles between `start_angle` and `end_angle` + ranges:[double]; + + /// Intensity of detections + intensities:[double]; +} + +root_type LaserScan; diff --git a/schemas/flatbuffer/foxglove/LinePrimitive.fbs b/schemas/flatbuffer/foxglove/LinePrimitive.fbs new file mode 100644 index 0000000..5a33c55 --- /dev/null +++ b/schemas/flatbuffer/foxglove/LinePrimitive.fbs @@ -0,0 +1,50 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point3.fbs"; +include "Pose.fbs"; + +namespace foxglove; + +/// An enumeration indicating how input points should be interpreted to create lines +enum LineType : byte { + /// 0-1, 1-2, ..., (n-1)-n + LINE_STRIP = 0, + + /// 0-1, 1-2, ..., (n-1)-n, n-0 + LINE_LOOP = 1, + + /// 0-1, 2-3, 4-5, ... + LINE_LIST = 2, +} + +/// A primitive representing a series of points connected by lines +table LinePrimitive { + /// Drawing primitive to use for lines + type:LineType; + + /// Origin of lines relative to reference frame + pose:foxglove.Pose; + + /// Line thickness + thickness:double; + + /// Indicates whether `thickness` is a fixed size in screen pixels (true), or specified in world coordinates and scales with distance from the camera (false) + scale_invariant:bool; + + /// Points along the line + points:[foxglove.Point3]; + + /// Solid color to use for the whole line. One of `color` or `colors` must be provided. + color:foxglove.Color; + + /// Per-point colors (if specified, must have the same length as `points`). One of `color` or `colors` must be provided. + colors:[foxglove.Color]; + + /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. + /// + /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). + indices:[uint]; +} + +root_type LinePrimitive; diff --git a/schemas/flatbuffer/foxglove/LocationFix.fbs b/schemas/flatbuffer/foxglove/LocationFix.fbs new file mode 100644 index 0000000..13fef32 --- /dev/null +++ b/schemas/flatbuffer/foxglove/LocationFix.fbs @@ -0,0 +1,35 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Type of position covariance +enum PositionCovarianceType : byte { + UNKNOWN = 0, + + APPROXIMATED = 1, + + DIAGONAL_KNOWN = 2, + + KNOWN = 3, +} + +/// A navigation satellite fix for any Global Navigation Satellite System +table LocationFix { + /// Latitude in degrees + latitude:double; + + /// Longitude in degrees + longitude:double; + + /// Altitude in meters + altitude:double; + + /// Position covariance (m^2) defined relative to a tangential plane through the reported position. The components are East, North, and Up (ENU), in row-major order. + /// length 9 + position_covariance:[double]; + + /// If `position_covariance` is available, `position_covariance_type` must be set to indicate the type of covariance. + position_covariance_type:PositionCovarianceType; +} + +root_type LocationFix; diff --git a/schemas/flatbuffer/foxglove/Log.fbs b/schemas/flatbuffer/foxglove/Log.fbs new file mode 100644 index 0000000..7b629fb --- /dev/null +++ b/schemas/flatbuffer/foxglove/Log.fbs @@ -0,0 +1,43 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// Log level +enum LogLevel : byte { + UNKNOWN = 0, + + DEBUG = 1, + + INFO = 2, + + WARNING = 3, + + ERROR = 4, + + FATAL = 5, +} + +/// A log message +table Log { + /// Timestamp of log message + timestamp:Time; + + /// Log level + level:LogLevel; + + /// Log message + message:string; + + /// Process or node name + name:string; + + /// Filename + file:string; + + /// Line number in the file + line:uint; +} + +root_type Log; diff --git a/schemas/flatbuffer/foxglove/ModelPrimitive.fbs b/schemas/flatbuffer/foxglove/ModelPrimitive.fbs new file mode 100644 index 0000000..412002b --- /dev/null +++ b/schemas/flatbuffer/foxglove/ModelPrimitive.fbs @@ -0,0 +1,34 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A primitive representing a 3D model file loaded from an external URL or embedded data +table ModelPrimitive { + /// Origin of model relative to reference frame + pose:foxglove.Pose; + + /// Scale factor to apply to the model along each axis + scale:foxglove.Vector3; + + /// Solid color to use for the whole model if `override_color` is true. + color:foxglove.Color; + + /// Whether to use the color specified in `color` instead of any materials embedded in the original model. + override_color:bool; + + /// URL pointing to model file. One of `url` or `data` should be provided. + url:string; + + /// [Media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of embedded model (e.g. `model/gltf-binary`). Required if `data` is provided instead of `url`. Overrides the inferred media type if `url` is provided. + media_type:string; + + /// Embedded model. One of `url` or `data` should be provided. If `data` is provided, `media_type` must be set to indicate the type of the data. + data:[byte]; +} + +root_type ModelPrimitive; diff --git a/schemas/flatbuffer/foxglove/PackedElementField.fbs b/schemas/flatbuffer/foxglove/PackedElementField.fbs new file mode 100644 index 0000000..9808418 --- /dev/null +++ b/schemas/flatbuffer/foxglove/PackedElementField.fbs @@ -0,0 +1,38 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Numeric type +enum NumericType : byte { + UNKNOWN = 0, + + UINT8 = 1, + + INT8 = 2, + + UINT16 = 3, + + INT16 = 4, + + UINT32 = 5, + + INT32 = 6, + + FLOAT32 = 7, + + FLOAT64 = 8, +} + +/// A field present within each element in a byte array of packed elements. +table PackedElementField { + /// Name of the field + name:string; + + /// Byte offset from start of data buffer + offset:uint; + + /// Type of data in the field. Integers are stored using little-endian byte order. + type:NumericType; +} + +root_type PackedElementField; diff --git a/schemas/flatbuffer/foxglove/Point2.fbs b/schemas/flatbuffer/foxglove/Point2.fbs new file mode 100644 index 0000000..db3b988 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Point2.fbs @@ -0,0 +1,15 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A point representing a position in 2D space +table Point2 { + /// x coordinate position + x:double; + + /// y coordinate position + y:double; +} + +root_type Point2; diff --git a/schemas/flatbuffer/foxglove/Point3.fbs b/schemas/flatbuffer/foxglove/Point3.fbs new file mode 100644 index 0000000..5f71ee5 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Point3.fbs @@ -0,0 +1,18 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A point representing a position in 3D space +table Point3 { + /// x coordinate position + x:double; + + /// y coordinate position + y:double; + + /// z coordinate position + z:double; +} + +root_type Point3; diff --git a/schemas/flatbuffer/foxglove/PointCloud.fbs b/schemas/flatbuffer/foxglove/PointCloud.fbs new file mode 100644 index 0000000..4146c7b --- /dev/null +++ b/schemas/flatbuffer/foxglove/PointCloud.fbs @@ -0,0 +1,31 @@ +// Generated by https://github.com/foxglove/schemas + +include "PackedElementField.fbs"; +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + + +/// A collection of N-dimensional points, which may contain additional fields with information like normals, intensity, etc. +table PointCloud { + /// Timestamp of point cloud + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// The origin of the point cloud relative to the frame of reference + pose:foxglove.Pose; + + /// Number of bytes between points in the `data` + point_stride:uint; + + /// Fields in the `data` + fields:[foxglove.PackedElementField]; + + /// Point data, interpreted using `fields` + data:[byte]; +} + +root_type PointCloud; diff --git a/schemas/flatbuffer/foxglove/PointsAnnotation.fbs b/schemas/flatbuffer/foxglove/PointsAnnotation.fbs new file mode 100644 index 0000000..e2889b3 --- /dev/null +++ b/schemas/flatbuffer/foxglove/PointsAnnotation.fbs @@ -0,0 +1,46 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point2.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// Type of points annotation +enum PointsAnnotationType : byte { + UNKNOWN = 0, + + POINTS = 1, + + LINE_LOOP = 2, + + LINE_STRIP = 3, + + LINE_LIST = 4, +} + +/// An array of points on a 2D image +table PointsAnnotation { + /// Timestamp of annotation + timestamp:Time; + + /// Type of points annotation to draw + type:PointsAnnotationType; + + /// Points in 2D image coordinates + points:[foxglove.Point2]; + + /// Outline color + outline_color:foxglove.Color; + + /// Per-point colors, if `type` is `POINTS`, or per-segment stroke colors, if `type` is `LINE_LIST`. + outline_colors:[foxglove.Color]; + + /// Fill color + fill_color:foxglove.Color; + + /// Stroke thickness + thickness:double; +} + +root_type PointsAnnotation; diff --git a/schemas/flatbuffer/foxglove/Pose.fbs b/schemas/flatbuffer/foxglove/Pose.fbs new file mode 100644 index 0000000..6034755 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Pose.fbs @@ -0,0 +1,18 @@ +// Generated by https://github.com/foxglove/schemas + +include "Quaternion.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A position and orientation for an object or reference frame in 3D space +table Pose { + /// Point denoting position in 3D space + position:foxglove.Vector3; + + /// Quaternion denoting orientation in 3D space + orientation:foxglove.Quaternion; +} + +root_type Pose; diff --git a/schemas/flatbuffer/foxglove/PoseInFrame.fbs b/schemas/flatbuffer/foxglove/PoseInFrame.fbs new file mode 100644 index 0000000..85fda60 --- /dev/null +++ b/schemas/flatbuffer/foxglove/PoseInFrame.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + + +/// A timestamped pose for an object or reference frame in 3D space +table PoseInFrame { + /// Timestamp of pose + timestamp:Time; + + /// Frame of reference for pose position and orientation + frame_id:string; + + /// Pose in 3D space + pose:foxglove.Pose; +} + +root_type PoseInFrame; diff --git a/schemas/flatbuffer/foxglove/PosesInFrame.fbs b/schemas/flatbuffer/foxglove/PosesInFrame.fbs new file mode 100644 index 0000000..352bde1 --- /dev/null +++ b/schemas/flatbuffer/foxglove/PosesInFrame.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + + +/// An array of timestamped poses for an object or reference frame in 3D space +table PosesInFrame { + /// Timestamp of pose + timestamp:Time; + + /// Frame of reference for pose position and orientation + frame_id:string; + + /// Poses in 3D space + poses:[foxglove.Pose]; +} + +root_type PosesInFrame; diff --git a/schemas/flatbuffer/foxglove/Quaternion.fbs b/schemas/flatbuffer/foxglove/Quaternion.fbs new file mode 100644 index 0000000..91dbbb3 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Quaternion.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A [quaternion](https://eater.net/quaternions) representing a rotation in 3D space +table Quaternion { + /// x value + x:double; + + /// y value + y:double; + + /// z value + z:double; + + /// w value + w:double; +} + +root_type Quaternion; diff --git a/schemas/flatbuffer/foxglove/RawImage.fbs b/schemas/flatbuffer/foxglove/RawImage.fbs new file mode 100644 index 0000000..d20b01c --- /dev/null +++ b/schemas/flatbuffer/foxglove/RawImage.fbs @@ -0,0 +1,32 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + + +/// A raw image +table RawImage { + /// Timestamp of image + timestamp:Time; + + /// Frame of reference for the image. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Image width + width:uint; + + /// Image height + height:uint; + + /// Encoding of the raw image data + encoding:string; + + /// Byte length of a single row + step:uint; + + /// Raw image data + data:[byte]; +} + +root_type RawImage; diff --git a/schemas/flatbuffer/foxglove/SceneEntity.fbs b/schemas/flatbuffer/foxglove/SceneEntity.fbs new file mode 100644 index 0000000..a08a05b --- /dev/null +++ b/schemas/flatbuffer/foxglove/SceneEntity.fbs @@ -0,0 +1,63 @@ +// Generated by https://github.com/foxglove/schemas + +include "ArrowPrimitive.fbs"; +include "CubePrimitive.fbs"; +include "CylinderPrimitive.fbs"; +include "Duration.fbs"; +include "KeyValuePair.fbs"; +include "LinePrimitive.fbs"; +include "ModelPrimitive.fbs"; +include "SpherePrimitive.fbs"; +include "TextPrimitive.fbs"; +include "Time.fbs"; +include "TriangleListPrimitive.fbs"; + +namespace foxglove; + + +/// A visual element in a 3D scene. An entity may be composed of multiple primitives which all share the same frame of reference. +table SceneEntity { + /// Timestamp of the entity + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Identifier for the entity. A entity will replace any prior entity on the same topic with the same `id`. + id:string; + + /// Length of time (relative to `timestamp`) after which the entity should be automatically removed. Zero value indicates the entity should remain visible until it is replaced or deleted. + lifetime:Duration; + + /// Whether the entity should keep its location in the fixed frame (false) or follow the frame specified in `frame_id` as it moves relative to the fixed frame (true) + frame_locked:bool; + + /// Additional user-provided metadata associated with the entity. Keys must be unique. + metadata:[foxglove.KeyValuePair]; + + /// Arrow primitives + arrows:[foxglove.ArrowPrimitive]; + + /// Cube primitives + cubes:[foxglove.CubePrimitive]; + + /// Sphere primitives + spheres:[foxglove.SpherePrimitive]; + + /// Cylinder primitives + cylinders:[foxglove.CylinderPrimitive]; + + /// Line primitives + lines:[foxglove.LinePrimitive]; + + /// Triangle list primitives + triangles:[foxglove.TriangleListPrimitive]; + + /// Text primitives + texts:[foxglove.TextPrimitive]; + + /// Model primitives + models:[foxglove.ModelPrimitive]; +} + +root_type SceneEntity; diff --git a/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs b/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs new file mode 100644 index 0000000..5ae6734 --- /dev/null +++ b/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs @@ -0,0 +1,28 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// An enumeration indicating which entities should match a SceneEntityDeletion command +enum SceneEntityDeletionType : byte { + /// Delete the existing entity on the same topic that has the provided `id` + MATCHING_ID = 0, + + /// Delete all existing entities on the same topic + ALL = 1, +} + +/// Command to remove previously published entities +table SceneEntityDeletion { + /// Timestamp of the deletion. Only matching entities earlier than this timestamp will be deleted. + timestamp:Time; + + /// Type of deletion action to perform + type:SceneEntityDeletionType; + + /// Identifier which must match if `type` is `MATCHING_ID`. + id:string; +} + +root_type SceneEntityDeletion; diff --git a/schemas/flatbuffer/foxglove/SceneUpdate.fbs b/schemas/flatbuffer/foxglove/SceneUpdate.fbs new file mode 100644 index 0000000..d36be2d --- /dev/null +++ b/schemas/flatbuffer/foxglove/SceneUpdate.fbs @@ -0,0 +1,18 @@ +// Generated by https://github.com/foxglove/schemas + +include "SceneEntity.fbs"; +include "SceneEntityDeletion.fbs"; + +namespace foxglove; + + +/// An update to the entities displayed in a 3D scene +table SceneUpdate { + /// Scene entities to delete + deletions:[foxglove.SceneEntityDeletion]; + + /// Scene entities to add or replace + entities:[foxglove.SceneEntity]; +} + +root_type SceneUpdate; diff --git a/schemas/flatbuffer/foxglove/SpherePrimitive.fbs b/schemas/flatbuffer/foxglove/SpherePrimitive.fbs new file mode 100644 index 0000000..7e67f48 --- /dev/null +++ b/schemas/flatbuffer/foxglove/SpherePrimitive.fbs @@ -0,0 +1,22 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + + +/// A primitive representing a sphere or ellipsoid +table SpherePrimitive { + /// Position of the center of the sphere and orientation of the sphere + pose:foxglove.Pose; + + /// Size (diameter) of the sphere along each axis + size:foxglove.Vector3; + + /// Color of the sphere + color:foxglove.Color; +} + +root_type SpherePrimitive; diff --git a/schemas/flatbuffer/foxglove/TextPrimitive.fbs b/schemas/flatbuffer/foxglove/TextPrimitive.fbs new file mode 100644 index 0000000..0ef5aaa --- /dev/null +++ b/schemas/flatbuffer/foxglove/TextPrimitive.fbs @@ -0,0 +1,30 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; + +namespace foxglove; + + +/// A primitive representing a text label +table TextPrimitive { + /// Position of the center of the text box and orientation of the text. Identity orientation means the text is oriented in the xy-plane and flows from -x to +x. + pose:foxglove.Pose; + + /// Whether the text should respect `pose.orientation` (false) or always face the camera (true) + billboard:bool; + + /// Font size (height of one line of text) + font_size:double; + + /// Indicates whether `font_size` is a fixed size in screen pixels (true), or specified in world coordinates and scales with distance from the camera (false) + scale_invariant:bool; + + /// Color of the text + color:foxglove.Color; + + /// Text + text:string; +} + +root_type TextPrimitive; diff --git a/schemas/flatbuffer/foxglove/Time.fbs b/schemas/flatbuffer/foxglove/Time.fbs new file mode 100644 index 0000000..011cf03 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Time.fbs @@ -0,0 +1,4 @@ +struct Time { + sec:uint; + nsec:uint; +} diff --git a/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs b/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs new file mode 100644 index 0000000..84cd7fc --- /dev/null +++ b/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs @@ -0,0 +1,30 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point3.fbs"; +include "Pose.fbs"; + +namespace foxglove; + + +/// A primitive representing a set of triangles or a surface tiled by triangles +table TriangleListPrimitive { + /// Origin of triangles relative to reference frame + pose:foxglove.Pose; + + /// Vertices to use for triangles, interpreted as a list of triples (0-1-2, 3-4-5, ...) + points:[foxglove.Point3]; + + /// Solid color to use for the whole shape. One of `color` or `colors` must be provided. + color:foxglove.Color; + + /// Per-vertex colors (if specified, must have the same length as `points`). One of `color` or `colors` must be provided. + colors:[foxglove.Color]; + + /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. + /// + /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). + indices:[uint]; +} + +root_type TriangleListPrimitive; diff --git a/schemas/flatbuffer/foxglove/Vector2.fbs b/schemas/flatbuffer/foxglove/Vector2.fbs new file mode 100644 index 0000000..5b63de5 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Vector2.fbs @@ -0,0 +1,15 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A vector in 2D space that represents a direction only +table Vector2 { + /// x coordinate length + x:double; + + /// y coordinate length + y:double; +} + +root_type Vector2; diff --git a/schemas/flatbuffer/foxglove/Vector3.fbs b/schemas/flatbuffer/foxglove/Vector3.fbs new file mode 100644 index 0000000..2ea9530 --- /dev/null +++ b/schemas/flatbuffer/foxglove/Vector3.fbs @@ -0,0 +1,18 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + + +/// A vector in 3D space that represents a direction only +table Vector3 { + /// x coordinate length + x:double; + + /// y coordinate length + y:double; + + /// z coordinate length + z:double; +} + +root_type Vector3; diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index 3e1d9f7..6344d82 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -5,6 +5,7 @@ import rimraf from "rimraf"; import { promisify } from "util"; import { generateRosMsg, generateRosMsgDefinition } from "../internal"; +import { DURATION_FB, generateFlatbuffer, TIME_FB } from "../internal/generateFlatbuffer"; import { generateJsonSchema } from "../internal/generateJsonSchema"; import { generateMarkdown } from "../internal/generateMarkdown"; import { generateProto } from "../internal/generateProto"; @@ -72,6 +73,21 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } } }); + await logProgress("Generating FlatBuffer definitions", async () => { + await fs.mkdir(path.join(outDir, "flatbuffer", "foxglove"), { recursive: true }); + await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Time.fbs"), TIME_FB); + await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Duration.fbs"), DURATION_FB); + for (const schema of Object.values(foxgloveMessageSchemas)) { + const enums = Object.values(foxgloveEnumSchemas).filter( + (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + ); + await fs.writeFile( + path.join(outDir, "flatbuffer", "foxglove", `${schema.name}.fbs`), + generateFlatbuffer(schema, enums), + ); + } + }); + await logProgress("Generating TypeScript definitions", async () => { await fs.mkdir(path.join(outDir, "typescript"), { recursive: true }); await fs.writeFile(path.join(outDir, "typescript", "Time.ts"), TIME_TS); From 5f2e676dd348f64fe3b3d7ecd1b47ebe1887098f Mon Sep 17 00:00:00 2001 From: snosenzo Date: Tue, 8 Nov 2022 23:36:08 +0100 Subject: [PATCH 02/15] - enums as separate files? --- internal/generateFlatbuffer.ts | 114 +++++++++--------- .../flatbuffer/foxglove/ArrowPrimitive.fbs | 1 - .../flatbuffer/foxglove/CameraCalibration.fbs | 1 - .../flatbuffer/foxglove/CircleAnnotation.fbs | 1 - schemas/flatbuffer/foxglove/Color.fbs | 1 - .../flatbuffer/foxglove/CompressedImage.fbs | 1 - schemas/flatbuffer/foxglove/CubePrimitive.fbs | 1 - .../flatbuffer/foxglove/CylinderPrimitive.fbs | 1 - .../flatbuffer/foxglove/FrameTransform.fbs | 1 - schemas/flatbuffer/foxglove/GeoJSON.fbs | 1 - schemas/flatbuffer/foxglove/Grid.fbs | 1 - .../flatbuffer/foxglove/ImageAnnotations.fbs | 1 - schemas/flatbuffer/foxglove/KeyValuePair.fbs | 1 - schemas/flatbuffer/foxglove/LaserScan.fbs | 1 - schemas/flatbuffer/foxglove/LinePrimitive.fbs | 13 +- schemas/flatbuffer/foxglove/LineType.fbs | 16 +++ schemas/flatbuffer/foxglove/LocationFix.fbs | 13 +- schemas/flatbuffer/foxglove/Log.fbs | 16 +-- schemas/flatbuffer/foxglove/LogLevel.fbs | 19 +++ .../flatbuffer/foxglove/ModelPrimitive.fbs | 1 - schemas/flatbuffer/foxglove/NumericType.fbs | 25 ++++ .../foxglove/PackedElementField.fbs | 23 +--- schemas/flatbuffer/foxglove/Point2.fbs | 1 - schemas/flatbuffer/foxglove/Point3.fbs | 1 - schemas/flatbuffer/foxglove/PointCloud.fbs | 1 - .../flatbuffer/foxglove/PointsAnnotation.fbs | 14 +-- .../foxglove/PointsAnnotationType.fbs | 17 +++ schemas/flatbuffer/foxglove/Pose.fbs | 1 - schemas/flatbuffer/foxglove/PoseInFrame.fbs | 1 - schemas/flatbuffer/foxglove/PosesInFrame.fbs | 1 - .../foxglove/PositionCovarianceType.fbs | 15 +++ schemas/flatbuffer/foxglove/Quaternion.fbs | 1 - schemas/flatbuffer/foxglove/RawImage.fbs | 1 - schemas/flatbuffer/foxglove/SceneEntity.fbs | 1 - .../foxglove/SceneEntityDeletion.fbs | 10 +- .../foxglove/SceneEntityDeletionType.fbs | 13 ++ schemas/flatbuffer/foxglove/SceneUpdate.fbs | 1 - .../flatbuffer/foxglove/SpherePrimitive.fbs | 1 - schemas/flatbuffer/foxglove/TextPrimitive.fbs | 1 - .../foxglove/TriangleListPrimitive.fbs | 1 - schemas/flatbuffer/foxglove/Vector2.fbs | 1 - schemas/flatbuffer/foxglove/Vector3.fbs | 1 - scripts/updateGeneratedFiles.ts | 9 +- 43 files changed, 177 insertions(+), 169 deletions(-) create mode 100644 schemas/flatbuffer/foxglove/LineType.fbs create mode 100644 schemas/flatbuffer/foxglove/LogLevel.fbs create mode 100644 schemas/flatbuffer/foxglove/NumericType.fbs create mode 100644 schemas/flatbuffer/foxglove/PointsAnnotationType.fbs create mode 100644 schemas/flatbuffer/foxglove/PositionCovarianceType.fbs create mode 100644 schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts index 1be963f..319f559 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffer.ts @@ -1,4 +1,4 @@ -import { FoxgloveEnumSchema, FoxgloveMessageSchema, FoxglovePrimitive } from "./types"; +import { FoxglovePrimitive, FoxgloveSchema } from "./types"; export const TIME_FB = `struct Time { sec:uint; @@ -27,68 +27,70 @@ function primitiveToFlatbuffer(type: Exclude { - if (description != undefined) { - return `/// ${description}\n ${name} = ${value},`; - } else { - return `${name} = ${value},`; - } - }); - enumDefinitions.push( +export function generateFlatbuffer(schema: FoxgloveSchema): string { + let definition; + const imports = new Set(); + switch (schema.type) { + case "enum": { + const fields = schema.values.map(({ name, value, description }) => { + if (description != undefined) { + return `/// ${description}\n ${name} = ${value},`; + } else { + return `${name} = ${value},`; + } + }); + // `///` comments required to show up in compiled flatbuffer schemas - `/// ${enumSchema.description}\nenum ${enumSchema.name} : byte {\n ${fields.join( + definition = `/// ${schema.description}\nenum ${schema.name} : byte {\n ${fields.join( "\n\n ", - )}\n}\n`, - ); - } + )}\n}\n`; + break; + } + case "message": { + const fields = schema.fields.map((field) => { + const isArray = field.array != undefined; - const imports = new Set(); - const fields = schema.fields.map((field) => { - const isArray = field.array != undefined; + let type; + switch (field.type.type) { + case "enum": + type = field.type.enum.name; + imports.add(field.type.enum.name); + break; + case "nested": + type = `foxglove.${field.type.schema.name}`; + imports.add(field.type.schema.name); + break; + case "primitive": + if (field.type.name === "time") { + type = "Time"; + imports.add(`Time`); + } else if (field.type.name === "duration") { + type = "Duration"; + imports.add(`Duration`); + } else { + type = primitiveToFlatbuffer(field.type.name); + } + break; + } + let lengthComment; - let type; - switch (field.type.type) { - case "enum": - type = field.type.enum.name; - break; - case "nested": - type = `foxglove.${field.type.schema.name}`; - imports.add(`${field.type.schema.name}`); - break; - case "primitive": - if (field.type.name === "time") { - type = "Time"; - imports.add(`Time`); - } else if (field.type.name === "duration") { - type = "Duration"; - imports.add(`Duration`); - } else { - type = primitiveToFlatbuffer(field.type.name); + if (typeof field.array === "number") { + // can't have inline comments + lengthComment = ` /// length ${field.array}\n`; } - break; - } - let lengthComment; + return `${field.description + .trim() + .split("\n") + .map((line) => ` /// ${line}\n`) + .join("")}${lengthComment ?? ""} ${field.name}:${isArray ? `[${type}]` : type};`; + }); - if (typeof field.array === "number") { - // can't have inline comments - lengthComment = ` /// length ${field.array}\n`; + definition = `/// ${schema.description}\ntable ${schema.name} {\n${fields.join( + "\n\n", + )}\n}\n\nroot_type ${schema.name};`; + break; } - return `${field.description - .trim() - .split("\n") - .map((line) => ` /// ${line}\n`) - .join("")}${lengthComment ?? ""} ${field.name}:${isArray ? `[${type}]` : type};`; - }); - - const definition = `${enumDefinitions.join("\n\n")}\n/// ${schema.description}\ntable ${ - schema.name - } {\n${fields.join("\n\n")}\n}\n\nroot_type ${schema.name};`; + } const outputSections = [ `// Generated by https://github.com/foxglove/schemas`, diff --git a/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs b/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs index f7393d0..7a7f104 100644 --- a/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs +++ b/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs @@ -5,7 +5,6 @@ include "Pose.fbs"; namespace foxglove; - /// A primitive representing an arrow table ArrowPrimitive { /// Position of the arrow's tail and orientation of the arrow. Identity orientation means the arrow points in the +x direction. diff --git a/schemas/flatbuffer/foxglove/CameraCalibration.fbs b/schemas/flatbuffer/foxglove/CameraCalibration.fbs index 035477c..041eb1e 100644 --- a/schemas/flatbuffer/foxglove/CameraCalibration.fbs +++ b/schemas/flatbuffer/foxglove/CameraCalibration.fbs @@ -4,7 +4,6 @@ include "Time.fbs"; namespace foxglove; - /// Camera calibration parameters table CameraCalibration { /// Timestamp of calibration data diff --git a/schemas/flatbuffer/foxglove/CircleAnnotation.fbs b/schemas/flatbuffer/foxglove/CircleAnnotation.fbs index b5894ae..de2a6cb 100644 --- a/schemas/flatbuffer/foxglove/CircleAnnotation.fbs +++ b/schemas/flatbuffer/foxglove/CircleAnnotation.fbs @@ -6,7 +6,6 @@ include "Time.fbs"; namespace foxglove; - /// A circle annotation on a 2D image table CircleAnnotation { /// Timestamp of circle diff --git a/schemas/flatbuffer/foxglove/Color.fbs b/schemas/flatbuffer/foxglove/Color.fbs index 1eef339..f119c3e 100644 --- a/schemas/flatbuffer/foxglove/Color.fbs +++ b/schemas/flatbuffer/foxglove/Color.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A color in RGBA format table Color { /// Red value between 0 and 1 diff --git a/schemas/flatbuffer/foxglove/CompressedImage.fbs b/schemas/flatbuffer/foxglove/CompressedImage.fbs index f9f0c7b..06b8837 100644 --- a/schemas/flatbuffer/foxglove/CompressedImage.fbs +++ b/schemas/flatbuffer/foxglove/CompressedImage.fbs @@ -4,7 +4,6 @@ include "Time.fbs"; namespace foxglove; - /// A compressed image table CompressedImage { /// Timestamp of image diff --git a/schemas/flatbuffer/foxglove/CubePrimitive.fbs b/schemas/flatbuffer/foxglove/CubePrimitive.fbs index 33212e8..0114872 100644 --- a/schemas/flatbuffer/foxglove/CubePrimitive.fbs +++ b/schemas/flatbuffer/foxglove/CubePrimitive.fbs @@ -6,7 +6,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A primitive representing a cube or rectangular prism table CubePrimitive { /// Position of the center of the cube and orientation of the cube diff --git a/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs b/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs index 4ae5c49..0b5391a 100644 --- a/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs +++ b/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs @@ -6,7 +6,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A primitive representing a cylinder, elliptic cylinder, or truncated cone table CylinderPrimitive { /// Position of the center of the cylinder and orientation of the cylinder. The flat face(s) are perpendicular to the z-axis. diff --git a/schemas/flatbuffer/foxglove/FrameTransform.fbs b/schemas/flatbuffer/foxglove/FrameTransform.fbs index f7a6a1a..129a85a 100644 --- a/schemas/flatbuffer/foxglove/FrameTransform.fbs +++ b/schemas/flatbuffer/foxglove/FrameTransform.fbs @@ -6,7 +6,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A transform between two reference frames in 3D space table FrameTransform { /// Timestamp of transform diff --git a/schemas/flatbuffer/foxglove/GeoJSON.fbs b/schemas/flatbuffer/foxglove/GeoJSON.fbs index c7110b6..c571c48 100644 --- a/schemas/flatbuffer/foxglove/GeoJSON.fbs +++ b/schemas/flatbuffer/foxglove/GeoJSON.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// GeoJSON data for annotating maps table GeoJSON { /// GeoJSON data encoded as a UTF-8 string diff --git a/schemas/flatbuffer/foxglove/Grid.fbs b/schemas/flatbuffer/foxglove/Grid.fbs index dff9b04..c993511 100644 --- a/schemas/flatbuffer/foxglove/Grid.fbs +++ b/schemas/flatbuffer/foxglove/Grid.fbs @@ -7,7 +7,6 @@ include "Vector2.fbs"; namespace foxglove; - /// A 2D grid of data table Grid { /// Timestamp of grid diff --git a/schemas/flatbuffer/foxglove/ImageAnnotations.fbs b/schemas/flatbuffer/foxglove/ImageAnnotations.fbs index fac3173..8c91711 100644 --- a/schemas/flatbuffer/foxglove/ImageAnnotations.fbs +++ b/schemas/flatbuffer/foxglove/ImageAnnotations.fbs @@ -5,7 +5,6 @@ include "PointsAnnotation.fbs"; namespace foxglove; - /// Array of annotations for a 2D image table ImageAnnotations { /// Circle annotations diff --git a/schemas/flatbuffer/foxglove/KeyValuePair.fbs b/schemas/flatbuffer/foxglove/KeyValuePair.fbs index 5529310..3c24830 100644 --- a/schemas/flatbuffer/foxglove/KeyValuePair.fbs +++ b/schemas/flatbuffer/foxglove/KeyValuePair.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A key with its associated value table KeyValuePair { /// Key diff --git a/schemas/flatbuffer/foxglove/LaserScan.fbs b/schemas/flatbuffer/foxglove/LaserScan.fbs index bdb16b5..2a7e651 100644 --- a/schemas/flatbuffer/foxglove/LaserScan.fbs +++ b/schemas/flatbuffer/foxglove/LaserScan.fbs @@ -5,7 +5,6 @@ include "Time.fbs"; namespace foxglove; - /// A single scan from a planar laser range-finder table LaserScan { /// Timestamp of scan diff --git a/schemas/flatbuffer/foxglove/LinePrimitive.fbs b/schemas/flatbuffer/foxglove/LinePrimitive.fbs index 5a33c55..7547b30 100644 --- a/schemas/flatbuffer/foxglove/LinePrimitive.fbs +++ b/schemas/flatbuffer/foxglove/LinePrimitive.fbs @@ -1,23 +1,12 @@ // Generated by https://github.com/foxglove/schemas include "Color.fbs"; +include "LineType.fbs"; include "Point3.fbs"; include "Pose.fbs"; namespace foxglove; -/// An enumeration indicating how input points should be interpreted to create lines -enum LineType : byte { - /// 0-1, 1-2, ..., (n-1)-n - LINE_STRIP = 0, - - /// 0-1, 1-2, ..., (n-1)-n, n-0 - LINE_LOOP = 1, - - /// 0-1, 2-3, 4-5, ... - LINE_LIST = 2, -} - /// A primitive representing a series of points connected by lines table LinePrimitive { /// Drawing primitive to use for lines diff --git a/schemas/flatbuffer/foxglove/LineType.fbs b/schemas/flatbuffer/foxglove/LineType.fbs new file mode 100644 index 0000000..76f73e7 --- /dev/null +++ b/schemas/flatbuffer/foxglove/LineType.fbs @@ -0,0 +1,16 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// An enumeration indicating how input points should be interpreted to create lines +enum LineType : byte { + /// 0-1, 1-2, ..., (n-1)-n + LINE_STRIP = 0, + + /// 0-1, 1-2, ..., (n-1)-n, n-0 + LINE_LOOP = 1, + + /// 0-1, 2-3, 4-5, ... + LINE_LIST = 2, +} + diff --git a/schemas/flatbuffer/foxglove/LocationFix.fbs b/schemas/flatbuffer/foxglove/LocationFix.fbs index 13fef32..7b0cae2 100644 --- a/schemas/flatbuffer/foxglove/LocationFix.fbs +++ b/schemas/flatbuffer/foxglove/LocationFix.fbs @@ -1,17 +1,8 @@ // Generated by https://github.com/foxglove/schemas -namespace foxglove; - -/// Type of position covariance -enum PositionCovarianceType : byte { - UNKNOWN = 0, - - APPROXIMATED = 1, +include "PositionCovarianceType.fbs"; - DIAGONAL_KNOWN = 2, - - KNOWN = 3, -} +namespace foxglove; /// A navigation satellite fix for any Global Navigation Satellite System table LocationFix { diff --git a/schemas/flatbuffer/foxglove/Log.fbs b/schemas/flatbuffer/foxglove/Log.fbs index 7b629fb..ff16520 100644 --- a/schemas/flatbuffer/foxglove/Log.fbs +++ b/schemas/flatbuffer/foxglove/Log.fbs @@ -1,24 +1,10 @@ // Generated by https://github.com/foxglove/schemas +include "LogLevel.fbs"; include "Time.fbs"; namespace foxglove; -/// Log level -enum LogLevel : byte { - UNKNOWN = 0, - - DEBUG = 1, - - INFO = 2, - - WARNING = 3, - - ERROR = 4, - - FATAL = 5, -} - /// A log message table Log { /// Timestamp of log message diff --git a/schemas/flatbuffer/foxglove/LogLevel.fbs b/schemas/flatbuffer/foxglove/LogLevel.fbs new file mode 100644 index 0000000..ea14644 --- /dev/null +++ b/schemas/flatbuffer/foxglove/LogLevel.fbs @@ -0,0 +1,19 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Log level +enum LogLevel : byte { + UNKNOWN = 0, + + DEBUG = 1, + + INFO = 2, + + WARNING = 3, + + ERROR = 4, + + FATAL = 5, +} + diff --git a/schemas/flatbuffer/foxglove/ModelPrimitive.fbs b/schemas/flatbuffer/foxglove/ModelPrimitive.fbs index 412002b..1b8558a 100644 --- a/schemas/flatbuffer/foxglove/ModelPrimitive.fbs +++ b/schemas/flatbuffer/foxglove/ModelPrimitive.fbs @@ -6,7 +6,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A primitive representing a 3D model file loaded from an external URL or embedded data table ModelPrimitive { /// Origin of model relative to reference frame diff --git a/schemas/flatbuffer/foxglove/NumericType.fbs b/schemas/flatbuffer/foxglove/NumericType.fbs new file mode 100644 index 0000000..1943af4 --- /dev/null +++ b/schemas/flatbuffer/foxglove/NumericType.fbs @@ -0,0 +1,25 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Numeric type +enum NumericType : byte { + UNKNOWN = 0, + + UINT8 = 1, + + INT8 = 2, + + UINT16 = 3, + + INT16 = 4, + + UINT32 = 5, + + INT32 = 6, + + FLOAT32 = 7, + + FLOAT64 = 8, +} + diff --git a/schemas/flatbuffer/foxglove/PackedElementField.fbs b/schemas/flatbuffer/foxglove/PackedElementField.fbs index 9808418..4bb65b3 100644 --- a/schemas/flatbuffer/foxglove/PackedElementField.fbs +++ b/schemas/flatbuffer/foxglove/PackedElementField.fbs @@ -1,27 +1,8 @@ // Generated by https://github.com/foxglove/schemas -namespace foxglove; - -/// Numeric type -enum NumericType : byte { - UNKNOWN = 0, - - UINT8 = 1, - - INT8 = 2, - - UINT16 = 3, - - INT16 = 4, +include "NumericType.fbs"; - UINT32 = 5, - - INT32 = 6, - - FLOAT32 = 7, - - FLOAT64 = 8, -} +namespace foxglove; /// A field present within each element in a byte array of packed elements. table PackedElementField { diff --git a/schemas/flatbuffer/foxglove/Point2.fbs b/schemas/flatbuffer/foxglove/Point2.fbs index db3b988..17dd980 100644 --- a/schemas/flatbuffer/foxglove/Point2.fbs +++ b/schemas/flatbuffer/foxglove/Point2.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A point representing a position in 2D space table Point2 { /// x coordinate position diff --git a/schemas/flatbuffer/foxglove/Point3.fbs b/schemas/flatbuffer/foxglove/Point3.fbs index 5f71ee5..c497bd1 100644 --- a/schemas/flatbuffer/foxglove/Point3.fbs +++ b/schemas/flatbuffer/foxglove/Point3.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A point representing a position in 3D space table Point3 { /// x coordinate position diff --git a/schemas/flatbuffer/foxglove/PointCloud.fbs b/schemas/flatbuffer/foxglove/PointCloud.fbs index 4146c7b..7dd9c0a 100644 --- a/schemas/flatbuffer/foxglove/PointCloud.fbs +++ b/schemas/flatbuffer/foxglove/PointCloud.fbs @@ -6,7 +6,6 @@ include "Time.fbs"; namespace foxglove; - /// A collection of N-dimensional points, which may contain additional fields with information like normals, intensity, etc. table PointCloud { /// Timestamp of point cloud diff --git a/schemas/flatbuffer/foxglove/PointsAnnotation.fbs b/schemas/flatbuffer/foxglove/PointsAnnotation.fbs index e2889b3..ca0fbf8 100644 --- a/schemas/flatbuffer/foxglove/PointsAnnotation.fbs +++ b/schemas/flatbuffer/foxglove/PointsAnnotation.fbs @@ -2,23 +2,11 @@ include "Color.fbs"; include "Point2.fbs"; +include "PointsAnnotationType.fbs"; include "Time.fbs"; namespace foxglove; -/// Type of points annotation -enum PointsAnnotationType : byte { - UNKNOWN = 0, - - POINTS = 1, - - LINE_LOOP = 2, - - LINE_STRIP = 3, - - LINE_LIST = 4, -} - /// An array of points on a 2D image table PointsAnnotation { /// Timestamp of annotation diff --git a/schemas/flatbuffer/foxglove/PointsAnnotationType.fbs b/schemas/flatbuffer/foxglove/PointsAnnotationType.fbs new file mode 100644 index 0000000..9d73df7 --- /dev/null +++ b/schemas/flatbuffer/foxglove/PointsAnnotationType.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Type of points annotation +enum PointsAnnotationType : byte { + UNKNOWN = 0, + + POINTS = 1, + + LINE_LOOP = 2, + + LINE_STRIP = 3, + + LINE_LIST = 4, +} + diff --git a/schemas/flatbuffer/foxglove/Pose.fbs b/schemas/flatbuffer/foxglove/Pose.fbs index 6034755..688a80c 100644 --- a/schemas/flatbuffer/foxglove/Pose.fbs +++ b/schemas/flatbuffer/foxglove/Pose.fbs @@ -5,7 +5,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A position and orientation for an object or reference frame in 3D space table Pose { /// Point denoting position in 3D space diff --git a/schemas/flatbuffer/foxglove/PoseInFrame.fbs b/schemas/flatbuffer/foxglove/PoseInFrame.fbs index 85fda60..0642564 100644 --- a/schemas/flatbuffer/foxglove/PoseInFrame.fbs +++ b/schemas/flatbuffer/foxglove/PoseInFrame.fbs @@ -5,7 +5,6 @@ include "Time.fbs"; namespace foxglove; - /// A timestamped pose for an object or reference frame in 3D space table PoseInFrame { /// Timestamp of pose diff --git a/schemas/flatbuffer/foxglove/PosesInFrame.fbs b/schemas/flatbuffer/foxglove/PosesInFrame.fbs index 352bde1..b98e64a 100644 --- a/schemas/flatbuffer/foxglove/PosesInFrame.fbs +++ b/schemas/flatbuffer/foxglove/PosesInFrame.fbs @@ -5,7 +5,6 @@ include "Time.fbs"; namespace foxglove; - /// An array of timestamped poses for an object or reference frame in 3D space table PosesInFrame { /// Timestamp of pose diff --git a/schemas/flatbuffer/foxglove/PositionCovarianceType.fbs b/schemas/flatbuffer/foxglove/PositionCovarianceType.fbs new file mode 100644 index 0000000..ba6bf4f --- /dev/null +++ b/schemas/flatbuffer/foxglove/PositionCovarianceType.fbs @@ -0,0 +1,15 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Type of position covariance +enum PositionCovarianceType : byte { + UNKNOWN = 0, + + APPROXIMATED = 1, + + DIAGONAL_KNOWN = 2, + + KNOWN = 3, +} + diff --git a/schemas/flatbuffer/foxglove/Quaternion.fbs b/schemas/flatbuffer/foxglove/Quaternion.fbs index 91dbbb3..7179c13 100644 --- a/schemas/flatbuffer/foxglove/Quaternion.fbs +++ b/schemas/flatbuffer/foxglove/Quaternion.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A [quaternion](https://eater.net/quaternions) representing a rotation in 3D space table Quaternion { /// x value diff --git a/schemas/flatbuffer/foxglove/RawImage.fbs b/schemas/flatbuffer/foxglove/RawImage.fbs index d20b01c..b76241e 100644 --- a/schemas/flatbuffer/foxglove/RawImage.fbs +++ b/schemas/flatbuffer/foxglove/RawImage.fbs @@ -4,7 +4,6 @@ include "Time.fbs"; namespace foxglove; - /// A raw image table RawImage { /// Timestamp of image diff --git a/schemas/flatbuffer/foxglove/SceneEntity.fbs b/schemas/flatbuffer/foxglove/SceneEntity.fbs index a08a05b..d2f1cfc 100644 --- a/schemas/flatbuffer/foxglove/SceneEntity.fbs +++ b/schemas/flatbuffer/foxglove/SceneEntity.fbs @@ -14,7 +14,6 @@ include "TriangleListPrimitive.fbs"; namespace foxglove; - /// A visual element in a 3D scene. An entity may be composed of multiple primitives which all share the same frame of reference. table SceneEntity { /// Timestamp of the entity diff --git a/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs b/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs index 5ae6734..e452126 100644 --- a/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs +++ b/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs @@ -1,18 +1,10 @@ // Generated by https://github.com/foxglove/schemas +include "SceneEntityDeletionType.fbs"; include "Time.fbs"; namespace foxglove; -/// An enumeration indicating which entities should match a SceneEntityDeletion command -enum SceneEntityDeletionType : byte { - /// Delete the existing entity on the same topic that has the provided `id` - MATCHING_ID = 0, - - /// Delete all existing entities on the same topic - ALL = 1, -} - /// Command to remove previously published entities table SceneEntityDeletion { /// Timestamp of the deletion. Only matching entities earlier than this timestamp will be deleted. diff --git a/schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs b/schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs new file mode 100644 index 0000000..2b6d3c1 --- /dev/null +++ b/schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs @@ -0,0 +1,13 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// An enumeration indicating which entities should match a SceneEntityDeletion command +enum SceneEntityDeletionType : byte { + /// Delete the existing entity on the same topic that has the provided `id` + MATCHING_ID = 0, + + /// Delete all existing entities on the same topic + ALL = 1, +} + diff --git a/schemas/flatbuffer/foxglove/SceneUpdate.fbs b/schemas/flatbuffer/foxglove/SceneUpdate.fbs index d36be2d..8d7dbe6 100644 --- a/schemas/flatbuffer/foxglove/SceneUpdate.fbs +++ b/schemas/flatbuffer/foxglove/SceneUpdate.fbs @@ -5,7 +5,6 @@ include "SceneEntityDeletion.fbs"; namespace foxglove; - /// An update to the entities displayed in a 3D scene table SceneUpdate { /// Scene entities to delete diff --git a/schemas/flatbuffer/foxglove/SpherePrimitive.fbs b/schemas/flatbuffer/foxglove/SpherePrimitive.fbs index 7e67f48..5f51499 100644 --- a/schemas/flatbuffer/foxglove/SpherePrimitive.fbs +++ b/schemas/flatbuffer/foxglove/SpherePrimitive.fbs @@ -6,7 +6,6 @@ include "Vector3.fbs"; namespace foxglove; - /// A primitive representing a sphere or ellipsoid table SpherePrimitive { /// Position of the center of the sphere and orientation of the sphere diff --git a/schemas/flatbuffer/foxglove/TextPrimitive.fbs b/schemas/flatbuffer/foxglove/TextPrimitive.fbs index 0ef5aaa..742affc 100644 --- a/schemas/flatbuffer/foxglove/TextPrimitive.fbs +++ b/schemas/flatbuffer/foxglove/TextPrimitive.fbs @@ -5,7 +5,6 @@ include "Pose.fbs"; namespace foxglove; - /// A primitive representing a text label table TextPrimitive { /// Position of the center of the text box and orientation of the text. Identity orientation means the text is oriented in the xy-plane and flows from -x to +x. diff --git a/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs b/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs index 84cd7fc..c3d319f 100644 --- a/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs +++ b/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs @@ -6,7 +6,6 @@ include "Pose.fbs"; namespace foxglove; - /// A primitive representing a set of triangles or a surface tiled by triangles table TriangleListPrimitive { /// Origin of triangles relative to reference frame diff --git a/schemas/flatbuffer/foxglove/Vector2.fbs b/schemas/flatbuffer/foxglove/Vector2.fbs index 5b63de5..ea12c59 100644 --- a/schemas/flatbuffer/foxglove/Vector2.fbs +++ b/schemas/flatbuffer/foxglove/Vector2.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A vector in 2D space that represents a direction only table Vector2 { /// x coordinate length diff --git a/schemas/flatbuffer/foxglove/Vector3.fbs b/schemas/flatbuffer/foxglove/Vector3.fbs index 2ea9530..3c7b156 100644 --- a/schemas/flatbuffer/foxglove/Vector3.fbs +++ b/schemas/flatbuffer/foxglove/Vector3.fbs @@ -2,7 +2,6 @@ namespace foxglove; - /// A vector in 3D space that represents a direction only table Vector3 { /// x coordinate length diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index 6344d82..fb03c96 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -78,12 +78,15 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Time.fbs"), TIME_FB); await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Duration.fbs"), DURATION_FB); for (const schema of Object.values(foxgloveMessageSchemas)) { - const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + await fs.writeFile( + path.join(outDir, "flatbuffer", "foxglove", `${schema.name}.fbs`), + generateFlatbuffer(schema), ); + } + for (const schema of Object.values(foxgloveEnumSchemas)) { await fs.writeFile( path.join(outDir, "flatbuffer", "foxglove", `${schema.name}.fbs`), - generateFlatbuffer(schema, enums), + generateFlatbuffer(schema), ); } }); From 058467e7f69ea3f92135bbf30bc62d215cfd8ed1 Mon Sep 17 00:00:00 2001 From: snosenzo Date: Wed, 9 Nov 2022 16:27:07 +0100 Subject: [PATCH 03/15] - add tests - final tweaks to generate script to support nested bytes - update time and duration to be more consistent with protobuf types --- internal/generateFlatbuffer.test.ts | 129 ++++++++++++++++++ internal/generateFlatbuffer.ts | 23 +++- .../foxglove/ByteVectorForNesting.fbs | 5 + schemas/flatbuffer/foxglove/Duration.fbs | 4 +- schemas/flatbuffer/foxglove/Time.fbs | 4 +- scripts/updateGeneratedFiles.ts | 11 +- 6 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 internal/generateFlatbuffer.test.ts create mode 100644 schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs diff --git a/internal/generateFlatbuffer.test.ts b/internal/generateFlatbuffer.test.ts new file mode 100644 index 0000000..5e379ae --- /dev/null +++ b/internal/generateFlatbuffer.test.ts @@ -0,0 +1,129 @@ +import { generateFlatbuffer } from "./generateFlatbuffer"; +import { exampleEnum, exampleMessage } from "./testFixtures"; + +describe("generateFlatBuffer", () => { + it("generates Message .fbs files", () => { + expect(generateFlatbuffer(exampleMessage)).toMatchInlineSnapshot(` + "// Generated by https://github.com/foxglove/schemas + + include "ByteVectorForNesting.fbs"; + include "Duration.fbs"; + include "ExampleEnum.fbs"; + include "NestedMessage.fbs"; + include "Time.fbs"; + + namespace foxglove; + + /// An example type + table ExampleMessage { + /// duration field + field_duration:Duration; + + /// time field + field_time:Time; + + /// boolean field + field_boolean:bool; + + /// bytes field + field_bytes:[byte]; + + /// float64 field + field_float64:double; + + /// uint32 field + field_uint32:uint; + + /// string field + field_string:string; + + /// duration array field + field_duration_array:[Duration]; + + /// time array field + field_time_array:[Time]; + + /// boolean array field + field_boolean_array:[bool]; + + /// bytes array field + field_bytes_array:[ByteVectorForNesting]; + + /// float64 array field + field_float64_array:[double]; + + /// uint32 array field + field_uint32_array:[uint]; + + /// string array field + field_string_array:[string]; + + /// duration fixed-length array field + /// length 3 + field_duration_fixed_array:[Duration]; + + /// time fixed-length array field + /// length 3 + field_time_fixed_array:[Time]; + + /// boolean fixed-length array field + /// length 3 + field_boolean_fixed_array:[bool]; + + /// bytes fixed-length array field + /// length 3 + field_bytes_fixed_array:[ByteVectorForNesting]; + + /// float64 fixed-length array field + /// length 3 + field_float64_fixed_array:[double]; + + /// uint32 fixed-length array field + /// length 3 + field_uint32_fixed_array:[uint]; + + /// string fixed-length array field + /// length 3 + field_string_fixed_array:[string]; + + /// An enum field + field_enum:ExampleEnum; + + /// An enum array field + field_enum_array:[ExampleEnum]; + + /// A nested field + field_nested:foxglove.NestedMessage; + + /// A nested array field + /// With + /// a + /// very + /// long + /// description + field_nested_array:[foxglove.NestedMessage]; + } + + root_type ExampleMessage; + " + `); + }); + it("generates Enum .fbs files", () => { + expect(generateFlatbuffer(exampleEnum)).toMatchInlineSnapshot(` + "// Generated by https://github.com/foxglove/schemas + + namespace foxglove; + + /// An example enum + enum ExampleEnum : byte { + /// Value A + A = 1, + + /// Value B + B = 2, + } + + " + `); + }); +}); diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts index 319f559..f64335d 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffer.ts @@ -1,14 +1,23 @@ import { FoxglovePrimitive, FoxgloveSchema } from "./types"; +// Flatbuffer only supports nested vectors via table +export const BYTE_VECTOR_FB = `table ByteVectorForNesting { + data:[byte]; +} + +root_type ByteVectorForNesting; +`; + +// Same as protobuf wellknown types export const TIME_FB = `struct Time { - sec:uint; - nsec:uint; + sec:long; + nsec:int; } `; export const DURATION_FB = `struct Duration { - sec:uint; - nsec:uint; + sec:long; + nsec:int; } `; @@ -67,6 +76,9 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { } else if (field.type.name === "duration") { type = "Duration"; imports.add(`Duration`); + } else if (field.type.name === "bytes" && isArray) { + type = "ByteVectorForNesting"; + imports.add("ByteVectorForNesting"); } else { type = primitiveToFlatbuffer(field.type.name); } @@ -75,13 +87,14 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { let lengthComment; if (typeof field.array === "number") { - // can't have inline comments + // can't specify length of vector outside of struct, all of these are tables lengthComment = ` /// length ${field.array}\n`; } return `${field.description .trim() .split("\n") .map((line) => ` /// ${line}\n`) + // can't have inline comments, so the lengthComment needs to be above .join("")}${lengthComment ?? ""} ${field.name}:${isArray ? `[${type}]` : type};`; }); diff --git a/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs b/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs new file mode 100644 index 0000000..9439bea --- /dev/null +++ b/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs @@ -0,0 +1,5 @@ +table ByteVectorForNesting { + data:[byte]; +} + +root_type ByteVectorForNesting; diff --git a/schemas/flatbuffer/foxglove/Duration.fbs b/schemas/flatbuffer/foxglove/Duration.fbs index 162eda1..6052258 100644 --- a/schemas/flatbuffer/foxglove/Duration.fbs +++ b/schemas/flatbuffer/foxglove/Duration.fbs @@ -1,4 +1,4 @@ struct Duration { - sec:uint; - nsec:uint; + sec:long; + nsec:int; } diff --git a/schemas/flatbuffer/foxglove/Time.fbs b/schemas/flatbuffer/foxglove/Time.fbs index 011cf03..23a9396 100644 --- a/schemas/flatbuffer/foxglove/Time.fbs +++ b/schemas/flatbuffer/foxglove/Time.fbs @@ -1,4 +1,4 @@ struct Time { - sec:uint; - nsec:uint; + sec:long; + nsec:int; } diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index fb03c96..e6d9d31 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -5,7 +5,12 @@ import rimraf from "rimraf"; import { promisify } from "util"; import { generateRosMsg, generateRosMsgDefinition } from "../internal"; -import { DURATION_FB, generateFlatbuffer, TIME_FB } from "../internal/generateFlatbuffer"; +import { + BYTE_VECTOR_FB, + DURATION_FB, + generateFlatbuffer, + TIME_FB, +} from "../internal/generateFlatbuffer"; import { generateJsonSchema } from "../internal/generateJsonSchema"; import { generateMarkdown } from "../internal/generateMarkdown"; import { generateProto } from "../internal/generateProto"; @@ -75,6 +80,10 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } await logProgress("Generating FlatBuffer definitions", async () => { await fs.mkdir(path.join(outDir, "flatbuffer", "foxglove"), { recursive: true }); + await fs.writeFile( + path.join(outDir, "flatbuffer/foxglove", "ByteVectorForNesting.fbs"), + BYTE_VECTOR_FB, + ); await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Time.fbs"), TIME_FB); await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Duration.fbs"), DURATION_FB); for (const schema of Object.values(foxgloveMessageSchemas)) { From d345d273702fcdf7de2de7a231d54da2d911359a Mon Sep 17 00:00:00 2001 From: snosenzo Date: Wed, 9 Nov 2022 17:44:10 +0100 Subject: [PATCH 04/15] - add default 1.0 fields - lowercase field names for compliance with flatc warnings --- internal/generateFlatbuffer.ts | 19 +++++++++++++++++-- .../flatbuffer/foxglove/CameraCalibration.fbs | 8 ++++---- schemas/flatbuffer/foxglove/Color.fbs | 8 ++++---- schemas/flatbuffer/foxglove/Point2.fbs | 4 ++-- schemas/flatbuffer/foxglove/Point3.fbs | 6 +++--- schemas/flatbuffer/foxglove/Quaternion.fbs | 8 ++++---- schemas/flatbuffer/foxglove/Vector2.fbs | 4 ++-- schemas/flatbuffer/foxglove/Vector3.fbs | 6 +++--- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts index f64335d..44c0d2d 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffer.ts @@ -1,4 +1,4 @@ -import { FoxglovePrimitive, FoxgloveSchema } from "./types"; +import { FoxgloveMessageField, FoxglovePrimitive, FoxgloveSchema } from "./types"; // Flatbuffer only supports nested vectors via table export const BYTE_VECTOR_FB = `table ByteVectorForNesting { @@ -21,6 +21,16 @@ export const DURATION_FB = `struct Duration { } `; +// fields that would benefit from having a default of 1 +const defaultOneNumberFields = new Set(["x", "y", "z", "r", "g", "b", "a", "w"]); +function isDefaultOneField(field: FoxgloveMessageField): boolean { + return ( + field.type.type === "primitive" && + field.type.name === "float64" && + defaultOneNumberFields.has(field.name) + ); +} + function primitiveToFlatbuffer(type: Exclude) { switch (type) { case "uint32": @@ -94,8 +104,13 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { .trim() .split("\n") .map((line) => ` /// ${line}\n`) + .join("")}${ // can't have inline comments, so the lengthComment needs to be above - .join("")}${lengthComment ?? ""} ${field.name}:${isArray ? `[${type}]` : type};`; + lengthComment ?? "" + // convert field.name to lowercase for flatbuffer compilation compliance + } ${field.name.toLowerCase()}:${isArray ? `[${type}]` : type}${ + isDefaultOneField(field) ? ` = 1.0` : "" + };`; }); definition = `/// ${schema.description}\ntable ${schema.name} {\n${fields.join( diff --git a/schemas/flatbuffer/foxglove/CameraCalibration.fbs b/schemas/flatbuffer/foxglove/CameraCalibration.fbs index 041eb1e..8439c9a 100644 --- a/schemas/flatbuffer/foxglove/CameraCalibration.fbs +++ b/schemas/flatbuffer/foxglove/CameraCalibration.fbs @@ -22,7 +22,7 @@ table CameraCalibration { distortion_model:string; /// Distortion parameters - D:[double]; + d:[double]; /// Intrinsic camera matrix (3x3 row-major matrix) /// @@ -36,13 +36,13 @@ table CameraCalibration { /// [ 0 0 1] /// ``` /// length 9 - K:[double]; + k:[double]; /// Rectification matrix (3x3 row-major matrix) /// /// A rotation matrix aligning the camera coordinate system to the ideal stereo image plane so that epipolar lines in both stereo images are parallel. /// length 9 - R:[double]; + r:[double]; /// Projection/camera matrix (3x4 row-major matrix) /// @@ -70,7 +70,7 @@ table CameraCalibration { /// /// This holds for both images of a stereo pair. /// length 12 - P:[double]; + p:[double]; } root_type CameraCalibration; diff --git a/schemas/flatbuffer/foxglove/Color.fbs b/schemas/flatbuffer/foxglove/Color.fbs index f119c3e..9c48fed 100644 --- a/schemas/flatbuffer/foxglove/Color.fbs +++ b/schemas/flatbuffer/foxglove/Color.fbs @@ -5,16 +5,16 @@ namespace foxglove; /// A color in RGBA format table Color { /// Red value between 0 and 1 - r:double; + r:double = 1.0; /// Green value between 0 and 1 - g:double; + g:double = 1.0; /// Blue value between 0 and 1 - b:double; + b:double = 1.0; /// Alpha value between 0 and 1 - a:double; + a:double = 1.0; } root_type Color; diff --git a/schemas/flatbuffer/foxglove/Point2.fbs b/schemas/flatbuffer/foxglove/Point2.fbs index 17dd980..9c8c9b9 100644 --- a/schemas/flatbuffer/foxglove/Point2.fbs +++ b/schemas/flatbuffer/foxglove/Point2.fbs @@ -5,10 +5,10 @@ namespace foxglove; /// A point representing a position in 2D space table Point2 { /// x coordinate position - x:double; + x:double = 1.0; /// y coordinate position - y:double; + y:double = 1.0; } root_type Point2; diff --git a/schemas/flatbuffer/foxglove/Point3.fbs b/schemas/flatbuffer/foxglove/Point3.fbs index c497bd1..d65239f 100644 --- a/schemas/flatbuffer/foxglove/Point3.fbs +++ b/schemas/flatbuffer/foxglove/Point3.fbs @@ -5,13 +5,13 @@ namespace foxglove; /// A point representing a position in 3D space table Point3 { /// x coordinate position - x:double; + x:double = 1.0; /// y coordinate position - y:double; + y:double = 1.0; /// z coordinate position - z:double; + z:double = 1.0; } root_type Point3; diff --git a/schemas/flatbuffer/foxglove/Quaternion.fbs b/schemas/flatbuffer/foxglove/Quaternion.fbs index 7179c13..29e2b7d 100644 --- a/schemas/flatbuffer/foxglove/Quaternion.fbs +++ b/schemas/flatbuffer/foxglove/Quaternion.fbs @@ -5,16 +5,16 @@ namespace foxglove; /// A [quaternion](https://eater.net/quaternions) representing a rotation in 3D space table Quaternion { /// x value - x:double; + x:double = 1.0; /// y value - y:double; + y:double = 1.0; /// z value - z:double; + z:double = 1.0; /// w value - w:double; + w:double = 1.0; } root_type Quaternion; diff --git a/schemas/flatbuffer/foxglove/Vector2.fbs b/schemas/flatbuffer/foxglove/Vector2.fbs index ea12c59..0c21dca 100644 --- a/schemas/flatbuffer/foxglove/Vector2.fbs +++ b/schemas/flatbuffer/foxglove/Vector2.fbs @@ -5,10 +5,10 @@ namespace foxglove; /// A vector in 2D space that represents a direction only table Vector2 { /// x coordinate length - x:double; + x:double = 1.0; /// y coordinate length - y:double; + y:double = 1.0; } root_type Vector2; diff --git a/schemas/flatbuffer/foxglove/Vector3.fbs b/schemas/flatbuffer/foxglove/Vector3.fbs index 3c7b156..1555c31 100644 --- a/schemas/flatbuffer/foxglove/Vector3.fbs +++ b/schemas/flatbuffer/foxglove/Vector3.fbs @@ -5,13 +5,13 @@ namespace foxglove; /// A vector in 3D space that represents a direction only table Vector3 { /// x coordinate length - x:double; + x:double = 1.0; /// y coordinate length - y:double; + y:double = 1.0; /// z coordinate length - z:double; + z:double = 1.0; } root_type Vector3; From d3ac125e9e893c034834ca74fcc44261fc04310e Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 10 Nov 2022 20:51:55 +0100 Subject: [PATCH 05/15] - respond to PR feedback - remove `foxglove` subdir - use more readable type aliases - comment Time, Duration types --- internal/generateFlatbuffer.test.ts | 224 +++++++++--------- internal/generateFlatbuffer.ts | 58 ++--- internal/schemas.ts | 10 + internal/testFixtures.ts | 1 + internal/types.ts | 1 + .../foxglove/ByteVectorForNesting.fbs | 5 - schemas/flatbuffer/foxglove/Duration.fbs | 4 - schemas/flatbuffer/foxglove/Time.fbs | 4 - .../ArrowPrimitive.fbs | 0 schemas/flatbuffers/ByteVector.fbs | 7 + .../CameraCalibration.fbs | 4 +- .../CircleAnnotation.fbs | 0 .../foxglove => flatbuffers}/Color.fbs | 0 .../CompressedImage.fbs | 2 +- .../CubePrimitive.fbs | 0 .../CylinderPrimitive.fbs | 0 schemas/flatbuffers/Duration.fbs | 8 + .../FrameTransform.fbs | 0 .../foxglove => flatbuffers}/GeoJSON.fbs | 0 .../foxglove => flatbuffers}/Grid.fbs | 8 +- .../ImageAnnotations.fbs | 0 .../foxglove => flatbuffers}/KeyValuePair.fbs | 0 .../foxglove => flatbuffers}/LaserScan.fbs | 0 .../LinePrimitive.fbs | 2 +- .../foxglove => flatbuffers}/LineType.fbs | 2 +- .../foxglove => flatbuffers}/LocationFix.fbs | 0 .../foxglove => flatbuffers}/Log.fbs | 2 +- .../foxglove => flatbuffers}/LogLevel.fbs | 2 +- .../ModelPrimitive.fbs | 2 +- .../foxglove => flatbuffers}/NumericType.fbs | 2 +- .../PackedElementField.fbs | 2 +- .../foxglove => flatbuffers}/Point2.fbs | 4 +- .../foxglove => flatbuffers}/Point3.fbs | 6 +- .../foxglove => flatbuffers}/PointCloud.fbs | 4 +- .../PointsAnnotation.fbs | 0 .../PointsAnnotationType.fbs | 2 +- .../foxglove => flatbuffers}/Pose.fbs | 0 .../foxglove => flatbuffers}/PoseInFrame.fbs | 0 .../foxglove => flatbuffers}/PosesInFrame.fbs | 0 .../PositionCovarianceType.fbs | 2 +- .../foxglove => flatbuffers}/Quaternion.fbs | 6 +- .../foxglove => flatbuffers}/RawImage.fbs | 8 +- .../foxglove => flatbuffers}/SceneEntity.fbs | 0 .../SceneEntityDeletion.fbs | 0 .../SceneEntityDeletionType.fbs | 2 +- .../foxglove => flatbuffers}/SceneUpdate.fbs | 0 .../SpherePrimitive.fbs | 0 .../TextPrimitive.fbs | 0 schemas/flatbuffers/Time.fbs | 7 + .../TriangleListPrimitive.fbs | 2 +- .../foxglove => flatbuffers}/Vector2.fbs | 0 .../foxglove => flatbuffers}/Vector3.fbs | 0 scripts/updateGeneratedFiles.ts | 15 +- 53 files changed, 215 insertions(+), 193 deletions(-) delete mode 100644 schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs delete mode 100644 schemas/flatbuffer/foxglove/Duration.fbs delete mode 100644 schemas/flatbuffer/foxglove/Time.fbs rename schemas/{flatbuffer/foxglove => flatbuffers}/ArrowPrimitive.fbs (100%) create mode 100644 schemas/flatbuffers/ByteVector.fbs rename schemas/{flatbuffer/foxglove => flatbuffers}/CameraCalibration.fbs (98%) rename schemas/{flatbuffer/foxglove => flatbuffers}/CircleAnnotation.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Color.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/CompressedImage.fbs (96%) rename schemas/{flatbuffer/foxglove => flatbuffers}/CubePrimitive.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/CylinderPrimitive.fbs (100%) create mode 100644 schemas/flatbuffers/Duration.fbs rename schemas/{flatbuffer/foxglove => flatbuffers}/FrameTransform.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/GeoJSON.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Grid.fbs (91%) rename schemas/{flatbuffer/foxglove => flatbuffers}/ImageAnnotations.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/KeyValuePair.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/LaserScan.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/LinePrimitive.fbs (98%) rename schemas/{flatbuffer/foxglove => flatbuffers}/LineType.fbs (92%) rename schemas/{flatbuffer/foxglove => flatbuffers}/LocationFix.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Log.fbs (96%) rename schemas/{flatbuffer/foxglove => flatbuffers}/LogLevel.fbs (88%) rename schemas/{flatbuffer/foxglove => flatbuffers}/ModelPrimitive.fbs (98%) rename schemas/{flatbuffer/foxglove => flatbuffers}/NumericType.fbs (89%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PackedElementField.fbs (96%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Point2.fbs (85%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Point3.fbs (81%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PointCloud.fbs (94%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PointsAnnotation.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PointsAnnotationType.fbs (84%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Pose.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PoseInFrame.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PosesInFrame.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/PositionCovarianceType.fbs (82%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Quaternion.fbs (83%) rename schemas/{flatbuffer/foxglove => flatbuffers}/RawImage.fbs (89%) rename schemas/{flatbuffer/foxglove => flatbuffers}/SceneEntity.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/SceneEntityDeletion.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/SceneEntityDeletionType.fbs (89%) rename schemas/{flatbuffer/foxglove => flatbuffers}/SceneUpdate.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/SpherePrimitive.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/TextPrimitive.fbs (100%) create mode 100644 schemas/flatbuffers/Time.fbs rename schemas/{flatbuffer/foxglove => flatbuffers}/TriangleListPrimitive.fbs (98%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Vector2.fbs (100%) rename schemas/{flatbuffer/foxglove => flatbuffers}/Vector3.fbs (100%) diff --git a/internal/generateFlatbuffer.test.ts b/internal/generateFlatbuffer.test.ts index 5e379ae..e00b1fb 100644 --- a/internal/generateFlatbuffer.test.ts +++ b/internal/generateFlatbuffer.test.ts @@ -4,126 +4,126 @@ import { exampleEnum, exampleMessage } from "./testFixtures"; describe("generateFlatBuffer", () => { it("generates Message .fbs files", () => { expect(generateFlatbuffer(exampleMessage)).toMatchInlineSnapshot(` - "// Generated by https://github.com/foxglove/schemas - - include "ByteVectorForNesting.fbs"; - include "Duration.fbs"; - include "ExampleEnum.fbs"; - include "NestedMessage.fbs"; - include "Time.fbs"; - - namespace foxglove; - - /// An example type - table ExampleMessage { - /// duration field - field_duration:Duration; - - /// time field - field_time:Time; - - /// boolean field - field_boolean:bool; - - /// bytes field - field_bytes:[byte]; - - /// float64 field - field_float64:double; - - /// uint32 field - field_uint32:uint; - - /// string field - field_string:string; - - /// duration array field - field_duration_array:[Duration]; - - /// time array field - field_time_array:[Time]; - - /// boolean array field - field_boolean_array:[bool]; - - /// bytes array field - field_bytes_array:[ByteVectorForNesting]; - - /// float64 array field - field_float64_array:[double]; - - /// uint32 array field - field_uint32_array:[uint]; - - /// string array field - field_string_array:[string]; - - /// duration fixed-length array field - /// length 3 - field_duration_fixed_array:[Duration]; - - /// time fixed-length array field - /// length 3 - field_time_fixed_array:[Time]; - - /// boolean fixed-length array field - /// length 3 - field_boolean_fixed_array:[bool]; - - /// bytes fixed-length array field - /// length 3 - field_bytes_fixed_array:[ByteVectorForNesting]; - - /// float64 fixed-length array field - /// length 3 - field_float64_fixed_array:[double]; - - /// uint32 fixed-length array field - /// length 3 - field_uint32_fixed_array:[uint]; - - /// string fixed-length array field - /// length 3 - field_string_fixed_array:[string]; - - /// An enum field - field_enum:ExampleEnum; - - /// An enum array field - field_enum_array:[ExampleEnum]; - - /// A nested field - field_nested:foxglove.NestedMessage; - - /// A nested array field - /// With - /// a - /// very - /// long - /// description - field_nested_array:[foxglove.NestedMessage]; - } - - root_type ExampleMessage; - " + "// Generated by https://github.com/foxglove/schemas + + include "ByteVector.fbs"; + include "Duration.fbs"; + include "ExampleEnum.fbs"; + include "NestedMessage.fbs"; + include "Time.fbs"; + + namespace foxglove; + + /// An example type + table ExampleMessage { + /// duration field + field_duration:Duration = 1; + + /// time field + field_time:Time = 1; + + /// boolean field + field_boolean:bool = true; + + /// bytes field + field_bytes:[uint8] = 1; + + /// float64 field + field_float64:double = 1; + + /// uint32 field + field_uint32:uint32 = 1; + + /// string field + field_string:string = 1; + + /// duration array field + field_duration_array:[Duration]; + + /// time array field + field_time_array:[Time]; + + /// boolean array field + field_boolean_array:[bool]; + + /// bytes array field + field_bytes_array:[ByteVector]; + + /// float64 array field + field_float64_array:[double]; + + /// uint32 array field + field_uint32_array:[uint32]; + + /// string array field + field_string_array:[string]; + + /// duration fixed-length array field + /// length 3 + field_duration_fixed_array:[Duration]; + + /// time fixed-length array field + /// length 3 + field_time_fixed_array:[Time]; + + /// boolean fixed-length array field + /// length 3 + field_boolean_fixed_array:[bool]; + + /// bytes fixed-length array field + /// length 3 + field_bytes_fixed_array:[ByteVector]; + + /// float64 fixed-length array field + /// length 3 + field_float64_fixed_array:[double]; + + /// uint32 fixed-length array field + /// length 3 + field_uint32_fixed_array:[uint32]; + + /// string fixed-length array field + /// length 3 + field_string_fixed_array:[string]; + + /// An enum field + field_enum:ExampleEnum; + + /// An enum array field + field_enum_array:[ExampleEnum]; + + /// A nested field + field_nested:foxglove.NestedMessage; + + /// A nested array field + /// With + /// a + /// very + /// long + /// description + field_nested_array:[foxglove.NestedMessage]; + } + + root_type ExampleMessage; + " `); }); it("generates Enum .fbs files", () => { expect(generateFlatbuffer(exampleEnum)).toMatchInlineSnapshot(` - "// Generated by https://github.com/foxglove/schemas + "// Generated by https://github.com/foxglove/schemas - namespace foxglove; + namespace foxglove; - /// An example enum - enum ExampleEnum : byte { - /// Value A - A = 1, + /// An example enum + enum ExampleEnum : ubyte { + /// Value A + A = 1, - /// Value B - B = 2, - } + /// Value B + B = 2, + } - " + " `); }); }); diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts index 44c0d2d..7d9af24 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffer.ts @@ -1,42 +1,41 @@ -import { FoxgloveMessageField, FoxglovePrimitive, FoxgloveSchema } from "./types"; +import { FoxglovePrimitive, FoxgloveSchema } from "./types"; // Flatbuffer only supports nested vectors via table -export const BYTE_VECTOR_FB = `table ByteVectorForNesting { - data:[byte]; -} +export const BYTE_VECTOR_FB = `namespace foxglove; -root_type ByteVectorForNesting; +/// Used for nesting byte vectors +table ByteVector { + data:[uint8]; +} +root_type ByteVector; `; // Same as protobuf wellknown types -export const TIME_FB = `struct Time { - sec:long; - nsec:int; +export const TIME_FB = `namespace foxglove; +struct Time { + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint64; + /// Nano-second fractions from 0 to 999,999,999 inclusive + nsec:uint32; } `; -export const DURATION_FB = `struct Duration { - sec:long; - nsec:int; +export const DURATION_FB = `namespace foxglove; +struct Duration { + /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. + sec:int64; + /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 + /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 + nsec:int32; } `; -// fields that would benefit from having a default of 1 -const defaultOneNumberFields = new Set(["x", "y", "z", "r", "g", "b", "a", "w"]); -function isDefaultOneField(field: FoxgloveMessageField): boolean { - return ( - field.type.type === "primitive" && - field.type.name === "float64" && - defaultOneNumberFields.has(field.name) - ); -} - function primitiveToFlatbuffer(type: Exclude) { switch (type) { case "uint32": - return "uint"; + return "uint32"; case "bytes": - return "[byte]"; + return "[uint8]"; case "string": return "string"; case "boolean": @@ -60,7 +59,7 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { }); // `///` comments required to show up in compiled flatbuffer schemas - definition = `/// ${schema.description}\nenum ${schema.name} : byte {\n ${fields.join( + definition = `/// ${schema.description}\nenum ${schema.name} : ubyte {\n ${fields.join( "\n\n ", )}\n}\n`; break; @@ -87,8 +86,8 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { type = "Duration"; imports.add(`Duration`); } else if (field.type.name === "bytes" && isArray) { - type = "ByteVectorForNesting"; - imports.add("ByteVectorForNesting"); + type = "ByteVector"; + imports.add("ByteVector"); } else { type = primitiveToFlatbuffer(field.type.name); } @@ -100,6 +99,11 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { // can't specify length of vector outside of struct, all of these are tables lengthComment = ` /// length ${field.array}\n`; } + let defaultValue; + if (field.defaultValue != undefined) { + defaultValue = field.defaultValue; + } + return `${field.description .trim() .split("\n") @@ -109,7 +113,7 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { lengthComment ?? "" // convert field.name to lowercase for flatbuffer compilation compliance } ${field.name.toLowerCase()}:${isArray ? `[${type}]` : type}${ - isDefaultOneField(field) ? ` = 1.0` : "" + defaultValue ? ` = ${defaultValue}` : "" };`; }); diff --git a/internal/schemas.ts b/internal/schemas.ts index dd70c43..2f57b11 100644 --- a/internal/schemas.ts +++ b/internal/schemas.ts @@ -9,21 +9,25 @@ const Color: FoxgloveMessageSchema = { name: "r", type: { type: "primitive", name: "float64" }, description: "Red value between 0 and 1", + defaultValue: "1.0", }, { name: "g", type: { type: "primitive", name: "float64" }, description: "Green value between 0 and 1", + defaultValue: "1.0", }, { name: "b", type: { type: "primitive", name: "float64" }, description: "Blue value between 0 and 1", + defaultValue: "1.0", }, { name: "a", type: { type: "primitive", name: "float64" }, description: "Alpha value between 0 and 1", + defaultValue: "1.0", }, ], }; @@ -37,11 +41,13 @@ const Vector2: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", + defaultValue: "1.0", }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", + defaultValue: "1.0", }, ], }; @@ -56,16 +62,19 @@ const Vector3: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", + defaultValue: "1.0", }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", + defaultValue: "1.0", }, { name: "z", type: { type: "primitive", name: "float64" }, description: "z coordinate length", + defaultValue: "1.0", }, ], }; @@ -137,6 +146,7 @@ const Quaternion: FoxgloveMessageSchema = { name: "w", type: { type: "primitive", name: "float64" }, description: "w value", + defaultValue: "1.0", }, ], }; diff --git a/internal/testFixtures.ts b/internal/testFixtures.ts index 62de11d..10f6103 100644 --- a/internal/testFixtures.ts +++ b/internal/testFixtures.ts @@ -44,6 +44,7 @@ export const exampleMessage: FoxgloveMessageSchema = { name: `field_${name}`, description: `${name} field`, type: { type: "primitive", name }, + defaultValue: name === "boolean" ? "true" : "1", })), ...allPrimitives.map((name): FoxgloveMessageSchema["fields"][0] => ({ name: `field_${name}_array`, diff --git a/internal/types.ts b/internal/types.ts index b3f05cd..4b1e07f 100644 --- a/internal/types.ts +++ b/internal/types.ts @@ -30,6 +30,7 @@ export type FoxgloveMessageField = { required?: true; description: string; protobufFieldNumber?: number; + defaultValue?: string; }; export type FoxgloveMessageSchema = { diff --git a/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs b/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs deleted file mode 100644 index 9439bea..0000000 --- a/schemas/flatbuffer/foxglove/ByteVectorForNesting.fbs +++ /dev/null @@ -1,5 +0,0 @@ -table ByteVectorForNesting { - data:[byte]; -} - -root_type ByteVectorForNesting; diff --git a/schemas/flatbuffer/foxglove/Duration.fbs b/schemas/flatbuffer/foxglove/Duration.fbs deleted file mode 100644 index 6052258..0000000 --- a/schemas/flatbuffer/foxglove/Duration.fbs +++ /dev/null @@ -1,4 +0,0 @@ -struct Duration { - sec:long; - nsec:int; -} diff --git a/schemas/flatbuffer/foxglove/Time.fbs b/schemas/flatbuffer/foxglove/Time.fbs deleted file mode 100644 index 23a9396..0000000 --- a/schemas/flatbuffer/foxglove/Time.fbs +++ /dev/null @@ -1,4 +0,0 @@ -struct Time { - sec:long; - nsec:int; -} diff --git a/schemas/flatbuffer/foxglove/ArrowPrimitive.fbs b/schemas/flatbuffers/ArrowPrimitive.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/ArrowPrimitive.fbs rename to schemas/flatbuffers/ArrowPrimitive.fbs diff --git a/schemas/flatbuffers/ByteVector.fbs b/schemas/flatbuffers/ByteVector.fbs new file mode 100644 index 0000000..f62662f --- /dev/null +++ b/schemas/flatbuffers/ByteVector.fbs @@ -0,0 +1,7 @@ +namespace foxglove; + +/// Used for nesting byte vectors +table ByteVector { + data:[uint8]; +} +root_type ByteVector; diff --git a/schemas/flatbuffer/foxglove/CameraCalibration.fbs b/schemas/flatbuffers/CameraCalibration.fbs similarity index 98% rename from schemas/flatbuffer/foxglove/CameraCalibration.fbs rename to schemas/flatbuffers/CameraCalibration.fbs index 8439c9a..a889174 100644 --- a/schemas/flatbuffer/foxglove/CameraCalibration.fbs +++ b/schemas/flatbuffers/CameraCalibration.fbs @@ -13,10 +13,10 @@ table CameraCalibration { frame_id:string; /// Image width - width:uint; + width:uint32; /// Image height - height:uint; + height:uint32; /// Name of distortion model distortion_model:string; diff --git a/schemas/flatbuffer/foxglove/CircleAnnotation.fbs b/schemas/flatbuffers/CircleAnnotation.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/CircleAnnotation.fbs rename to schemas/flatbuffers/CircleAnnotation.fbs diff --git a/schemas/flatbuffer/foxglove/Color.fbs b/schemas/flatbuffers/Color.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/Color.fbs rename to schemas/flatbuffers/Color.fbs diff --git a/schemas/flatbuffer/foxglove/CompressedImage.fbs b/schemas/flatbuffers/CompressedImage.fbs similarity index 96% rename from schemas/flatbuffer/foxglove/CompressedImage.fbs rename to schemas/flatbuffers/CompressedImage.fbs index 06b8837..e5a033f 100644 --- a/schemas/flatbuffer/foxglove/CompressedImage.fbs +++ b/schemas/flatbuffers/CompressedImage.fbs @@ -13,7 +13,7 @@ table CompressedImage { frame_id:string; /// Compressed image data - data:[byte]; + data:[uint8]; /// Image format format:string; diff --git a/schemas/flatbuffer/foxglove/CubePrimitive.fbs b/schemas/flatbuffers/CubePrimitive.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/CubePrimitive.fbs rename to schemas/flatbuffers/CubePrimitive.fbs diff --git a/schemas/flatbuffer/foxglove/CylinderPrimitive.fbs b/schemas/flatbuffers/CylinderPrimitive.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/CylinderPrimitive.fbs rename to schemas/flatbuffers/CylinderPrimitive.fbs diff --git a/schemas/flatbuffers/Duration.fbs b/schemas/flatbuffers/Duration.fbs new file mode 100644 index 0000000..dd3b44d --- /dev/null +++ b/schemas/flatbuffers/Duration.fbs @@ -0,0 +1,8 @@ +namespace foxglove; +struct Duration { + /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. + sec:int64; + /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 + /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 + nsec:int32; +} diff --git a/schemas/flatbuffer/foxglove/FrameTransform.fbs b/schemas/flatbuffers/FrameTransform.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/FrameTransform.fbs rename to schemas/flatbuffers/FrameTransform.fbs diff --git a/schemas/flatbuffer/foxglove/GeoJSON.fbs b/schemas/flatbuffers/GeoJSON.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/GeoJSON.fbs rename to schemas/flatbuffers/GeoJSON.fbs diff --git a/schemas/flatbuffer/foxglove/Grid.fbs b/schemas/flatbuffers/Grid.fbs similarity index 91% rename from schemas/flatbuffer/foxglove/Grid.fbs rename to schemas/flatbuffers/Grid.fbs index c993511..62d128d 100644 --- a/schemas/flatbuffer/foxglove/Grid.fbs +++ b/schemas/flatbuffers/Grid.fbs @@ -19,22 +19,22 @@ table Grid { pose:foxglove.Pose; /// Number of grid columns - column_count:uint; + column_count:uint32; /// Size of single grid cell along x and y axes, relative to `pose` cell_size:foxglove.Vector2; /// Number of bytes between rows in `data` - row_stride:uint; + row_stride:uint32; /// Number of bytes between cells within a row in `data` - cell_stride:uint; + cell_stride:uint32; /// Fields in `data` fields:[foxglove.PackedElementField]; /// Grid cell data, interpreted using `fields`, in row-major (y-major) order - data:[byte]; + data:[uint8]; } root_type Grid; diff --git a/schemas/flatbuffer/foxglove/ImageAnnotations.fbs b/schemas/flatbuffers/ImageAnnotations.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/ImageAnnotations.fbs rename to schemas/flatbuffers/ImageAnnotations.fbs diff --git a/schemas/flatbuffer/foxglove/KeyValuePair.fbs b/schemas/flatbuffers/KeyValuePair.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/KeyValuePair.fbs rename to schemas/flatbuffers/KeyValuePair.fbs diff --git a/schemas/flatbuffer/foxglove/LaserScan.fbs b/schemas/flatbuffers/LaserScan.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/LaserScan.fbs rename to schemas/flatbuffers/LaserScan.fbs diff --git a/schemas/flatbuffer/foxglove/LinePrimitive.fbs b/schemas/flatbuffers/LinePrimitive.fbs similarity index 98% rename from schemas/flatbuffer/foxglove/LinePrimitive.fbs rename to schemas/flatbuffers/LinePrimitive.fbs index 7547b30..6db759e 100644 --- a/schemas/flatbuffer/foxglove/LinePrimitive.fbs +++ b/schemas/flatbuffers/LinePrimitive.fbs @@ -33,7 +33,7 @@ table LinePrimitive { /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. /// /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). - indices:[uint]; + indices:[uint32]; } root_type LinePrimitive; diff --git a/schemas/flatbuffer/foxglove/LineType.fbs b/schemas/flatbuffers/LineType.fbs similarity index 92% rename from schemas/flatbuffer/foxglove/LineType.fbs rename to schemas/flatbuffers/LineType.fbs index 76f73e7..5b446ad 100644 --- a/schemas/flatbuffer/foxglove/LineType.fbs +++ b/schemas/flatbuffers/LineType.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// An enumeration indicating how input points should be interpreted to create lines -enum LineType : byte { +enum LineType : ubyte { /// 0-1, 1-2, ..., (n-1)-n LINE_STRIP = 0, diff --git a/schemas/flatbuffer/foxglove/LocationFix.fbs b/schemas/flatbuffers/LocationFix.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/LocationFix.fbs rename to schemas/flatbuffers/LocationFix.fbs diff --git a/schemas/flatbuffer/foxglove/Log.fbs b/schemas/flatbuffers/Log.fbs similarity index 96% rename from schemas/flatbuffer/foxglove/Log.fbs rename to schemas/flatbuffers/Log.fbs index ff16520..063fd0c 100644 --- a/schemas/flatbuffer/foxglove/Log.fbs +++ b/schemas/flatbuffers/Log.fbs @@ -23,7 +23,7 @@ table Log { file:string; /// Line number in the file - line:uint; + line:uint32; } root_type Log; diff --git a/schemas/flatbuffer/foxglove/LogLevel.fbs b/schemas/flatbuffers/LogLevel.fbs similarity index 88% rename from schemas/flatbuffer/foxglove/LogLevel.fbs rename to schemas/flatbuffers/LogLevel.fbs index ea14644..687dd76 100644 --- a/schemas/flatbuffer/foxglove/LogLevel.fbs +++ b/schemas/flatbuffers/LogLevel.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// Log level -enum LogLevel : byte { +enum LogLevel : ubyte { UNKNOWN = 0, DEBUG = 1, diff --git a/schemas/flatbuffer/foxglove/ModelPrimitive.fbs b/schemas/flatbuffers/ModelPrimitive.fbs similarity index 98% rename from schemas/flatbuffer/foxglove/ModelPrimitive.fbs rename to schemas/flatbuffers/ModelPrimitive.fbs index 1b8558a..c6493f8 100644 --- a/schemas/flatbuffer/foxglove/ModelPrimitive.fbs +++ b/schemas/flatbuffers/ModelPrimitive.fbs @@ -27,7 +27,7 @@ table ModelPrimitive { media_type:string; /// Embedded model. One of `url` or `data` should be provided. If `data` is provided, `media_type` must be set to indicate the type of the data. - data:[byte]; + data:[uint8]; } root_type ModelPrimitive; diff --git a/schemas/flatbuffer/foxglove/NumericType.fbs b/schemas/flatbuffers/NumericType.fbs similarity index 89% rename from schemas/flatbuffer/foxglove/NumericType.fbs rename to schemas/flatbuffers/NumericType.fbs index 1943af4..b48eb47 100644 --- a/schemas/flatbuffer/foxglove/NumericType.fbs +++ b/schemas/flatbuffers/NumericType.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// Numeric type -enum NumericType : byte { +enum NumericType : ubyte { UNKNOWN = 0, UINT8 = 1, diff --git a/schemas/flatbuffer/foxglove/PackedElementField.fbs b/schemas/flatbuffers/PackedElementField.fbs similarity index 96% rename from schemas/flatbuffer/foxglove/PackedElementField.fbs rename to schemas/flatbuffers/PackedElementField.fbs index 4bb65b3..1262169 100644 --- a/schemas/flatbuffer/foxglove/PackedElementField.fbs +++ b/schemas/flatbuffers/PackedElementField.fbs @@ -10,7 +10,7 @@ table PackedElementField { name:string; /// Byte offset from start of data buffer - offset:uint; + offset:uint32; /// Type of data in the field. Integers are stored using little-endian byte order. type:NumericType; diff --git a/schemas/flatbuffer/foxglove/Point2.fbs b/schemas/flatbuffers/Point2.fbs similarity index 85% rename from schemas/flatbuffer/foxglove/Point2.fbs rename to schemas/flatbuffers/Point2.fbs index 9c8c9b9..17dd980 100644 --- a/schemas/flatbuffer/foxglove/Point2.fbs +++ b/schemas/flatbuffers/Point2.fbs @@ -5,10 +5,10 @@ namespace foxglove; /// A point representing a position in 2D space table Point2 { /// x coordinate position - x:double = 1.0; + x:double; /// y coordinate position - y:double = 1.0; + y:double; } root_type Point2; diff --git a/schemas/flatbuffer/foxglove/Point3.fbs b/schemas/flatbuffers/Point3.fbs similarity index 81% rename from schemas/flatbuffer/foxglove/Point3.fbs rename to schemas/flatbuffers/Point3.fbs index d65239f..c497bd1 100644 --- a/schemas/flatbuffer/foxglove/Point3.fbs +++ b/schemas/flatbuffers/Point3.fbs @@ -5,13 +5,13 @@ namespace foxglove; /// A point representing a position in 3D space table Point3 { /// x coordinate position - x:double = 1.0; + x:double; /// y coordinate position - y:double = 1.0; + y:double; /// z coordinate position - z:double = 1.0; + z:double; } root_type Point3; diff --git a/schemas/flatbuffer/foxglove/PointCloud.fbs b/schemas/flatbuffers/PointCloud.fbs similarity index 94% rename from schemas/flatbuffer/foxglove/PointCloud.fbs rename to schemas/flatbuffers/PointCloud.fbs index 7dd9c0a..d153fd6 100644 --- a/schemas/flatbuffer/foxglove/PointCloud.fbs +++ b/schemas/flatbuffers/PointCloud.fbs @@ -18,13 +18,13 @@ table PointCloud { pose:foxglove.Pose; /// Number of bytes between points in the `data` - point_stride:uint; + point_stride:uint32; /// Fields in the `data` fields:[foxglove.PackedElementField]; /// Point data, interpreted using `fields` - data:[byte]; + data:[uint8]; } root_type PointCloud; diff --git a/schemas/flatbuffer/foxglove/PointsAnnotation.fbs b/schemas/flatbuffers/PointsAnnotation.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/PointsAnnotation.fbs rename to schemas/flatbuffers/PointsAnnotation.fbs diff --git a/schemas/flatbuffer/foxglove/PointsAnnotationType.fbs b/schemas/flatbuffers/PointsAnnotationType.fbs similarity index 84% rename from schemas/flatbuffer/foxglove/PointsAnnotationType.fbs rename to schemas/flatbuffers/PointsAnnotationType.fbs index 9d73df7..ff1d101 100644 --- a/schemas/flatbuffer/foxglove/PointsAnnotationType.fbs +++ b/schemas/flatbuffers/PointsAnnotationType.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// Type of points annotation -enum PointsAnnotationType : byte { +enum PointsAnnotationType : ubyte { UNKNOWN = 0, POINTS = 1, diff --git a/schemas/flatbuffer/foxglove/Pose.fbs b/schemas/flatbuffers/Pose.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/Pose.fbs rename to schemas/flatbuffers/Pose.fbs diff --git a/schemas/flatbuffer/foxglove/PoseInFrame.fbs b/schemas/flatbuffers/PoseInFrame.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/PoseInFrame.fbs rename to schemas/flatbuffers/PoseInFrame.fbs diff --git a/schemas/flatbuffer/foxglove/PosesInFrame.fbs b/schemas/flatbuffers/PosesInFrame.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/PosesInFrame.fbs rename to schemas/flatbuffers/PosesInFrame.fbs diff --git a/schemas/flatbuffer/foxglove/PositionCovarianceType.fbs b/schemas/flatbuffers/PositionCovarianceType.fbs similarity index 82% rename from schemas/flatbuffer/foxglove/PositionCovarianceType.fbs rename to schemas/flatbuffers/PositionCovarianceType.fbs index ba6bf4f..ec8e02a 100644 --- a/schemas/flatbuffer/foxglove/PositionCovarianceType.fbs +++ b/schemas/flatbuffers/PositionCovarianceType.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// Type of position covariance -enum PositionCovarianceType : byte { +enum PositionCovarianceType : ubyte { UNKNOWN = 0, APPROXIMATED = 1, diff --git a/schemas/flatbuffer/foxglove/Quaternion.fbs b/schemas/flatbuffers/Quaternion.fbs similarity index 83% rename from schemas/flatbuffer/foxglove/Quaternion.fbs rename to schemas/flatbuffers/Quaternion.fbs index 29e2b7d..409d24f 100644 --- a/schemas/flatbuffer/foxglove/Quaternion.fbs +++ b/schemas/flatbuffers/Quaternion.fbs @@ -5,13 +5,13 @@ namespace foxglove; /// A [quaternion](https://eater.net/quaternions) representing a rotation in 3D space table Quaternion { /// x value - x:double = 1.0; + x:double; /// y value - y:double = 1.0; + y:double; /// z value - z:double = 1.0; + z:double; /// w value w:double = 1.0; diff --git a/schemas/flatbuffer/foxglove/RawImage.fbs b/schemas/flatbuffers/RawImage.fbs similarity index 89% rename from schemas/flatbuffer/foxglove/RawImage.fbs rename to schemas/flatbuffers/RawImage.fbs index b76241e..000fe90 100644 --- a/schemas/flatbuffer/foxglove/RawImage.fbs +++ b/schemas/flatbuffers/RawImage.fbs @@ -13,19 +13,19 @@ table RawImage { frame_id:string; /// Image width - width:uint; + width:uint32; /// Image height - height:uint; + height:uint32; /// Encoding of the raw image data encoding:string; /// Byte length of a single row - step:uint; + step:uint32; /// Raw image data - data:[byte]; + data:[uint8]; } root_type RawImage; diff --git a/schemas/flatbuffer/foxglove/SceneEntity.fbs b/schemas/flatbuffers/SceneEntity.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/SceneEntity.fbs rename to schemas/flatbuffers/SceneEntity.fbs diff --git a/schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs b/schemas/flatbuffers/SceneEntityDeletion.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/SceneEntityDeletion.fbs rename to schemas/flatbuffers/SceneEntityDeletion.fbs diff --git a/schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs b/schemas/flatbuffers/SceneEntityDeletionType.fbs similarity index 89% rename from schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs rename to schemas/flatbuffers/SceneEntityDeletionType.fbs index 2b6d3c1..1d164f8 100644 --- a/schemas/flatbuffer/foxglove/SceneEntityDeletionType.fbs +++ b/schemas/flatbuffers/SceneEntityDeletionType.fbs @@ -3,7 +3,7 @@ namespace foxglove; /// An enumeration indicating which entities should match a SceneEntityDeletion command -enum SceneEntityDeletionType : byte { +enum SceneEntityDeletionType : ubyte { /// Delete the existing entity on the same topic that has the provided `id` MATCHING_ID = 0, diff --git a/schemas/flatbuffer/foxglove/SceneUpdate.fbs b/schemas/flatbuffers/SceneUpdate.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/SceneUpdate.fbs rename to schemas/flatbuffers/SceneUpdate.fbs diff --git a/schemas/flatbuffer/foxglove/SpherePrimitive.fbs b/schemas/flatbuffers/SpherePrimitive.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/SpherePrimitive.fbs rename to schemas/flatbuffers/SpherePrimitive.fbs diff --git a/schemas/flatbuffer/foxglove/TextPrimitive.fbs b/schemas/flatbuffers/TextPrimitive.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/TextPrimitive.fbs rename to schemas/flatbuffers/TextPrimitive.fbs diff --git a/schemas/flatbuffers/Time.fbs b/schemas/flatbuffers/Time.fbs new file mode 100644 index 0000000..f5a0341 --- /dev/null +++ b/schemas/flatbuffers/Time.fbs @@ -0,0 +1,7 @@ +namespace foxglove; +struct Time { + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint64; + /// Nano-second fractions from 0 to 999,999,999 inclusive + nsec:uint32; +} diff --git a/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs b/schemas/flatbuffers/TriangleListPrimitive.fbs similarity index 98% rename from schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs rename to schemas/flatbuffers/TriangleListPrimitive.fbs index c3d319f..f0233ac 100644 --- a/schemas/flatbuffer/foxglove/TriangleListPrimitive.fbs +++ b/schemas/flatbuffers/TriangleListPrimitive.fbs @@ -23,7 +23,7 @@ table TriangleListPrimitive { /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. /// /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). - indices:[uint]; + indices:[uint32]; } root_type TriangleListPrimitive; diff --git a/schemas/flatbuffer/foxglove/Vector2.fbs b/schemas/flatbuffers/Vector2.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/Vector2.fbs rename to schemas/flatbuffers/Vector2.fbs diff --git a/schemas/flatbuffer/foxglove/Vector3.fbs b/schemas/flatbuffers/Vector3.fbs similarity index 100% rename from schemas/flatbuffer/foxglove/Vector3.fbs rename to schemas/flatbuffers/Vector3.fbs diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index e6d9d31..b47a4c6 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -79,22 +79,19 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } }); await logProgress("Generating FlatBuffer definitions", async () => { - await fs.mkdir(path.join(outDir, "flatbuffer", "foxglove"), { recursive: true }); - await fs.writeFile( - path.join(outDir, "flatbuffer/foxglove", "ByteVectorForNesting.fbs"), - BYTE_VECTOR_FB, - ); - await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Time.fbs"), TIME_FB); - await fs.writeFile(path.join(outDir, "flatbuffer/foxglove", "Duration.fbs"), DURATION_FB); + await fs.mkdir(path.join(outDir, "flatbuffers"), { recursive: true }); + await fs.writeFile(path.join(outDir, "flatbuffers", "ByteVector.fbs"), BYTE_VECTOR_FB); + await fs.writeFile(path.join(outDir, "flatbuffers", "Time.fbs"), TIME_FB); + await fs.writeFile(path.join(outDir, "flatbuffers", "Duration.fbs"), DURATION_FB); for (const schema of Object.values(foxgloveMessageSchemas)) { await fs.writeFile( - path.join(outDir, "flatbuffer", "foxglove", `${schema.name}.fbs`), + path.join(outDir, "flatbuffers", `${schema.name}.fbs`), generateFlatbuffer(schema), ); } for (const schema of Object.values(foxgloveEnumSchemas)) { await fs.writeFile( - path.join(outDir, "flatbuffer", "foxglove", `${schema.name}.fbs`), + path.join(outDir, "flatbuffers", `${schema.name}.fbs`), generateFlatbuffer(schema), ); } From ff4b563d8547998390bd3dd84686440543a5fb1f Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 10 Nov 2022 20:56:11 +0100 Subject: [PATCH 06/15] adjust spacing of time, duration, bytevector flatbuffer schemas --- internal/generateFlatbuffer.ts | 11 ++++++++--- schemas/flatbuffers/ByteVector.fbs | 1 + schemas/flatbuffers/Duration.fbs | 1 + schemas/flatbuffers/Time.fbs | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffer.ts index 7d9af24..d9b24b0 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffer.ts @@ -1,7 +1,8 @@ import { FoxglovePrimitive, FoxgloveSchema } from "./types"; // Flatbuffer only supports nested vectors via table -export const BYTE_VECTOR_FB = `namespace foxglove; +export const BYTE_VECTOR_FB = ` +namespace foxglove; /// Used for nesting byte vectors table ByteVector { @@ -11,7 +12,9 @@ root_type ByteVector; `; // Same as protobuf wellknown types -export const TIME_FB = `namespace foxglove; +export const TIME_FB = ` +namespace foxglove; + struct Time { /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z sec:uint64; @@ -20,7 +23,9 @@ struct Time { } `; -export const DURATION_FB = `namespace foxglove; +export const DURATION_FB = ` +namespace foxglove; + struct Duration { /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. sec:int64; diff --git a/schemas/flatbuffers/ByteVector.fbs b/schemas/flatbuffers/ByteVector.fbs index f62662f..513df43 100644 --- a/schemas/flatbuffers/ByteVector.fbs +++ b/schemas/flatbuffers/ByteVector.fbs @@ -1,3 +1,4 @@ + namespace foxglove; /// Used for nesting byte vectors diff --git a/schemas/flatbuffers/Duration.fbs b/schemas/flatbuffers/Duration.fbs index dd3b44d..4f155e6 100644 --- a/schemas/flatbuffers/Duration.fbs +++ b/schemas/flatbuffers/Duration.fbs @@ -1,3 +1,4 @@ + namespace foxglove; struct Duration { /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. diff --git a/schemas/flatbuffers/Time.fbs b/schemas/flatbuffers/Time.fbs index f5a0341..ac1634e 100644 --- a/schemas/flatbuffers/Time.fbs +++ b/schemas/flatbuffers/Time.fbs @@ -1,3 +1,4 @@ + namespace foxglove; struct Time { /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z From e274c21cbeedab332bbbacc02e4254a480f22c6b Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 10 Nov 2022 20:59:37 +0100 Subject: [PATCH 07/15] - flatbuffer -> flatbuffers in code --- ...rateFlatbuffer.test.ts => generateFlatbuffers.test.ts} | 6 +++--- .../{generateFlatbuffer.ts => generateFlatbuffers.ts} | 8 ++++---- schemas/flatbuffers/Duration.fbs | 1 + schemas/flatbuffers/Time.fbs | 1 + scripts/updateGeneratedFiles.ts | 8 ++++---- 5 files changed, 13 insertions(+), 11 deletions(-) rename internal/{generateFlatbuffer.test.ts => generateFlatbuffers.test.ts} (93%) rename internal/{generateFlatbuffer.ts => generateFlatbuffers.ts} (93%) diff --git a/internal/generateFlatbuffer.test.ts b/internal/generateFlatbuffers.test.ts similarity index 93% rename from internal/generateFlatbuffer.test.ts rename to internal/generateFlatbuffers.test.ts index e00b1fb..2ddeb54 100644 --- a/internal/generateFlatbuffer.test.ts +++ b/internal/generateFlatbuffers.test.ts @@ -1,9 +1,9 @@ -import { generateFlatbuffer } from "./generateFlatbuffer"; +import { generateFlatbuffers } from "./generateFlatbuffers"; import { exampleEnum, exampleMessage } from "./testFixtures"; describe("generateFlatBuffer", () => { it("generates Message .fbs files", () => { - expect(generateFlatbuffer(exampleMessage)).toMatchInlineSnapshot(` + expect(generateFlatbuffers(exampleMessage)).toMatchInlineSnapshot(` "// Generated by https://github.com/foxglove/schemas include "ByteVector.fbs"; @@ -109,7 +109,7 @@ describe("generateFlatBuffer", () => { `); }); it("generates Enum .fbs files", () => { - expect(generateFlatbuffer(exampleEnum)).toMatchInlineSnapshot(` + expect(generateFlatbuffers(exampleEnum)).toMatchInlineSnapshot(` "// Generated by https://github.com/foxglove/schemas namespace foxglove; diff --git a/internal/generateFlatbuffer.ts b/internal/generateFlatbuffers.ts similarity index 93% rename from internal/generateFlatbuffer.ts rename to internal/generateFlatbuffers.ts index d9b24b0..f95e4d5 100644 --- a/internal/generateFlatbuffer.ts +++ b/internal/generateFlatbuffers.ts @@ -1,6 +1,6 @@ import { FoxglovePrimitive, FoxgloveSchema } from "./types"; -// Flatbuffer only supports nested vectors via table +// Flatbuffers only supports nested vectors via table export const BYTE_VECTOR_FB = ` namespace foxglove; @@ -35,7 +35,7 @@ struct Duration { } `; -function primitiveToFlatbuffer(type: Exclude) { +function primitiveToFlatbuffers(type: Exclude) { switch (type) { case "uint32": return "uint32"; @@ -50,7 +50,7 @@ function primitiveToFlatbuffer(type: Exclude(); switch (schema.type) { @@ -94,7 +94,7 @@ export function generateFlatbuffer(schema: FoxgloveSchema): string { type = "ByteVector"; imports.add("ByteVector"); } else { - type = primitiveToFlatbuffer(field.type.name); + type = primitiveToFlatbuffers(field.type.name); } break; } diff --git a/schemas/flatbuffers/Duration.fbs b/schemas/flatbuffers/Duration.fbs index 4f155e6..cb6b595 100644 --- a/schemas/flatbuffers/Duration.fbs +++ b/schemas/flatbuffers/Duration.fbs @@ -1,5 +1,6 @@ namespace foxglove; + struct Duration { /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. sec:int64; diff --git a/schemas/flatbuffers/Time.fbs b/schemas/flatbuffers/Time.fbs index ac1634e..09b5c3b 100644 --- a/schemas/flatbuffers/Time.fbs +++ b/schemas/flatbuffers/Time.fbs @@ -1,5 +1,6 @@ namespace foxglove; + struct Time { /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z sec:uint64; diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index b47a4c6..fc73cc9 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -8,9 +8,9 @@ import { generateRosMsg, generateRosMsgDefinition } from "../internal"; import { BYTE_VECTOR_FB, DURATION_FB, - generateFlatbuffer, + generateFlatbuffers, TIME_FB, -} from "../internal/generateFlatbuffer"; +} from "../internal/generateFlatbuffers"; import { generateJsonSchema } from "../internal/generateJsonSchema"; import { generateMarkdown } from "../internal/generateMarkdown"; import { generateProto } from "../internal/generateProto"; @@ -86,13 +86,13 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } for (const schema of Object.values(foxgloveMessageSchemas)) { await fs.writeFile( path.join(outDir, "flatbuffers", `${schema.name}.fbs`), - generateFlatbuffer(schema), + generateFlatbuffers(schema), ); } for (const schema of Object.values(foxgloveEnumSchemas)) { await fs.writeFile( path.join(outDir, "flatbuffers", `${schema.name}.fbs`), - generateFlatbuffer(schema), + generateFlatbuffers(schema), ); } }); From 5e38b8be4a2714295e4c960dbc514ba24283eaad Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 10 Nov 2022 23:53:25 +0100 Subject: [PATCH 08/15] - add flatbuffer validation to ci --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a8ee6e..d055e08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,13 @@ jobs: echo "Generated schemas are up to date!" fi + - name: Validate Flatbuffer definitions + run: | + curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip && + echo "0821af82a3a736b0ba9235c02219df24d1f042dd Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c + unzip Linux.flatc.binary.clang++-12.zip + ./flatc --ts -o /dev/null schemas/flatbuffers/*.fbs + - name: Validate protobuf definitions run: protoc --proto_path=schemas/proto schemas/proto/**/*.proto --descriptor_set_out=/dev/null From c251616785d99fa16b76bdea89afc541d5d7f8bb Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 10 Nov 2022 23:55:13 +0100 Subject: [PATCH 09/15] remove && --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d055e08..7e2f7dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: - name: Validate Flatbuffer definitions run: | - curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip && + curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip echo "0821af82a3a736b0ba9235c02219df24d1f042dd Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c unzip Linux.flatc.binary.clang++-12.zip ./flatc --ts -o /dev/null schemas/flatbuffers/*.fbs From 5e11a5c0c05088ac5a2f194526067c56a1cd78c9 Mon Sep 17 00:00:00 2001 From: snosenzo Date: Mon, 14 Nov 2022 21:42:10 +0100 Subject: [PATCH 10/15] - enums in files with parents --- internal/generateFlatbuffers.test.ts | 29 ++++++----------- internal/generateFlatbuffers.ts | 31 +++++++++++++++---- schemas/flatbuffers/LinePrimitive.fbs | 12 ++++++- schemas/flatbuffers/LineType.fbs | 16 ---------- schemas/flatbuffers/LocationFix.fbs | 12 +++++-- schemas/flatbuffers/Log.fbs | 15 ++++++++- schemas/flatbuffers/LogLevel.fbs | 19 ------------ schemas/flatbuffers/NumericType.fbs | 25 --------------- schemas/flatbuffers/PackedElementField.fbs | 22 +++++++++++-- schemas/flatbuffers/PointsAnnotation.fbs | 13 +++++++- schemas/flatbuffers/PointsAnnotationType.fbs | 17 ---------- .../flatbuffers/PositionCovarianceType.fbs | 15 --------- schemas/flatbuffers/SceneEntityDeletion.fbs | 9 +++++- .../flatbuffers/SceneEntityDeletionType.fbs | 13 -------- scripts/updateGeneratedFiles.ts | 11 +++---- 15 files changed, 114 insertions(+), 145 deletions(-) delete mode 100644 schemas/flatbuffers/LineType.fbs delete mode 100644 schemas/flatbuffers/LogLevel.fbs delete mode 100644 schemas/flatbuffers/NumericType.fbs delete mode 100644 schemas/flatbuffers/PointsAnnotationType.fbs delete mode 100644 schemas/flatbuffers/PositionCovarianceType.fbs delete mode 100644 schemas/flatbuffers/SceneEntityDeletionType.fbs diff --git a/internal/generateFlatbuffers.test.ts b/internal/generateFlatbuffers.test.ts index 2ddeb54..86fc8cf 100644 --- a/internal/generateFlatbuffers.test.ts +++ b/internal/generateFlatbuffers.test.ts @@ -3,17 +3,24 @@ import { exampleEnum, exampleMessage } from "./testFixtures"; describe("generateFlatBuffer", () => { it("generates Message .fbs files", () => { - expect(generateFlatbuffers(exampleMessage)).toMatchInlineSnapshot(` + expect(generateFlatbuffers(exampleMessage, [exampleEnum])).toMatchInlineSnapshot(` "// Generated by https://github.com/foxglove/schemas include "ByteVector.fbs"; include "Duration.fbs"; - include "ExampleEnum.fbs"; include "NestedMessage.fbs"; include "Time.fbs"; namespace foxglove; + /// An example enum + enum ExampleEnum : ubyte { + /// Value A + A = 1, + + /// Value B + B = 2, + } /// An example type table ExampleMessage { /// duration field @@ -108,22 +115,4 @@ describe("generateFlatBuffer", () => { " `); }); - it("generates Enum .fbs files", () => { - expect(generateFlatbuffers(exampleEnum)).toMatchInlineSnapshot(` - "// Generated by https://github.com/foxglove/schemas - - namespace foxglove; - - /// An example enum - enum ExampleEnum : ubyte { - /// Value A - A = 1, - - /// Value B - B = 2, - } - - " - `); - }); }); diff --git a/internal/generateFlatbuffers.ts b/internal/generateFlatbuffers.ts index f95e4d5..183996d 100644 --- a/internal/generateFlatbuffers.ts +++ b/internal/generateFlatbuffers.ts @@ -1,4 +1,4 @@ -import { FoxglovePrimitive, FoxgloveSchema } from "./types"; +import { FoxgloveEnumSchema, FoxglovePrimitive, FoxgloveSchema } from "./types"; // Flatbuffers only supports nested vectors via table export const BYTE_VECTOR_FB = ` @@ -50,7 +50,27 @@ function primitiveToFlatbuffers(type: Exclude { + if (description != undefined) { + return `/// ${description}\n ${name} = ${value},`; + } else { + return `${name} = ${value},`; + } + }); + enumDefinitions.push( + // `///` comments required to show up in compiled flatbuffer schemas + `/// ${enumSchema.description}\nenum ${enumSchema.name} : ubyte {\n ${fields.join( + "\n\n ", + )}\n}\n`, + ); + } + let definition; const imports = new Set(); switch (schema.type) { @@ -77,7 +97,6 @@ export function generateFlatbuffers(schema: FoxgloveSchema): string { switch (field.type.type) { case "enum": type = field.type.enum.name; - imports.add(field.type.enum.name); break; case "nested": type = `foxglove.${field.type.schema.name}`; @@ -122,9 +141,9 @@ export function generateFlatbuffers(schema: FoxgloveSchema): string { };`; }); - definition = `/// ${schema.description}\ntable ${schema.name} {\n${fields.join( - "\n\n", - )}\n}\n\nroot_type ${schema.name};`; + definition = `${enumDefinitions.join("\n\n")}/// ${schema.description}\ntable ${ + schema.name + } {\n${fields.join("\n\n")}\n}\n\nroot_type ${schema.name};`; break; } } diff --git a/schemas/flatbuffers/LinePrimitive.fbs b/schemas/flatbuffers/LinePrimitive.fbs index 6db759e..a7ced77 100644 --- a/schemas/flatbuffers/LinePrimitive.fbs +++ b/schemas/flatbuffers/LinePrimitive.fbs @@ -1,12 +1,22 @@ // Generated by https://github.com/foxglove/schemas include "Color.fbs"; -include "LineType.fbs"; include "Point3.fbs"; include "Pose.fbs"; namespace foxglove; +/// An enumeration indicating how input points should be interpreted to create lines +enum LineType : ubyte { + /// 0-1, 1-2, ..., (n-1)-n + LINE_STRIP = 0, + + /// 0-1, 1-2, ..., (n-1)-n, n-0 + LINE_LOOP = 1, + + /// 0-1, 2-3, 4-5, ... + LINE_LIST = 2, +} /// A primitive representing a series of points connected by lines table LinePrimitive { /// Drawing primitive to use for lines diff --git a/schemas/flatbuffers/LineType.fbs b/schemas/flatbuffers/LineType.fbs deleted file mode 100644 index 5b446ad..0000000 --- a/schemas/flatbuffers/LineType.fbs +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// An enumeration indicating how input points should be interpreted to create lines -enum LineType : ubyte { - /// 0-1, 1-2, ..., (n-1)-n - LINE_STRIP = 0, - - /// 0-1, 1-2, ..., (n-1)-n, n-0 - LINE_LOOP = 1, - - /// 0-1, 2-3, 4-5, ... - LINE_LIST = 2, -} - diff --git a/schemas/flatbuffers/LocationFix.fbs b/schemas/flatbuffers/LocationFix.fbs index 7b0cae2..68a6011 100644 --- a/schemas/flatbuffers/LocationFix.fbs +++ b/schemas/flatbuffers/LocationFix.fbs @@ -1,9 +1,17 @@ // Generated by https://github.com/foxglove/schemas -include "PositionCovarianceType.fbs"; - namespace foxglove; +/// Type of position covariance +enum PositionCovarianceType : ubyte { + UNKNOWN = 0, + + APPROXIMATED = 1, + + DIAGONAL_KNOWN = 2, + + KNOWN = 3, +} /// A navigation satellite fix for any Global Navigation Satellite System table LocationFix { /// Latitude in degrees diff --git a/schemas/flatbuffers/Log.fbs b/schemas/flatbuffers/Log.fbs index 063fd0c..d1f2f19 100644 --- a/schemas/flatbuffers/Log.fbs +++ b/schemas/flatbuffers/Log.fbs @@ -1,10 +1,23 @@ // Generated by https://github.com/foxglove/schemas -include "LogLevel.fbs"; include "Time.fbs"; namespace foxglove; +/// Log level +enum LogLevel : ubyte { + UNKNOWN = 0, + + DEBUG = 1, + + INFO = 2, + + WARNING = 3, + + ERROR = 4, + + FATAL = 5, +} /// A log message table Log { /// Timestamp of log message diff --git a/schemas/flatbuffers/LogLevel.fbs b/schemas/flatbuffers/LogLevel.fbs deleted file mode 100644 index 687dd76..0000000 --- a/schemas/flatbuffers/LogLevel.fbs +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// Log level -enum LogLevel : ubyte { - UNKNOWN = 0, - - DEBUG = 1, - - INFO = 2, - - WARNING = 3, - - ERROR = 4, - - FATAL = 5, -} - diff --git a/schemas/flatbuffers/NumericType.fbs b/schemas/flatbuffers/NumericType.fbs deleted file mode 100644 index b48eb47..0000000 --- a/schemas/flatbuffers/NumericType.fbs +++ /dev/null @@ -1,25 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// Numeric type -enum NumericType : ubyte { - UNKNOWN = 0, - - UINT8 = 1, - - INT8 = 2, - - UINT16 = 3, - - INT16 = 4, - - UINT32 = 5, - - INT32 = 6, - - FLOAT32 = 7, - - FLOAT64 = 8, -} - diff --git a/schemas/flatbuffers/PackedElementField.fbs b/schemas/flatbuffers/PackedElementField.fbs index 1262169..a25f5a9 100644 --- a/schemas/flatbuffers/PackedElementField.fbs +++ b/schemas/flatbuffers/PackedElementField.fbs @@ -1,9 +1,27 @@ // Generated by https://github.com/foxglove/schemas -include "NumericType.fbs"; - namespace foxglove; +/// Numeric type +enum NumericType : ubyte { + UNKNOWN = 0, + + UINT8 = 1, + + INT8 = 2, + + UINT16 = 3, + + INT16 = 4, + + UINT32 = 5, + + INT32 = 6, + + FLOAT32 = 7, + + FLOAT64 = 8, +} /// A field present within each element in a byte array of packed elements. table PackedElementField { /// Name of the field diff --git a/schemas/flatbuffers/PointsAnnotation.fbs b/schemas/flatbuffers/PointsAnnotation.fbs index ca0fbf8..883ddfe 100644 --- a/schemas/flatbuffers/PointsAnnotation.fbs +++ b/schemas/flatbuffers/PointsAnnotation.fbs @@ -2,11 +2,22 @@ include "Color.fbs"; include "Point2.fbs"; -include "PointsAnnotationType.fbs"; include "Time.fbs"; namespace foxglove; +/// Type of points annotation +enum PointsAnnotationType : ubyte { + UNKNOWN = 0, + + POINTS = 1, + + LINE_LOOP = 2, + + LINE_STRIP = 3, + + LINE_LIST = 4, +} /// An array of points on a 2D image table PointsAnnotation { /// Timestamp of annotation diff --git a/schemas/flatbuffers/PointsAnnotationType.fbs b/schemas/flatbuffers/PointsAnnotationType.fbs deleted file mode 100644 index ff1d101..0000000 --- a/schemas/flatbuffers/PointsAnnotationType.fbs +++ /dev/null @@ -1,17 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// Type of points annotation -enum PointsAnnotationType : ubyte { - UNKNOWN = 0, - - POINTS = 1, - - LINE_LOOP = 2, - - LINE_STRIP = 3, - - LINE_LIST = 4, -} - diff --git a/schemas/flatbuffers/PositionCovarianceType.fbs b/schemas/flatbuffers/PositionCovarianceType.fbs deleted file mode 100644 index ec8e02a..0000000 --- a/schemas/flatbuffers/PositionCovarianceType.fbs +++ /dev/null @@ -1,15 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// Type of position covariance -enum PositionCovarianceType : ubyte { - UNKNOWN = 0, - - APPROXIMATED = 1, - - DIAGONAL_KNOWN = 2, - - KNOWN = 3, -} - diff --git a/schemas/flatbuffers/SceneEntityDeletion.fbs b/schemas/flatbuffers/SceneEntityDeletion.fbs index e452126..8cec716 100644 --- a/schemas/flatbuffers/SceneEntityDeletion.fbs +++ b/schemas/flatbuffers/SceneEntityDeletion.fbs @@ -1,10 +1,17 @@ // Generated by https://github.com/foxglove/schemas -include "SceneEntityDeletionType.fbs"; include "Time.fbs"; namespace foxglove; +/// An enumeration indicating which entities should match a SceneEntityDeletion command +enum SceneEntityDeletionType : ubyte { + /// Delete the existing entity on the same topic that has the provided `id` + MATCHING_ID = 0, + + /// Delete all existing entities on the same topic + ALL = 1, +} /// Command to remove previously published entities table SceneEntityDeletion { /// Timestamp of the deletion. Only matching entities earlier than this timestamp will be deleted. diff --git a/schemas/flatbuffers/SceneEntityDeletionType.fbs b/schemas/flatbuffers/SceneEntityDeletionType.fbs deleted file mode 100644 index 1d164f8..0000000 --- a/schemas/flatbuffers/SceneEntityDeletionType.fbs +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by https://github.com/foxglove/schemas - -namespace foxglove; - -/// An enumeration indicating which entities should match a SceneEntityDeletion command -enum SceneEntityDeletionType : ubyte { - /// Delete the existing entity on the same topic that has the provided `id` - MATCHING_ID = 0, - - /// Delete all existing entities on the same topic - ALL = 1, -} - diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index fc73cc9..e70005b 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -83,16 +83,15 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } await fs.writeFile(path.join(outDir, "flatbuffers", "ByteVector.fbs"), BYTE_VECTOR_FB); await fs.writeFile(path.join(outDir, "flatbuffers", "Time.fbs"), TIME_FB); await fs.writeFile(path.join(outDir, "flatbuffers", "Duration.fbs"), DURATION_FB); + for (const schema of Object.values(foxgloveMessageSchemas)) { - await fs.writeFile( - path.join(outDir, "flatbuffers", `${schema.name}.fbs`), - generateFlatbuffers(schema), + // want enums with their corresponding parent tables for usage + const enums = Object.values(foxgloveEnumSchemas).filter( + (enumSchema) => enumSchema.protobufParentMessageName === schema.name, ); - } - for (const schema of Object.values(foxgloveEnumSchemas)) { await fs.writeFile( path.join(outDir, "flatbuffers", `${schema.name}.fbs`), - generateFlatbuffers(schema), + generateFlatbuffers(schema, enums), ); } }); From 45fc71a114fe3cfde8201e8292bb93d5143a91ca Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 17 Nov 2022 00:07:23 +0100 Subject: [PATCH 11/15] - schemas/flatbuffer instead of schemas/flatbuffers --- .github/workflows/ci.yml | 2 +- ...fers.test.ts => generateFlatbufferSchema.test.ts} | 2 +- ...ateFlatbuffers.ts => generateFlatbufferSchema.ts} | 0 .../{flatbuffers => flatbuffer}/ArrowPrimitive.fbs | 0 schemas/{flatbuffers => flatbuffer}/ByteVector.fbs | 0 .../CameraCalibration.fbs | 0 .../{flatbuffers => flatbuffer}/CircleAnnotation.fbs | 0 schemas/{flatbuffers => flatbuffer}/Color.fbs | 0 .../{flatbuffers => flatbuffer}/CompressedImage.fbs | 0 .../{flatbuffers => flatbuffer}/CubePrimitive.fbs | 0 .../CylinderPrimitive.fbs | 0 schemas/{flatbuffers => flatbuffer}/Duration.fbs | 0 .../{flatbuffers => flatbuffer}/FrameTransform.fbs | 0 schemas/{flatbuffers => flatbuffer}/GeoJSON.fbs | 0 schemas/{flatbuffers => flatbuffer}/Grid.fbs | 0 .../{flatbuffers => flatbuffer}/ImageAnnotations.fbs | 0 schemas/{flatbuffers => flatbuffer}/KeyValuePair.fbs | 0 schemas/{flatbuffers => flatbuffer}/LaserScan.fbs | 0 .../{flatbuffers => flatbuffer}/LinePrimitive.fbs | 0 schemas/{flatbuffers => flatbuffer}/LocationFix.fbs | 0 schemas/{flatbuffers => flatbuffer}/Log.fbs | 0 .../{flatbuffers => flatbuffer}/ModelPrimitive.fbs | 0 .../PackedElementField.fbs | 0 schemas/{flatbuffers => flatbuffer}/Point2.fbs | 0 schemas/{flatbuffers => flatbuffer}/Point3.fbs | 0 schemas/{flatbuffers => flatbuffer}/PointCloud.fbs | 0 .../{flatbuffers => flatbuffer}/PointsAnnotation.fbs | 0 schemas/{flatbuffers => flatbuffer}/Pose.fbs | 0 schemas/{flatbuffers => flatbuffer}/PoseInFrame.fbs | 0 schemas/{flatbuffers => flatbuffer}/PosesInFrame.fbs | 0 schemas/{flatbuffers => flatbuffer}/Quaternion.fbs | 0 schemas/{flatbuffers => flatbuffer}/RawImage.fbs | 0 schemas/{flatbuffers => flatbuffer}/SceneEntity.fbs | 0 .../SceneEntityDeletion.fbs | 0 schemas/{flatbuffers => flatbuffer}/SceneUpdate.fbs | 0 .../{flatbuffers => flatbuffer}/SpherePrimitive.fbs | 0 .../{flatbuffers => flatbuffer}/TextPrimitive.fbs | 0 schemas/{flatbuffers => flatbuffer}/Time.fbs | 0 .../TriangleListPrimitive.fbs | 0 schemas/{flatbuffers => flatbuffer}/Vector2.fbs | 0 schemas/{flatbuffers => flatbuffer}/Vector3.fbs | 0 scripts/updateGeneratedFiles.ts | 12 ++++++------ 42 files changed, 8 insertions(+), 8 deletions(-) rename internal/{generateFlatbuffers.test.ts => generateFlatbufferSchema.test.ts} (97%) rename internal/{generateFlatbuffers.ts => generateFlatbufferSchema.ts} (100%) rename schemas/{flatbuffers => flatbuffer}/ArrowPrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/ByteVector.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/CameraCalibration.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/CircleAnnotation.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Color.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/CompressedImage.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/CubePrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/CylinderPrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Duration.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/FrameTransform.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/GeoJSON.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Grid.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/ImageAnnotations.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/KeyValuePair.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/LaserScan.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/LinePrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/LocationFix.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Log.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/ModelPrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/PackedElementField.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Point2.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Point3.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/PointCloud.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/PointsAnnotation.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Pose.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/PoseInFrame.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/PosesInFrame.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Quaternion.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/RawImage.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/SceneEntity.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/SceneEntityDeletion.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/SceneUpdate.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/SpherePrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/TextPrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Time.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/TriangleListPrimitive.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Vector2.fbs (100%) rename schemas/{flatbuffers => flatbuffer}/Vector3.fbs (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e2f7dc..6134a46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip echo "0821af82a3a736b0ba9235c02219df24d1f042dd Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c unzip Linux.flatc.binary.clang++-12.zip - ./flatc --ts -o /dev/null schemas/flatbuffers/*.fbs + ./flatc --ts -o /dev/null schemas/flatbuffer/*.fbs - name: Validate protobuf definitions run: protoc --proto_path=schemas/proto schemas/proto/**/*.proto --descriptor_set_out=/dev/null diff --git a/internal/generateFlatbuffers.test.ts b/internal/generateFlatbufferSchema.test.ts similarity index 97% rename from internal/generateFlatbuffers.test.ts rename to internal/generateFlatbufferSchema.test.ts index 86fc8cf..81e4dd2 100644 --- a/internal/generateFlatbuffers.test.ts +++ b/internal/generateFlatbufferSchema.test.ts @@ -1,4 +1,4 @@ -import { generateFlatbuffers } from "./generateFlatbuffers"; +import { generateFlatbuffers } from "./generateFlatbufferSchema"; import { exampleEnum, exampleMessage } from "./testFixtures"; describe("generateFlatBuffer", () => { diff --git a/internal/generateFlatbuffers.ts b/internal/generateFlatbufferSchema.ts similarity index 100% rename from internal/generateFlatbuffers.ts rename to internal/generateFlatbufferSchema.ts diff --git a/schemas/flatbuffers/ArrowPrimitive.fbs b/schemas/flatbuffer/ArrowPrimitive.fbs similarity index 100% rename from schemas/flatbuffers/ArrowPrimitive.fbs rename to schemas/flatbuffer/ArrowPrimitive.fbs diff --git a/schemas/flatbuffers/ByteVector.fbs b/schemas/flatbuffer/ByteVector.fbs similarity index 100% rename from schemas/flatbuffers/ByteVector.fbs rename to schemas/flatbuffer/ByteVector.fbs diff --git a/schemas/flatbuffers/CameraCalibration.fbs b/schemas/flatbuffer/CameraCalibration.fbs similarity index 100% rename from schemas/flatbuffers/CameraCalibration.fbs rename to schemas/flatbuffer/CameraCalibration.fbs diff --git a/schemas/flatbuffers/CircleAnnotation.fbs b/schemas/flatbuffer/CircleAnnotation.fbs similarity index 100% rename from schemas/flatbuffers/CircleAnnotation.fbs rename to schemas/flatbuffer/CircleAnnotation.fbs diff --git a/schemas/flatbuffers/Color.fbs b/schemas/flatbuffer/Color.fbs similarity index 100% rename from schemas/flatbuffers/Color.fbs rename to schemas/flatbuffer/Color.fbs diff --git a/schemas/flatbuffers/CompressedImage.fbs b/schemas/flatbuffer/CompressedImage.fbs similarity index 100% rename from schemas/flatbuffers/CompressedImage.fbs rename to schemas/flatbuffer/CompressedImage.fbs diff --git a/schemas/flatbuffers/CubePrimitive.fbs b/schemas/flatbuffer/CubePrimitive.fbs similarity index 100% rename from schemas/flatbuffers/CubePrimitive.fbs rename to schemas/flatbuffer/CubePrimitive.fbs diff --git a/schemas/flatbuffers/CylinderPrimitive.fbs b/schemas/flatbuffer/CylinderPrimitive.fbs similarity index 100% rename from schemas/flatbuffers/CylinderPrimitive.fbs rename to schemas/flatbuffer/CylinderPrimitive.fbs diff --git a/schemas/flatbuffers/Duration.fbs b/schemas/flatbuffer/Duration.fbs similarity index 100% rename from schemas/flatbuffers/Duration.fbs rename to schemas/flatbuffer/Duration.fbs diff --git a/schemas/flatbuffers/FrameTransform.fbs b/schemas/flatbuffer/FrameTransform.fbs similarity index 100% rename from schemas/flatbuffers/FrameTransform.fbs rename to schemas/flatbuffer/FrameTransform.fbs diff --git a/schemas/flatbuffers/GeoJSON.fbs b/schemas/flatbuffer/GeoJSON.fbs similarity index 100% rename from schemas/flatbuffers/GeoJSON.fbs rename to schemas/flatbuffer/GeoJSON.fbs diff --git a/schemas/flatbuffers/Grid.fbs b/schemas/flatbuffer/Grid.fbs similarity index 100% rename from schemas/flatbuffers/Grid.fbs rename to schemas/flatbuffer/Grid.fbs diff --git a/schemas/flatbuffers/ImageAnnotations.fbs b/schemas/flatbuffer/ImageAnnotations.fbs similarity index 100% rename from schemas/flatbuffers/ImageAnnotations.fbs rename to schemas/flatbuffer/ImageAnnotations.fbs diff --git a/schemas/flatbuffers/KeyValuePair.fbs b/schemas/flatbuffer/KeyValuePair.fbs similarity index 100% rename from schemas/flatbuffers/KeyValuePair.fbs rename to schemas/flatbuffer/KeyValuePair.fbs diff --git a/schemas/flatbuffers/LaserScan.fbs b/schemas/flatbuffer/LaserScan.fbs similarity index 100% rename from schemas/flatbuffers/LaserScan.fbs rename to schemas/flatbuffer/LaserScan.fbs diff --git a/schemas/flatbuffers/LinePrimitive.fbs b/schemas/flatbuffer/LinePrimitive.fbs similarity index 100% rename from schemas/flatbuffers/LinePrimitive.fbs rename to schemas/flatbuffer/LinePrimitive.fbs diff --git a/schemas/flatbuffers/LocationFix.fbs b/schemas/flatbuffer/LocationFix.fbs similarity index 100% rename from schemas/flatbuffers/LocationFix.fbs rename to schemas/flatbuffer/LocationFix.fbs diff --git a/schemas/flatbuffers/Log.fbs b/schemas/flatbuffer/Log.fbs similarity index 100% rename from schemas/flatbuffers/Log.fbs rename to schemas/flatbuffer/Log.fbs diff --git a/schemas/flatbuffers/ModelPrimitive.fbs b/schemas/flatbuffer/ModelPrimitive.fbs similarity index 100% rename from schemas/flatbuffers/ModelPrimitive.fbs rename to schemas/flatbuffer/ModelPrimitive.fbs diff --git a/schemas/flatbuffers/PackedElementField.fbs b/schemas/flatbuffer/PackedElementField.fbs similarity index 100% rename from schemas/flatbuffers/PackedElementField.fbs rename to schemas/flatbuffer/PackedElementField.fbs diff --git a/schemas/flatbuffers/Point2.fbs b/schemas/flatbuffer/Point2.fbs similarity index 100% rename from schemas/flatbuffers/Point2.fbs rename to schemas/flatbuffer/Point2.fbs diff --git a/schemas/flatbuffers/Point3.fbs b/schemas/flatbuffer/Point3.fbs similarity index 100% rename from schemas/flatbuffers/Point3.fbs rename to schemas/flatbuffer/Point3.fbs diff --git a/schemas/flatbuffers/PointCloud.fbs b/schemas/flatbuffer/PointCloud.fbs similarity index 100% rename from schemas/flatbuffers/PointCloud.fbs rename to schemas/flatbuffer/PointCloud.fbs diff --git a/schemas/flatbuffers/PointsAnnotation.fbs b/schemas/flatbuffer/PointsAnnotation.fbs similarity index 100% rename from schemas/flatbuffers/PointsAnnotation.fbs rename to schemas/flatbuffer/PointsAnnotation.fbs diff --git a/schemas/flatbuffers/Pose.fbs b/schemas/flatbuffer/Pose.fbs similarity index 100% rename from schemas/flatbuffers/Pose.fbs rename to schemas/flatbuffer/Pose.fbs diff --git a/schemas/flatbuffers/PoseInFrame.fbs b/schemas/flatbuffer/PoseInFrame.fbs similarity index 100% rename from schemas/flatbuffers/PoseInFrame.fbs rename to schemas/flatbuffer/PoseInFrame.fbs diff --git a/schemas/flatbuffers/PosesInFrame.fbs b/schemas/flatbuffer/PosesInFrame.fbs similarity index 100% rename from schemas/flatbuffers/PosesInFrame.fbs rename to schemas/flatbuffer/PosesInFrame.fbs diff --git a/schemas/flatbuffers/Quaternion.fbs b/schemas/flatbuffer/Quaternion.fbs similarity index 100% rename from schemas/flatbuffers/Quaternion.fbs rename to schemas/flatbuffer/Quaternion.fbs diff --git a/schemas/flatbuffers/RawImage.fbs b/schemas/flatbuffer/RawImage.fbs similarity index 100% rename from schemas/flatbuffers/RawImage.fbs rename to schemas/flatbuffer/RawImage.fbs diff --git a/schemas/flatbuffers/SceneEntity.fbs b/schemas/flatbuffer/SceneEntity.fbs similarity index 100% rename from schemas/flatbuffers/SceneEntity.fbs rename to schemas/flatbuffer/SceneEntity.fbs diff --git a/schemas/flatbuffers/SceneEntityDeletion.fbs b/schemas/flatbuffer/SceneEntityDeletion.fbs similarity index 100% rename from schemas/flatbuffers/SceneEntityDeletion.fbs rename to schemas/flatbuffer/SceneEntityDeletion.fbs diff --git a/schemas/flatbuffers/SceneUpdate.fbs b/schemas/flatbuffer/SceneUpdate.fbs similarity index 100% rename from schemas/flatbuffers/SceneUpdate.fbs rename to schemas/flatbuffer/SceneUpdate.fbs diff --git a/schemas/flatbuffers/SpherePrimitive.fbs b/schemas/flatbuffer/SpherePrimitive.fbs similarity index 100% rename from schemas/flatbuffers/SpherePrimitive.fbs rename to schemas/flatbuffer/SpherePrimitive.fbs diff --git a/schemas/flatbuffers/TextPrimitive.fbs b/schemas/flatbuffer/TextPrimitive.fbs similarity index 100% rename from schemas/flatbuffers/TextPrimitive.fbs rename to schemas/flatbuffer/TextPrimitive.fbs diff --git a/schemas/flatbuffers/Time.fbs b/schemas/flatbuffer/Time.fbs similarity index 100% rename from schemas/flatbuffers/Time.fbs rename to schemas/flatbuffer/Time.fbs diff --git a/schemas/flatbuffers/TriangleListPrimitive.fbs b/schemas/flatbuffer/TriangleListPrimitive.fbs similarity index 100% rename from schemas/flatbuffers/TriangleListPrimitive.fbs rename to schemas/flatbuffer/TriangleListPrimitive.fbs diff --git a/schemas/flatbuffers/Vector2.fbs b/schemas/flatbuffer/Vector2.fbs similarity index 100% rename from schemas/flatbuffers/Vector2.fbs rename to schemas/flatbuffer/Vector2.fbs diff --git a/schemas/flatbuffers/Vector3.fbs b/schemas/flatbuffer/Vector3.fbs similarity index 100% rename from schemas/flatbuffers/Vector3.fbs rename to schemas/flatbuffer/Vector3.fbs diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index e70005b..b87ad12 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -10,7 +10,7 @@ import { DURATION_FB, generateFlatbuffers, TIME_FB, -} from "../internal/generateFlatbuffers"; +} from "../internal/generateFlatbufferSchema"; import { generateJsonSchema } from "../internal/generateJsonSchema"; import { generateMarkdown } from "../internal/generateMarkdown"; import { generateProto } from "../internal/generateProto"; @@ -79,10 +79,10 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } }); await logProgress("Generating FlatBuffer definitions", async () => { - await fs.mkdir(path.join(outDir, "flatbuffers"), { recursive: true }); - await fs.writeFile(path.join(outDir, "flatbuffers", "ByteVector.fbs"), BYTE_VECTOR_FB); - await fs.writeFile(path.join(outDir, "flatbuffers", "Time.fbs"), TIME_FB); - await fs.writeFile(path.join(outDir, "flatbuffers", "Duration.fbs"), DURATION_FB); + await fs.mkdir(path.join(outDir, "flatbuffer"), { recursive: true }); + await fs.writeFile(path.join(outDir, "flatbuffer", "ByteVector.fbs"), BYTE_VECTOR_FB); + await fs.writeFile(path.join(outDir, "flatbuffer", "Time.fbs"), TIME_FB); + await fs.writeFile(path.join(outDir, "flatbuffer", "Duration.fbs"), DURATION_FB); for (const schema of Object.values(foxgloveMessageSchemas)) { // want enums with their corresponding parent tables for usage @@ -90,7 +90,7 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } (enumSchema) => enumSchema.protobufParentMessageName === schema.name, ); await fs.writeFile( - path.join(outDir, "flatbuffers", `${schema.name}.fbs`), + path.join(outDir, "flatbuffer", `${schema.name}.fbs`), generateFlatbuffers(schema, enums), ); } From 3909e089dd515f57cc6b8eb182890d813708ec17 Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 17 Nov 2022 00:19:31 +0100 Subject: [PATCH 12/15] - update ci with logic to detect flatc errors --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6134a46..b227ba8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,12 @@ jobs: curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip echo "0821af82a3a736b0ba9235c02219df24d1f042dd Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c unzip Linux.flatc.binary.clang++-12.zip - ./flatc --ts -o /dev/null schemas/flatbuffer/*.fbs + output=$(./flatc --ts -o /dev/null ./schemas/flatbuffer/*.fbs) + if [ -n "$output" ]; then + echo "::error::Flatbuffer schema compilation had warnings or errors. Fix them to proceed:" + echo "$output" + exit 1 + fi - name: Validate protobuf definitions run: protoc --proto_path=schemas/proto schemas/proto/**/*.proto --descriptor_set_out=/dev/null From 3a6a8a57a3f06d1649c5c87868639e3ea42ad8cc Mon Sep 17 00:00:00 2001 From: snosenzo Date: Thu, 17 Nov 2022 16:38:08 +0100 Subject: [PATCH 13/15] -merge main --- schemas/flatbuffer/CameraCalibration.fbs | 4 +++- schemas/flatbuffer/CompressedImage.fbs | 2 ++ schemas/flatbuffer/RawImage.fbs | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/schemas/flatbuffer/CameraCalibration.fbs b/schemas/flatbuffer/CameraCalibration.fbs index a889174..18d76d9 100644 --- a/schemas/flatbuffer/CameraCalibration.fbs +++ b/schemas/flatbuffer/CameraCalibration.fbs @@ -19,6 +19,8 @@ table CameraCalibration { height:uint32; /// Name of distortion model + /// + /// Supported values: `plumb_bob` and `rational_polynomial` distortion_model:string; /// Distortion parameters @@ -38,7 +40,7 @@ table CameraCalibration { /// length 9 k:[double]; - /// Rectification matrix (3x3 row-major matrix) + /// Rectification matrix (stereo cameras only, 3x3 row-major matrix) /// /// A rotation matrix aligning the camera coordinate system to the ideal stereo image plane so that epipolar lines in both stereo images are parallel. /// length 9 diff --git a/schemas/flatbuffer/CompressedImage.fbs b/schemas/flatbuffer/CompressedImage.fbs index e5a033f..f22b81d 100644 --- a/schemas/flatbuffer/CompressedImage.fbs +++ b/schemas/flatbuffer/CompressedImage.fbs @@ -16,6 +16,8 @@ table CompressedImage { data:[uint8]; /// Image format + /// + /// Supported values: `webp`, `jpeg`, `png` format:string; } diff --git a/schemas/flatbuffer/RawImage.fbs b/schemas/flatbuffer/RawImage.fbs index 000fe90..686cc26 100644 --- a/schemas/flatbuffer/RawImage.fbs +++ b/schemas/flatbuffer/RawImage.fbs @@ -19,6 +19,8 @@ table RawImage { height:uint32; /// Encoding of the raw image data + /// + /// Supported values: `8UC1`, `8UC3`, `16UC1`, `32FC1`, `bayer_bggr8`, `bayer_gbrg8`, `bayer_grbg8`, `bayer_rggb8`, `bgr8`, `bgra8`, `mono8`, `mono16`, `rgb8`, `rgba8`, `yuv422` encoding:string; /// Byte length of a single row From fa625ec2dd42054b7e465524b62956ff43060a58 Mon Sep 17 00:00:00 2001 From: snosenzo Date: Mon, 21 Nov 2022 12:34:12 -0500 Subject: [PATCH 14/15] - address feedback --- internal/generateFlatbufferSchema.test.ts | 12 ++++---- internal/generateFlatbufferSchema.ts | 34 +++++++++++++++++++---- internal/generateProto.test.ts | 2 +- internal/schemas.test.ts | 2 +- internal/schemas.ts | 32 ++++++++++----------- internal/testFixtures.ts | 14 ++++++++-- internal/types.ts | 4 +-- schemas/flatbuffer/Duration.fbs | 2 +- schemas/flatbuffer/Time.fbs | 4 +-- scripts/updateGeneratedFiles.ts | 4 +-- 10 files changed, 72 insertions(+), 38 deletions(-) diff --git a/internal/generateFlatbufferSchema.test.ts b/internal/generateFlatbufferSchema.test.ts index 81e4dd2..e1fddef 100644 --- a/internal/generateFlatbufferSchema.test.ts +++ b/internal/generateFlatbufferSchema.test.ts @@ -24,25 +24,25 @@ describe("generateFlatBuffer", () => { /// An example type table ExampleMessage { /// duration field - field_duration:Duration = 1; + field_duration:Duration; /// time field - field_time:Time = 1; + field_time:Time; /// boolean field field_boolean:bool = true; /// bytes field - field_bytes:[uint8] = 1; + field_bytes:[uint8]; /// float64 field - field_float64:double = 1; + field_float64:double = 1.0; /// uint32 field - field_uint32:uint32 = 1; + field_uint32:uint32 = 5; /// string field - field_string:string = 1; + field_string:string = "string-type"; /// duration array field field_duration_array:[Duration]; diff --git a/internal/generateFlatbufferSchema.ts b/internal/generateFlatbufferSchema.ts index 183996d..149ea49 100644 --- a/internal/generateFlatbufferSchema.ts +++ b/internal/generateFlatbufferSchema.ts @@ -16,8 +16,8 @@ export const TIME_FB = ` namespace foxglove; struct Time { - /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z - sec:uint64; + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint32; /// Nano-second fractions from 0 to 999,999,999 inclusive nsec:uint32; } @@ -28,7 +28,7 @@ namespace foxglove; struct Duration { /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. - sec:int64; + sec:int32; /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 nsec:int32; @@ -124,8 +124,32 @@ export function generateFlatbuffers( lengthComment = ` /// length ${field.array}\n`; } let defaultValue; - if (field.defaultValue != undefined) { - defaultValue = field.defaultValue; + if (field.defaultValue != undefined && !isArray) { + if ( + field.type.type === "primitive" && + !(field.type.name === "duration" || field.type.name === "time") + ) { + if (typeof field.defaultValue === "string") { + defaultValue = `"${field.defaultValue}"`; + } else if (typeof field.defaultValue === "number") { + if (Number.isInteger(field.defaultValue) && field.type.name === "float64") { + // if it is a floating point number that is an integer, we need to add a decimal point + defaultValue = `${field.defaultValue}.0`; + } else { + defaultValue = field.defaultValue.toString(); + } + } else if (typeof field.defaultValue === "boolean") { + // uses same 'false'/'true' as js + defaultValue = field.defaultValue.toString(); + } + } else if (field.type.type === "enum") { + // default enums are just the enum string of the enum and don't require other formatting + // ie: type numericType: NumericType = INT32; + defaultValue = field.defaultValue as string; + } + } + if (field.defaultValue != undefined && defaultValue == undefined) { + throw new Error("Flatbuffers does not support non-scalar default values"); } return `${field.description diff --git a/internal/generateProto.test.ts b/internal/generateProto.test.ts index dbcecdf..79b5555 100644 --- a/internal/generateProto.test.ts +++ b/internal/generateProto.test.ts @@ -117,7 +117,7 @@ describe("generateProto", () => { root.addJSON(protobufjs.common.get("google/protobuf/duration.proto")!.nested!); for (const schema of Object.values(foxgloveMessageSchemas)) { const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + (enumSchema) => enumSchema.parentSchemaName === schema.name, ); root.add(protobufjs.parse(generateProto(schema, enums)).root); } diff --git a/internal/schemas.test.ts b/internal/schemas.test.ts index 99172dd..90c3d1b 100644 --- a/internal/schemas.test.ts +++ b/internal/schemas.test.ts @@ -8,7 +8,7 @@ describe("schemas", () => { } for (const [key, value] of Object.entries(foxgloveEnumSchemas)) { expect(key).toEqual(value.name); - expect(value.protobufParentMessageName in foxgloveMessageSchemas).toBe(true); + expect(value.parentSchemaName in foxgloveMessageSchemas).toBe(true); } }); diff --git a/internal/schemas.ts b/internal/schemas.ts index 1b0971f..edded04 100644 --- a/internal/schemas.ts +++ b/internal/schemas.ts @@ -9,25 +9,25 @@ const Color: FoxgloveMessageSchema = { name: "r", type: { type: "primitive", name: "float64" }, description: "Red value between 0 and 1", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "g", type: { type: "primitive", name: "float64" }, description: "Green value between 0 and 1", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "b", type: { type: "primitive", name: "float64" }, description: "Blue value between 0 and 1", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "a", type: { type: "primitive", name: "float64" }, description: "Alpha value between 0 and 1", - defaultValue: "1.0", + defaultValue: 1.0, }, ], }; @@ -41,13 +41,13 @@ const Vector2: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", - defaultValue: "1.0", + defaultValue: 1.0, }, ], }; @@ -62,19 +62,19 @@ const Vector3: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", - defaultValue: "1.0", + defaultValue: 1.0, }, { name: "z", type: { type: "primitive", name: "float64" }, description: "z coordinate length", - defaultValue: "1.0", + defaultValue: 1.0, }, ], }; @@ -146,7 +146,7 @@ const Quaternion: FoxgloveMessageSchema = { name: "w", type: { type: "primitive", name: "float64" }, description: "w value", - defaultValue: "1.0", + defaultValue: 1.0, }, ], }; @@ -191,7 +191,7 @@ const KeyValuePair: FoxgloveMessageSchema = { const SceneEntityDeletionType: FoxgloveEnumSchema = { type: "enum", name: "SceneEntityDeletionType", - protobufParentMessageName: "SceneEntityDeletion", + parentSchemaName: "SceneEntityDeletion", protobufEnumName: "Type", description: "An enumeration indicating which entities should match a SceneEntityDeletion command", @@ -353,7 +353,7 @@ const CylinderPrimitive: FoxgloveMessageSchema = { const LineType: FoxgloveEnumSchema = { type: "enum", name: "LineType", - protobufParentMessageName: "LinePrimitive", + parentSchemaName: "LinePrimitive", protobufEnumName: "Type", description: "An enumeration indicating how input points should be interpreted to create lines", values: [ @@ -929,7 +929,7 @@ const NumericType: FoxgloveEnumSchema = { type: "enum", name: "NumericType", description: "Numeric type", - protobufParentMessageName: "PackedElementField", + parentSchemaName: "PackedElementField", protobufEnumName: "NumericType", values: [ { name: "UNKNOWN", value: 0 }, @@ -1064,7 +1064,7 @@ const PointsAnnotationType: FoxgloveEnumSchema = { type: "enum", name: "PointsAnnotationType", description: "Type of points annotation", - protobufParentMessageName: "PointsAnnotation", + parentSchemaName: "PointsAnnotation", protobufEnumName: "Type", values: [ { name: "UNKNOWN", value: 0 }, @@ -1145,7 +1145,7 @@ const PositionCovarianceType: FoxgloveEnumSchema = { type: "enum", name: "PositionCovarianceType", description: "Type of position covariance", - protobufParentMessageName: "LocationFix", + parentSchemaName: "LocationFix", protobufEnumName: "PositionCovarianceType", values: [ { name: "UNKNOWN", value: 0 }, @@ -1195,7 +1195,7 @@ const LogLevel: FoxgloveEnumSchema = { type: "enum", name: "LogLevel", description: "Log level", - protobufParentMessageName: "Log", + parentSchemaName: "Log", protobufEnumName: "Level", values: [ { name: "UNKNOWN", value: 0 }, diff --git a/internal/testFixtures.ts b/internal/testFixtures.ts index 10f6103..cf949a2 100644 --- a/internal/testFixtures.ts +++ b/internal/testFixtures.ts @@ -14,7 +14,7 @@ export const exampleEnum: FoxgloveEnumSchema = { type: "enum", name: "ExampleEnum", protobufEnumName: "ExampleProtoEnum", - protobufParentMessageName: "ExampleMessage", + parentSchemaName: "ExampleMessage", description: "An example enum", values: [ { name: "A", value: 1, description: "Value A" }, @@ -44,7 +44,17 @@ export const exampleMessage: FoxgloveMessageSchema = { name: `field_${name}`, description: `${name} field`, type: { type: "primitive", name }, - defaultValue: name === "boolean" ? "true" : "1", + defaultValue: + name === "boolean" + ? true + : name === "string" + ? "string-type" + : name === "uint32" + ? 5 + : name === "float64" + ? 1.0 + : // time and duration and bytes + undefined, })), ...allPrimitives.map((name): FoxgloveMessageSchema["fields"][0] => ({ name: `field_${name}_array`, diff --git a/internal/types.ts b/internal/types.ts index 4b1e07f..73f7e86 100644 --- a/internal/types.ts +++ b/internal/types.ts @@ -11,7 +11,7 @@ export type FoxgloveEnumSchema = { type: "enum"; name: string; description: string; - protobufParentMessageName: string; + parentSchemaName: string; protobufEnumName: string; values: ReadonlyArray<{ value: number; @@ -30,7 +30,7 @@ export type FoxgloveMessageField = { required?: true; description: string; protobufFieldNumber?: number; - defaultValue?: string; + defaultValue?: string | number | boolean; }; export type FoxgloveMessageSchema = { diff --git a/schemas/flatbuffer/Duration.fbs b/schemas/flatbuffer/Duration.fbs index cb6b595..72c0a02 100644 --- a/schemas/flatbuffer/Duration.fbs +++ b/schemas/flatbuffer/Duration.fbs @@ -3,7 +3,7 @@ namespace foxglove; struct Duration { /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. - sec:int64; + sec:int32; /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 nsec:int32; diff --git a/schemas/flatbuffer/Time.fbs b/schemas/flatbuffer/Time.fbs index 09b5c3b..6bfc35e 100644 --- a/schemas/flatbuffer/Time.fbs +++ b/schemas/flatbuffer/Time.fbs @@ -2,8 +2,8 @@ namespace foxglove; struct Time { - /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z - sec:uint64; + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint32; /// Nano-second fractions from 0 to 999,999,999 inclusive nsec:uint32; } diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index b87ad12..a905aa2 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -69,7 +69,7 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } await fs.mkdir(path.join(outDir, "proto", "foxglove"), { recursive: true }); for (const schema of Object.values(foxgloveMessageSchemas)) { const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + (enumSchema) => enumSchema.parentSchemaName === schema.name, ); await fs.writeFile( path.join(outDir, "proto", "foxglove", `${schema.name}.proto`), @@ -87,7 +87,7 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } for (const schema of Object.values(foxgloveMessageSchemas)) { // want enums with their corresponding parent tables for usage const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + (enumSchema) => enumSchema.parentSchemaName === schema.name, ); await fs.writeFile( path.join(outDir, "flatbuffer", `${schema.name}.fbs`), From 141de2e7abdb9db4d04076e0785b8fe98acbe89f Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Mon, 21 Nov 2022 16:38:52 -0800 Subject: [PATCH 15/15] Update internal/generateFlatbufferSchema.test.ts --- internal/generateFlatbufferSchema.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/generateFlatbufferSchema.test.ts b/internal/generateFlatbufferSchema.test.ts index e1fddef..c9fa3fa 100644 --- a/internal/generateFlatbufferSchema.test.ts +++ b/internal/generateFlatbufferSchema.test.ts @@ -1,7 +1,7 @@ import { generateFlatbuffers } from "./generateFlatbufferSchema"; import { exampleEnum, exampleMessage } from "./testFixtures"; -describe("generateFlatBuffer", () => { +describe("generateFlatbuffers", () => { it("generates Message .fbs files", () => { expect(generateFlatbuffers(exampleMessage, [exampleEnum])).toMatchInlineSnapshot(` "// Generated by https://github.com/foxglove/schemas