Skip to content

Commit

Permalink
remove parseChannel stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbandes committed Nov 18, 2023
1 parent 11c2385 commit fb90670
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 1,892 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"orta.vscode-jest",
"ms-vscode.cpptools-extension-pack",
"ms-vscode-remote.vscode-remote-extensionpack",
"streetsidesoftware.code-spell-checker"
"streetsidesoftware.code-spell-checker",
"ms-python.flake8"
]
}
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"**/dist": true
},

"python.formatting.provider": "black",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.analysis.typeCheckingMode": "strict",
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.linting.flake8Args": ["--config", "python/.flake8"],
"python.analysis.extraPaths": [
"./python/mcap",
"./python/mcap-protobuf-support",
"./python/mcap-ros1-support",
"./python/mcap-ros2-support"
],
"flake8.args": ["--config", "python/.flake8"],

// https://github.com/microsoft/vscode-cpptools/issues/722
"C_Cpp.autoAddFileAssociations": false,
Expand Down
2 changes: 1 addition & 1 deletion typescript/examples/bag2mcap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint-plugin-prettier": "5.0.1",
"lodash": "4.17.21",
"prettier": "3.1.0",
"protobufjs": "7.2.2",
"protobufjs": "7.2.5",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.2",
"typescript": "5.2.2"
Expand Down
6 changes: 4 additions & 2 deletions typescript/examples/validate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"@foxglove/wasm-bz2": "0.1.1",
"@foxglove/wasm-lz4": "1.0.2",
"@foxglove/wasm-zstd": "1.0.1",
"@mcap/core": "*",
"@mcap/core": "workspace:*",
"@mcap/nodejs": "workspace:*",
"@mcap/support": "workspace:*",
"@types/jest": "29.5.8",
"@types/lodash": "4.14.191",
"@types/node": "18.13.0",
Expand All @@ -46,7 +48,7 @@
"jest": "29.7.0",
"lodash": "4.17.21",
"prettier": "3.1.0",
"protobufjs": "7.2.2",
"protobufjs": "7.2.5",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.2",
Expand Down
70 changes: 57 additions & 13 deletions typescript/examples/validate/scripts/validate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { parse as parseMessageDefinition } from "@foxglove/rosmsg";
import { LazyMessageReader as ROS1LazyMessageReader } from "@foxglove/rosmsg-serialization";
import { MessageReader as ROS2MessageReader } from "@foxglove/rosmsg2-serialization";
import {
hasMcapPrefix,
McapConstants,
Expand All @@ -6,13 +9,16 @@ import {
McapTypes,
} from "@mcap/core";
import { FileHandleReadable } from "@mcap/nodejs";
import { loadDecompressHandlers, parseChannel, ParsedChannel } from "@mcap/support";
import { loadDecompressHandlers } from "@mcap/support";
import { program } from "commander";
import { createReadStream } from "fs";
import fs from "fs/promises";
import { isEqual } from "lodash";
import { performance } from "perf_hooks";
import protobufjs from "protobufjs";
import { FileDescriptorSet } from "protobufjs/ext/descriptor";

type Channel = McapTypes.Channel;
type TypedMcapRecord = McapTypes.TypedMcapRecord;

function log(...data: unknown[]) {
Expand Down Expand Up @@ -90,7 +96,10 @@ async function validate(
const schemasById = new Map<number, McapTypes.TypedMcapRecords["Schema"]>();
const channelInfoById = new Map<
number,
{ info: McapTypes.Channel; parsedChannel: ParsedChannel }
{
info: Channel;
messageDeserializer?: (data: ArrayBufferView) => unknown;
}
>();

function processRecord(record: TypedMcapRecord) {
Expand Down Expand Up @@ -120,17 +129,47 @@ async function validate(
}
break;
}
let schema: McapTypes.Schema | undefined;
if (record.schemaId !== 0) {
schema = schemasById.get(record.schemaId);
if (!schema) {
throw new Error(`Missing schema ${record.schemaId} for channel ${record.id}`);
}
if (record.schemaId === 0) {
throw new Error(
`Channel ${record.id} has no schema; channels without schemas are not supported`,
);
}
const schema = schemasById.get(record.schemaId);
if (!schema) {
throw new Error(`Missing schema ${record.schemaId} for channel ${record.id}`);
}
channelInfoById.set(record.id, {
info: record,
parsedChannel: parseChannel({ schema, messageEncoding: record.messageEncoding }),
});
let messageDeserializer: (data: ArrayBufferView) => unknown;
if (record.messageEncoding === "ros1") {
const reader = new ROS1LazyMessageReader(
parseMessageDefinition(new TextDecoder().decode(schema.data)),
);
messageDeserializer = (data) => {
const size = reader.size(data);
if (size !== data.byteLength) {
throw new Error(`Message size ${size} should match buffer length ${data.byteLength}`);
}
return reader.readMessage(data).toJSON();
};
} else if (record.messageEncoding === "ros2") {
const reader = new ROS2MessageReader(
parseMessageDefinition(new TextDecoder().decode(schema.data), {
ros2: true,
}),
);
messageDeserializer = (data) => reader.readMessage(data);
} else if (record.messageEncoding === "protobuf") {
const root = protobufjs.Root.fromDescriptor(FileDescriptorSet.decode(schema.data));
const type = root.lookupType(schema.name);

messageDeserializer = (data) =>
type.decode(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
} else if (record.messageEncoding === "json") {
const textDecoder = new TextDecoder();
messageDeserializer = (data) => JSON.parse(textDecoder.decode(data));
} else {
throw new Error(`unsupported encoding ${record.messageEncoding}`);
}
channelInfoById.set(record.id, { info: record, messageDeserializer });
break;
}

Expand All @@ -140,7 +179,12 @@ async function validate(
throw new Error(`message for channel ${record.channelId} with no prior channel info`);
}
if (deserialize) {
const message = channelInfo.parsedChannel.deserialize(record.data);
if (channelInfo.messageDeserializer == undefined) {
throw new Error(
`No deserializer available for channel id: ${channelInfo.info.id} ${channelInfo.info.messageEncoding}`,
);
}
const message = channelInfo.messageDeserializer(record.data);
if (dump) {
log(message);
}
Expand Down
4 changes: 2 additions & 2 deletions typescript/support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@foxglove/message-definition": "^0.3.0",
"@foxglove/omgidl-parser": "^1.0.0",
"@foxglove/omgidl-serialization": "^1.0.0",
"@foxglove/protobufjs": "0.0.1-toobject-bigint.1",
"@foxglove/ros2idl-parser": "^0.3.0",
"@foxglove/rosmsg": "^4.2.2",
"@foxglove/rosmsg-serialization": "^2.0.2",
Expand All @@ -66,6 +65,7 @@
"@foxglove/wasm-zstd": "^1.0.1",
"@protobufjs/base64": "^1.1.2",
"flatbuffers": "^23.5.26",
"flatbuffers_reflection": "^0.0.7"
"flatbuffers_reflection": "^0.0.7",
"protobufjs": "7.2.5"
}
}
3 changes: 0 additions & 3 deletions typescript/support/src/fixtures/ByteVector.bfbs

This file was deleted.

91 changes: 0 additions & 91 deletions typescript/support/src/fixtures/byte-vector.ts

This file was deleted.

3 changes: 0 additions & 3 deletions typescript/support/src/fixtures/reflection.bfbs

This file was deleted.

5 changes: 0 additions & 5 deletions typescript/support/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export * from "./decompressHandlers";
export * from "./parseChannel";
export * from "./parseFlatbufferSchema";
export * from "./parseJsonSchema";
export * from "./parseProtobufSchema";
export * from "./protobufDefinitionsToDatatypes";
export * from "./protobufDescriptors";
Loading

0 comments on commit fb90670

Please sign in to comment.