Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add explicit field IDs to flatbuffer schemas #148

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Validate Flatbuffer definitions
run: |
output=$(flatc --ts -o /dev/null ./schemas/flatbuffer/*.fbs)
output=$(flatc --require-explicit-ids --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"
Expand Down
50 changes: 25 additions & 25 deletions internal/generateFlatbufferSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,91 +24,91 @@ describe("generateFlatbuffers", () => {
/// An example type
table ExampleMessage {
/// duration field
field_duration:Duration;
field_duration:Duration (id: 0);
/// time field
field_time:Time;
field_time:Time (id: 1);
/// boolean field
field_boolean:bool = true;
field_boolean:bool = true (id: 2);
/// bytes field
field_bytes:[uint8];
field_bytes:[uint8] (id: 3);
/// float64 field
field_float64:double = 1.0;
field_float64:double = 1.0 (id: 4);
/// uint32 field
field_uint32:uint32 = 5;
field_uint32:uint32 = 5 (id: 5);
/// string field
field_string:string = "string-type";
field_string:string = "string-type" (id: 6);
/// duration array field
field_duration_array:[Duration];
field_duration_array:[Duration] (id: 7);
/// time array field
field_time_array:[Time];
field_time_array:[Time] (id: 8);
/// boolean array field
field_boolean_array:[bool];
field_boolean_array:[bool] (id: 9);
/// bytes array field
field_bytes_array:[ByteVector];
field_bytes_array:[ByteVector] (id: 10);
/// float64 array field
field_float64_array:[double];
field_float64_array:[double] (id: 11);
/// uint32 array field
field_uint32_array:[uint32];
field_uint32_array:[uint32] (id: 12);
/// string array field
field_string_array:[string];
field_string_array:[string] (id: 13);
/// duration fixed-length array field
/// length 3
field_duration_fixed_array:[Duration];
field_duration_fixed_array:[Duration] (id: 14);
/// time fixed-length array field
/// length 3
field_time_fixed_array:[Time];
field_time_fixed_array:[Time] (id: 15);
/// boolean fixed-length array field
/// length 3
field_boolean_fixed_array:[bool];
field_boolean_fixed_array:[bool] (id: 16);
/// bytes fixed-length array field
/// length 3
field_bytes_fixed_array:[ByteVector];
field_bytes_fixed_array:[ByteVector] (id: 17);
/// float64 fixed-length array field
/// length 3
field_float64_fixed_array:[double];
field_float64_fixed_array:[double] (id: 18);
/// uint32 fixed-length array field
/// length 3
field_uint32_fixed_array:[uint32];
field_uint32_fixed_array:[uint32] (id: 19);
/// string fixed-length array field
/// length 3
field_string_fixed_array:[string];
field_string_fixed_array:[string] (id: 20);
/// An enum field
field_enum:ExampleEnum;
field_enum:ExampleEnum (id: 21);
/// An enum array field
field_enum_array:[ExampleEnum];
field_enum_array:[ExampleEnum] (id: 22);
/// A nested field
field_nested:foxglove.NestedMessage;
field_nested:foxglove.NestedMessage (id: 23);
/// A nested array field
/// With
/// a
/// very
/// long
/// description
field_nested_array:[foxglove.NestedMessage];
field_nested_array:[foxglove.NestedMessage] (id: 24);
}
root_type ExampleMessage;
Expand Down
8 changes: 4 additions & 4 deletions internal/generateFlatbufferSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace foxglove;
/// Used for nesting byte vectors
table ByteVector {
data:[uint8];
data:[uint8] (id: 0);
}
root_type ByteVector;
`;
Expand All @@ -29,7 +29,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:int32;
/// if sec === 0 : -999,999,999 <= nsec <= +999,999,999
/// 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;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export function generateFlatbuffers(
break;
}
case "message": {
const fields = schema.fields.map((field) => {
const fields = schema.fields.map((field, fieldId) => {
const isArray = field.array != undefined;

let type;
Expand Down Expand Up @@ -162,7 +162,7 @@ export function generateFlatbuffers(
// convert field.name to lowercase for flatbuffer compilation compliance
} ${field.name.toLowerCase()}:${isArray ? `[${type}]` : type}${
defaultValue ? ` = ${defaultValue}` : ""
};`;
} (id: ${fieldId});`;
});

definition = `${enumDefinitions.join("\n\n")}/// ${schema.description}\ntable ${
Expand Down
1 change: 1 addition & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif
generate-flatbuffer:
find foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer ! -name '__init__.py' -type f -exec rm -f {} +
pipenv run flatc \
--require-explicit-ids \
--python \
-o foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer \
../schemas/flatbuffer/*.fbs
Expand Down
12 changes: 6 additions & 6 deletions schemas/flatbuffer/ArrowPrimitive.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemas/flatbuffer/ByteVector.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions schemas/flatbuffer/CameraCalibration.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions schemas/flatbuffer/CircleAnnotation.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions schemas/flatbuffer/Color.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions schemas/flatbuffer/CompressedImage.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions schemas/flatbuffer/CompressedVideo.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions schemas/flatbuffer/CubePrimitive.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading