Skip to content

Commit

Permalink
Extra protobuf time/duration modifications so they can live in studio…
Browse files Browse the repository at this point in the history
… only
  • Loading branch information
jtbandes committed Sep 13, 2023
1 parent 7a583ca commit 5d89e9c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 196 deletions.
20 changes: 16 additions & 4 deletions typescript/support/src/parseChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ describe("parseChannel", () => {
});

it("works with protobuf", () => {
const processRootType = jest.fn().mockImplementation((x: unknown) => x);
const processMessageDefinitions = jest.fn().mockImplementation((x: unknown) => x);
const fds = FileDescriptorSet.encode(FileDescriptorSet.root.toDescriptor("proto3")).finish();
const channel = parseChannel({
messageEncoding: "protobuf",
schema: { name: "google.protobuf.FileDescriptorSet", encoding: "protobuf", data: fds },
});
const channel = parseChannel(
{
messageEncoding: "protobuf",
schema: { name: "google.protobuf.FileDescriptorSet", encoding: "protobuf", data: fds },
},
{
protobuf: {
processRootType,
processMessageDefinitions,
},
},
);
const deserialized = channel.deserialize(fds) as IFileDescriptorSet;
expect(deserialized.file[0]!.name).toEqual("google_protobuf.proto");
expect(processRootType).toHaveBeenCalled();
expect(processMessageDefinitions).toHaveBeenCalled();
});

