Skip to content

Commit

Permalink
First release (#1)
Browse files Browse the repository at this point in the history
* Initial setup for first release

* Initial setup

* fix typo

* node version

* node version on second pipeline

* missing references
  • Loading branch information
aneuwald-ctw authored Sep 20, 2024
1 parent 0655aae commit 2293368
Show file tree
Hide file tree
Showing 19 changed files with 1,357 additions and 1,365 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ ignorePatterns:
- dist

extends:
- plugin:@foxglove/base
- plugin:@foxglove/jest
- plugin:@lichtblick/base
- plugin:@lichtblick/jest

overrides:
- files: ["*.ts", "*.tsx"]
extends:
- plugin:@foxglove/typescript
- plugin:@lichtblick/typescript
parserOptions:
project: ./tsconfig.eslint.json
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches: [main]
tags: ["v*"]
pull_request:
branches: ["*"]

jobs:
push:
Expand All @@ -16,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org
cache: yarn

Expand All @@ -39,7 +38,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org
cache: yarn

Expand Down
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# @foxglove/rosmsg-serialization
# @lichtblick/rosmsg-serialization

> _ROS1 (Robot Operating System) message serialization, for reading and writing bags and network messages_
[![npm version](https://img.shields.io/npm/v/@foxglove/rosmsg-serialization.svg?style=flat)](https://www.npmjs.com/package/@foxglove/rosmsg-serialization)
[![npm version](https://img.shields.io/npm/v/@lichtblick/rosmsg-serialization.svg?style=flat)](https://www.npmjs.com/package/@lichtblick/rosmsg-serialization)

## MessageReader

Message reader deserializes ROS messages into plain objects. The messages are fully deserialized.

```typescript
import { MessageReader } from "@foxglove/rosmsg-serialization";
import { MessageReader } from "@lichtblick/rosmsg-serialization";

// message definition comes from `parse()` in @foxglove/rosmsg
// message definition comes from `parse()` in @lichtblick/rosmsg
const reader = new MessageReader(messageDefinition);

// deserialize a buffer into an object
Expand All @@ -28,9 +28,9 @@ a lazy message from a buffer performs no de-serialization during creation. Only
deserialized; the deserialization occurs at access time.

```Typescript
import { LazyMessageReader } from "@foxglove/rosmsg-serialization";
import { LazyMessageReader } from "@lichtblick/rosmsg-serialization";

// message definition comes from `parse()` in @foxglove/rosmsg
// message definition comes from `parse()` in @lichtblick/rosmsg
const reader = new LazyMessageReader(messageDefinition);

// build a new lazy message instance for our serialized message from the Uint8Array
Expand All @@ -46,9 +46,9 @@ message.header.stamp;
Convert an object, array, or primitive value into binary data using ROS message serialization.

```Typescript
import { MessageWriter } from "@foxglove/rosmsg-serialization";
import { MessageWriter } from "@lichtblick/rosmsg-serialization";

// message definition comes from `parse()` in @foxglove/rosmsg
// message definition comes from `parse()` in @lichtblick/rosmsg
const writer = new MessageWriter(pointStampedMessageDefinition);

// serialize the passed in object to a Uint8Array as a geometry_msgs/PointStamped message
Expand All @@ -70,7 +70,7 @@ const uint8Array = writer.writeMessage({

## License

@foxglove/rosmsg-serialization is licensed under the [MIT License](https://opensource.org/licenses/MIT).
@lichtblick/rosmsg-serialization is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Releasing

Expand All @@ -82,17 +82,13 @@ const uint8Array = writer.writeMessage({

The `bench` folder contains benchmarks. Run with:

```
```plain
yarn bench
yarn bench:benny
```

To run benchmarks in web:

```
```plain
yarn bench:web
```

## Stay in touch

Join our [Slack channel](https://foxglove.dev/slack) to ask questions, share feedback, and stay up to date on what our team is working on.
2 changes: 1 addition & 1 deletion bench/bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from "@foxglove/rosmsg";
import { parse } from "@lichtblick/rosmsg";
import { printTable } from "console-table-printer";
import { Benchmark, BenchmarkData, Measurement } from "kelonio";
import percentile from "percentile";
Expand Down
2 changes: 1 addition & 1 deletion bench/benny.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from "@foxglove/rosmsg";
import { parse } from "@lichtblick/rosmsg";
import benny from "benny";

import { Testcase, testCases } from "./testCases";
Expand Down
6 changes: 4 additions & 2 deletions bench/web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from "@foxglove/rosmsg";
import { parse } from "@lichtblick/rosmsg";

import { testCases } from "./testCases";
import { LazyMessageReader, MessageReader, MessageWriter } from "../src";
Expand Down Expand Up @@ -83,7 +83,9 @@ async function main() {
runCases("read", [
{
name: "reg",
benchCase: () => reader.readMessage(msgData),
benchCase: () => {
reader.readMessage(msgData);
},
},
{
name: "lazy",
Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foxglove/rosmsg-serialization",
"version": "2.0.3",
"name": "@lichtblick/rosmsg-serialization",
"version": "1.0.0",
"description": "ROS1 (Robot Operating System) message serialization, for reading and writing bags and network messages",
"license": "MIT",
"keywords": [
Expand All @@ -16,13 +16,13 @@
],
"repository": {
"type": "git",
"url": "https://github.com/foxglove/rosmsg-serialization.git"
"url": "https://github.com/lichtblick-suite/rosmsg-serialization"
},
"author": {
"name": "Foxglove Technologies Inc",
"email": "[email protected]"
"name": "Lichtblick",
"email": "[email protected]"
},
"homepage": "https://github.com/foxglove/rosmsg-serialization",
"homepage": "https://github.com/lichtblick-suite",
"module": "dist/esm/index.js",
"main": "dist/cjs/index.js",
"typings": "dist/esm/index.d.ts",
Expand All @@ -45,17 +45,18 @@
"bench:web": "yarn build:web && open bench/web.html"
},
"engines": {
"node": ">= 14"
"node": ">= 18"
},
"devDependencies": {
"@foxglove/eslint-plugin": "0.22.1",
"@foxglove/rosmsg": "^4.0.0",
"@foxglove/tsconfig": "1.1.0",
"@lichtblick/eslint-plugin": "^1.0.1",
"@lichtblick/message-definition": "^1.0.0",
"@lichtblick/rosmsg": "^1.0.0",
"@lichtblick/tsconfig": "^1.0.0",
"@types/jest": "^29.4.0",
"@types/node": "^20.3.2",
"@types/prettier": "2.7.2",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.62.0",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^8.6.0",
"benny": "3.7.1",
"console-table-printer": "2.11.1",
"esbuild": "0.17.11",
Expand All @@ -73,8 +74,5 @@
"ts-jest": "29.1.2",
"ts-node": "10.9.1",
"typescript": "5.1.6"
},
"dependencies": {
"@foxglove/message-definition": "^0.3.1"
}
}
4 changes: 2 additions & 2 deletions src/BuiltinDeserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export const deserializers: BuiltinReaders & {
const intArr = new Int32Array(view.buffer, totalOffset, len * 2);
for (let i = 0, j = 0; i < len; ++i, j = j + 2) {
timeArr[i] = {
sec: intArr[j] as number,
nsec: intArr[j + 1] as number,
sec: intArr[j]!,
nsec: intArr[j + 1]!,
};
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/LazyMessageReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse as parseMessageDefinition } from "@foxglove/rosmsg";
import { parse as parseMessageDefinition } from "@lichtblick/rosmsg";
import parserBabel from "prettier/parser-babel";
import prettier from "prettier/standalone";

Expand Down
2 changes: 1 addition & 1 deletion src/LazyMessageReader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageDefinition } from "@foxglove/message-definition";
import { MessageDefinition } from "@lichtblick/message-definition";

import buildReader from "./buildReader";

Expand Down
2 changes: 1 addition & 1 deletion src/MessageReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.

import { parse as parseMessageDefinition } from "@foxglove/rosmsg";
import { parse as parseMessageDefinition } from "@lichtblick/rosmsg";

import { MessageReader } from "./MessageReader";
import messageReaderTests from "./fixtures/messageReaderTests";
Expand Down
16 changes: 6 additions & 10 deletions src/MessageReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.

import { MessageDefinition } from "@foxglove/message-definition";
import { MessageDefinition } from "@lichtblick/message-definition";

import decodeString from "./decodeString";

Expand Down Expand Up @@ -80,7 +80,7 @@ export class StandardTypeReader {
len: number | null | undefined,
TypedArrayConstructor: TypedArrayConstructor,
): TypedArray {
const arrayLength = len == undefined ? this.uint32() : len;
const arrayLength = len ?? this.uint32();
const view = this.view;
const totalOffset = this.offset + view.byteOffset;
this.offset += arrayLength * TypedArrayConstructor.BYTES_PER_ELEMENT;
Expand Down Expand Up @@ -228,7 +228,7 @@ export const createParsers = ({
definitions: readonly MessageDefinition[];
options?: { freeze?: boolean };
topLevelReaderKey: string;
}): Map<string, { new (reader: StandardTypeReader): unknown }> => {
}): Map<string, new (reader: StandardTypeReader) => unknown> => {
if (definitions.length === 0) {
throw new Error(`no types given`);
}
Expand Down Expand Up @@ -264,11 +264,7 @@ export const createParsers = ({
const lenField = `length_${def.name}`;
// set a variable pointing to the parsed fixed array length
// or read the byte indicating the dynamic length
readerLines.push(
`var ${lenField} = ${
def.arrayLength != undefined ? def.arrayLength : "reader.uint32();"
}`,
);
readerLines.push(`var ${lenField} = ${def.arrayLength ?? "reader.uint32();"}`);

// only allocate an array if there is a length - skips empty allocations
const arrayName = `this.${def.name}`;
Expand Down Expand Up @@ -322,12 +318,12 @@ export const createParsers = ({
// eslint-disable-next-line @typescript-eslint/no-implied-eval,no-new-func
return new Function("topLevelReaderKey", js)(topLevelReaderKey) as Map<
string,
{ new (reader: StandardTypeReader): unknown }
new (reader: StandardTypeReader) => unknown
>;
};

export class MessageReader {
reader: { new (reader: StandardTypeReader): unknown };
reader: new (reader: StandardTypeReader) => unknown;

// takes an object message definition and returns
// a message reader which can be used to read messages based
Expand Down
35 changes: 26 additions & 9 deletions src/MessageWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.

import { parse as parseMessageDefinition } from "@foxglove/rosmsg";
import { parse as parseMessageDefinition } from "@lichtblick/rosmsg";

import { MessageReader } from "./MessageReader";
import { MessageWriter } from "./MessageWriter";
Expand Down Expand Up @@ -80,15 +80,32 @@ describe("MessageWriter", () => {
});
};

testNum("int8", 1, -3, (data) => writeInt8(data, -3, 0));
testNum("uint8", 1, 13, (data) => writeInt8(data, 13, 0));
testNum("int16", 2, -21, (data) => writeInt16LE(data, -21, 0));
testNum("uint16", 2, 21, (data) => writeUInt16LE(data, 21, 0));
testNum("int32", 4, -210010, (data) => writeInt32LE(data, -210010, 0));
testNum("uint32", 4, 210010, (data) => writeUInt32LE(data, 210010, 0));
testNum("float32", 4, 5.5, (data) => writeFloatLE(data, 5.5, 0));
testNum("int8", 1, -3, (data) => {
writeInt8(data, -3, 0);
});
testNum("uint8", 1, 13, (data) => {
writeInt8(data, 13, 0);
});
testNum("int16", 2, -21, (data) => {
writeInt16LE(data, -21, 0);
});
testNum("uint16", 2, 21, (data) => {
writeUInt16LE(data, 21, 0);
});
testNum("int32", 4, -210010, (data) => {
writeInt32LE(data, -210010, 0);
});
testNum("uint32", 4, 210010, (data) => {
writeUInt32LE(data, 210010, 0);
});
testNum("float32", 4, 5.5, (data) => {
writeFloatLE(data, 5.5, 0);
});
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
testNum("float64", 8, 0xdeadbeefcafebabe, (data) => writeDoubleLE(data, 0xdeadbeefcafebabe, 0));
testNum("float64", 8, 0xdeadbeefcafebab, (data) => {
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
writeDoubleLE(data, 0xdeadbeefcafebab, 0);
});

it("writes strings", () => {
const writer = new MessageWriter(parseMessageDefinition("string name"));
Expand Down
4 changes: 2 additions & 2 deletions src/MessageWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.

import { MessageDefinition, MessageDefinitionField } from "@foxglove/message-definition";
import { MessageDefinition, MessageDefinitionField } from "@lichtblick/message-definition";

import { stringLengthUtf8 } from "./stringLengthUtf8";

Expand Down Expand Up @@ -146,7 +146,7 @@ class StandardTypeWriter {
}
}

// eslint-disable-next-line @foxglove/no-boolean-parameters
// eslint-disable-next-line @lichtblick/no-boolean-parameters
bool(value: boolean): void {
this.uint8(value ? 1 : 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/buildReader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageDefinition, MessageDefinitionField } from "@foxglove/message-definition";
import { MessageDefinition, MessageDefinitionField } from "@lichtblick/message-definition";

import { createParsers, StandardTypeReader } from ".";
import { deserializers, fixedSizeTypes, FixedSizeTypes } from "./BuiltinDeserialize";
Expand Down
3 changes: 3 additions & 0 deletions src/decodeString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export default function decodeString(data: Uint8Array): string {
if (data.length >= 50) {
return decoder.decode(data);
}

// Disable the prefer-for-of rule for this specific case
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < data.length; i++) {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (data[i]! & 0x80) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- jsonc -*-
// tsconfig for eslint
{
"extends": "@foxglove/tsconfig/base",
"extends": "@lichtblick/tsconfig/base",
"include": ["./src/**/*", "./bench/**/*"],
"compilerOptions": {
"lib": ["DOM", "es2020"]
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- jsonc -*-
{
"extends": "@foxglove/tsconfig/base",
"extends": "@lichtblick/tsconfig/base",
"include": ["./src/**/*"],
"compilerOptions": {
"rootDir": "./src",
Expand Down
Loading

0 comments on commit 2293368

Please sign in to comment.