it("works with ros1", () => {
Expand Down
10 changes: 7 additions & 3 deletions typescript/support/src/parseChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MessageReader as ROS2MessageReader } from "@foxglove/rosmsg2-serializat

import { parseFlatbufferSchema } from "./parseFlatbufferSchema";
import { parseJsonSchema } from "./parseJsonSchema";
import { parseProtobufSchema } from "./parseProtobufSchema";
import { ParseProtobufSchemaOptions, parseProtobufSchema } from "./parseProtobufSchema";
import { MessageDefinitionMap } from "./types";

type Channel = {
Expand Down Expand Up @@ -64,6 +64,10 @@ function parsedDefinitionsToDatatypes(
return datatypes;
}

export type ParseChannelOptions = {
protobuf?: ParseProtobufSchemaOptions;
};

/**
* Process a channel/schema and extract information that can be used to deserialize messages on the
* channel, and schemas in the format expected by Studio's RosDatatypes.
Expand All @@ -72,7 +76,7 @@ function parsedDefinitionsToDatatypes(
* - https://github.com/foxglove/mcap/blob/main/docs/specification/well-known-message-encodings.md
* - https://github.com/foxglove/mcap/blob/main/docs/specification/well-known-schema-encodings.md
*/
export function parseChannel(channel: Channel): ParsedChannel {
export function parseChannel(channel: Channel, options?: ParseChannelOptions): ParsedChannel {
if (channel.messageEncoding === "json") {
if (channel.schema != undefined && channel.schema.encoding !== "jsonschema") {
throw new Error(
Expand Down Expand Up @@ -126,7 +130,7 @@ export function parseChannel(channel: Channel): ParsedChannel {
} is not supported (expected protobuf)`,
);
}
return parseProtobufSchema(channel.schema.name, channel.schema.data);
return parseProtobufSchema(channel.schema.name, channel.schema.data, options?.protobuf);
}

if (channel.messageEncoding === "ros1") {
Expand Down
216 changes: 71 additions & 145 deletions typescript/support/src/parseProtobufSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,77 @@ describe("parseProtobufSchema", () => {
),
);
expect(channel.deserialize(Buffer.from("0A0101", "hex"))).toEqual({ data: [1] });
expect(channel.datatypes).toEqual(
new Map([
[
"ExampleMessage",
{
definitions: [
{ isConstant: true, name: "UNKNOWN", type: "int32", value: 0 },
{ isConstant: true, name: "WHATEVER", type: "int32", value: 0 },
{ isConstant: true, name: "FOO", type: "int32", value: 1 },
{ isConstant: true, name: "BAR", type: "int32", value: 2 },
{ name: "data", type: "int32" },
],
},
],
]),
);
});

it("allows modifying deserialization and datatypes", () => {
/*
syntax = "proto3";
enum ExampleEnum {
option allow_alias = true;
UNKNOWN = 0;
WHATEVER = 0;
FOO = 1;
BAR = 2;
}
message ExampleMessage {
repeated ExampleEnum data = 1;
}
*/
const channel = parseProtobufSchema(
"ExampleMessage",
Buffer.from(
// cspell:disable-next-line
"0A8D010A156578616D706C655F6D6573736167652E70726F746F222C0A0E4578616D706C654D657373616765121A0A046461746118012003280E320C2E4578616D706C65456E756D2A3E0A0B4578616D706C65456E756D120B0A07554E4B4E4F574E1000120C0A085748415445564552100012070A03464F4F100112070A0342415210021A021001620670726F746F33",
"hex",
),
{
processRootType(rootType) {
rootType.fieldsById[1]!.name = "renamed_data";
return rootType;
},
processMessageDefinitions(definitions) {
definitions
.get("ExampleMessage")!
.definitions.find((def) => def.name === "renamed_data")!.type = "float64";
return definitions;
},
},
);
expect(channel.deserialize(Buffer.from("0A0101", "hex"))).toEqual({ renamed_data: [1] });
expect(channel.datatypes).toEqual(
new Map([
[
"ExampleMessage",
{
definitions: [
{ isConstant: true, name: "UNKNOWN", type: "int32", value: 0 },
{ isConstant: true, name: "WHATEVER", type: "int32", value: 0 },
{ isConstant: true, name: "FOO", type: "int32", value: 1 },
{ isConstant: true, name: "BAR", type: "int32", value: 2 },
{ name: "renamed_data", type: "float64" },
],
},
],
]),
);
});

it("handles protobuf int64 values", () => {
Expand Down Expand Up @@ -102,149 +173,4 @@ describe("parseProtobufSchema", () => {
],
});
});

it("converts protobuf time/duration int64 to number rather than bigint", () => {
const poseInFrameChannel = parseProtobufSchema(
"foxglove.PoseInFrame",
Buffer.from(
// cspell:disable-next-line
"CmcKGWZveGdsb3ZlL1F1YXRlcm5pb24ucHJvdG8SCGZveGdsb3ZlIjgKClF1YXRlcm5pb24SCQoBeBgBIAEoARIJCgF5GAIgASgBEgkKAXoYAyABKAESCQoBdxgEIAEoAWIGcHJvdG8zClYKFmZveGdsb3ZlL1ZlY3RvcjMucHJvdG8SCGZveGdsb3ZlIioKB1ZlY3RvcjMSCQoBeBgBIAEoARIJCgF5GAIgASgBEgkKAXoYAyABKAFiBnByb3RvMwqyAQoTZm94Z2xvdmUvUG9zZS5wcm90bxIIZm94Z2xvdmUaGWZveGdsb3ZlL1F1YXRlcm5pb24ucHJvdG8aFmZveGdsb3ZlL1ZlY3RvcjMucHJvdG8iVgoEUG9zZRIjCghwb3NpdGlvbhgBIAEoCzIRLmZveGdsb3ZlLlZlY3RvcjMSKQoLb3JpZW50YXRpb24YAiABKAsyFC5mb3hnbG92ZS5RdWF0ZXJuaW9uYgZwcm90bzMK7wEKH2dvb2dsZS9wcm90b2J1Zi90aW1lc3RhbXAucHJvdG8SD2dvb2dsZS5wcm90b2J1ZiIrCglUaW1lc3RhbXASDwoHc2Vjb25kcxgBIAEoAxINCgVuYW5vcxgCIAEoBUKFAQoTY29tLmdvb2dsZS5wcm90b2J1ZkIOVGltZXN0YW1wUHJvdG9QAVoyZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMva25vd24vdGltZXN0YW1wcGL4AQGiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlwZXNiBnByb3RvMwrSAQoaZm94Z2xvdmUvUG9zZUluRnJhbWUucHJvdG8SCGZveGdsb3ZlGhNmb3hnbG92ZS9Qb3NlLnByb3RvGh9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnByb3RvImwKC1Bvc2VJbkZyYW1lEi0KCXRpbWVzdGFtcBgBIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5UaW1lc3RhbXASEAoIZnJhbWVfaWQYAiABKAkSHAoEcG9zZRgDIAEoCzIOLmZveGdsb3ZlLlBvc2ViBnByb3RvMw==",
"base64",
),
);

const poseInFrame = poseInFrameChannel.deserialize(
Buffer.from(
// cspell:disable-next-line
"CgwIx8LcoQYQuJzV6wESA2ZvbxooChsJAAAAAAAA8D8RAAAAAAAAAEAZAAAAAAAACEASCSEAAAAAAADwPw==",
"base64",
),
);
expect(poseInFrame).toMatchInlineSnapshot(`
{
"frame_id": "foo",
"pose": {
"orientation": {
"w": 1,
"x": 0,
"y": 0,
"z": 0,
},
"position": {
"x": 1,
"y": 2,
"z": 3,
},
},
"timestamp": {
"nsec": 494227000,
"sec": 1681334599,
},
}
`);

expect(() =>
poseInFrameChannel.deserialize(
Buffer.from(
// cspell:disable-next-line
"CgsIgICAgICAgBAQARIDZm9vGigKGwkAAAAAAADwPxEAAAAAAAAAQBkAAAAAAAAIQBIJIQAAAAAAAPA/",
"base64",
),
),
).toThrow(
"Timestamps with seconds greater than 2^53-1 are not supported (found seconds=9007199254740992, nanos=1)",
);

const sceneUpdateChannel = parseProtobufSchema(
"foxglove.SceneUpdate",
Buffer.from(
// cspell:disable-next-line
"Cl0KFGZveGdsb3ZlL0NvbG9yLnByb3RvEghmb3hnbG92ZSIzCgVDb2xvchIJCgFyGAEgASgBEgkKAWcYAiABKAESCQoBYhgDIAEoARIJCgFhGAQgASgBYgZwcm90bzMKZwoZZm94Z2xvdmUvUXVhdGVybmlvbi5wcm90bxIIZm94Z2xvdmUiOAoKUXVhdGVybmlvbhIJCgF4GAEgASgBEgkKAXkYAiABKAESCQoBehgDIAEoARIJCgF3GAQgASgBYgZwcm90bzMKVgoWZm94Z2xvdmUvVmVjdG9yMy5wcm90bxIIZm94Z2xvdmUiKgoHVmVjdG9yMxIJCgF4GAEgASgBEgkKAXkYAiABKAESCQoBehgDIAEoAWIGcHJvdG8zCrIBChNmb3hnbG92ZS9Qb3NlLnByb3RvEghmb3hnbG92ZRoZZm94Z2xvdmUvUXVhdGVybmlvbi5wcm90bxoWZm94Z2xvdmUvVmVjdG9yMy5wcm90byJWCgRQb3NlEiMKCHBvc2l0aW9uGAEgASgLMhEuZm94Z2xvdmUuVmVjdG9yMxIpCgtvcmllbnRhdGlvbhgCIAEoCzIULmZveGdsb3ZlLlF1YXRlcm5pb25iBnByb3RvMwqHAgodZm94Z2xvdmUvQXJyb3dQcmltaXRpdmUucHJvdG8SCGZveGdsb3ZlGhRmb3hnbG92ZS9Db2xvci5wcm90bxoTZm94Z2xvdmUvUG9zZS5wcm90byKoAQoOQXJyb3dQcmltaXRpdmUSHAoEcG9zZRgBIAEoCzIOLmZveGdsb3ZlLlBvc2USFAoMc2hhZnRfbGVuZ3RoGAIgASgBEhYKDnNoYWZ0X2RpYW1ldGVyGAMgASgBEhMKC2hlYWRfbGVuZ3RoGAQgASgBEhUKDWhlYWRfZGlhbWV0ZXIYBSABKAESHgoFY29sb3IY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ZS9TY2VuZUVudGl0eURlbGV0aW9uLnByb3RvImgKC1NjZW5lVXBkYXRlEjAKCWRlbGV0aW9ucxgBIAMoCzIdLmZveGdsb3ZlLlNjZW5lRW50aXR5RGVsZXRpb24SJwoIZW50aXRpZXMYAiADKAsyFS5mb3hnbG92ZS5TY2VuZUVudGl0eWIGcHJvdG8z",
"base64",
),
);

const sceneUpdate = sceneUpdateChannel.deserialize(
// cspell:disable-next-line
Buffer.from("EhwKDAjHwtyhBhC4nNXrASIMCMfC3KEGELic1esB", "base64"),
);
expect(sceneUpdate).toMatchInlineSnapshot(`
{
"deletions": [],
"entities": [
{
"arrows": [],
"cubes": [],
"cylinders": [],
"frame_id": "",
"frame_locked": false,
"id": "",
"lifetime": {
"nsec": 494227000,
"sec": 1681334599,
},
"lines": [],
"metadata": [],
"models": [],
"spheres": [],
"texts": [],
"timestamp": {
"nsec": 494227000,
"sec": 1681334599,
},
"triangles": [],
},
],
}
`);

expect(sceneUpdateChannel.datatypes.get("google.protobuf.Timestamp")).toMatchInlineSnapshot(`
{
"definitions": [
{
"isArray": false,
"name": "sec",
"type": "int32",
},
{
"isArray": false,
"name": "nsec",
"type": "int32",
},
],
}
`);
expect(sceneUpdateChannel.datatypes.get("google.protobuf.Duration")).toMatchInlineSnapshot(`
{
"definitions": [
{
"isArray": false,
"name": "sec",
"type": "int32",
},
{
"isArray": false,
"name": "nsec",
"type": "int32",
},
],
}
`);

// Duration too large
expect(() =>
// cspell:disable-next-line
sceneUpdateChannel.deserialize(Buffer.from("EhMKBAgCEAMiCwiAgICAgICAEBAB", "base64")),
).toThrow(
"Timestamps with seconds greater than 2^53-1 are not supported (found seconds=9007199254740992, nanos=1)",
);

// Timestamp too large
expect(() =>
// cspell:disable-next-line
sceneUpdateChannel.deserialize(Buffer.from("EhMKCwiAgICAgICAEBABIgQIAhAD", "base64")),
).toThrow(
"Timestamps with seconds greater than 2^53-1 are not supported (found seconds=9007199254740992, nanos=1)",
);
});
});
Loading

0 comments on commit 5d89e9c

Please sign in to comment.