Skip to content

Commit dcc0d2c

Browse files
authored
Merge pull request #16 from dimensionalOS/typescript-gen
Typescript gen
2 parents ad3ffef + 96ebb26 commit dcc0d2c

File tree

187 files changed

+17879
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+17879
-4
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release to PyPI
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
id-token: write # for trusted publishing
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install Nix
16+
uses: cachix/install-nix-action@v27
17+
with:
18+
extra_nix_config: |
19+
experimental-features = nix-command flakes
20+
21+
# likely we don't need to have these bindings in the actual repo
22+
- name: Generate LCM bindings
23+
run: nix develop --command ./generate.sh
24+
25+
- name: Build package
26+
run: nix develop --command python -m build
27+
28+
- name: Publish to PyPI
29+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This will:
2020
3. Generate C++ bindings (`generated/cpp_lcm_msgs/`)
2121
4. Generate C# bindings (`generated/cs_lcm_msgs/`)
2222
5. Generate Java bindings (`generated/java_lcm_msgs/`)
23+
6. Generate Typescript bindings (`generated/ts_lcm_msgs/`)
2324

2425
## Directory Structure
2526

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
buildInputs = [
1919
lcmgen
2020
pkgs.python3
21+
pkgs.python3Packages.build
22+
pkgs.ruff
23+
pkgs.deno
2124
];
2225
};
2326
});

generate.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ set -euo pipefail
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66

7+
mkdir -p "$SCRIPT_DIR/generated"
8+
79
python3 "$SCRIPT_DIR/sources/ros_to_lcm.py"
810

911
echo -e "\033[32mRos -> LCM done\033[0m"
1012

1113
# Generate Python bindings
12-
"$SCRIPT_DIR/generated/generate_python.sh"
14+
"$SCRIPT_DIR/tools/generate_python.sh"
1315
echo -e "\033[32mLCM -> Python done\033[0m"
1416

1517
# Generate C++ bindings
@@ -26,3 +28,8 @@ echo -e "\033[32mLCM -> C# done\033[0m"
2628
rm -rf "$SCRIPT_DIR/generated/java_lcm_msgs"
2729
"$SCRIPT_DIR/sources/lcm_to_generated.sh" -j "$SCRIPT_DIR/lcm_types" -o "$SCRIPT_DIR/generated/java_lcm_msgs"
2830
echo -e "\033[32mLCM -> Java done\033[0m"
31+
32+
# Generate TypeScript bindings
33+
rm -rf "$SCRIPT_DIR/generated/ts_lcm_msgs"
34+
deno run --allow-read --allow-write "$SCRIPT_DIR/tools/ts/gen/mod.ts" -q -o "$SCRIPT_DIR/generated/ts_lcm_msgs" "$SCRIPT_DIR/lcm_types"/*.lcm
35+
echo -e "\033[32mLCM -> TypeScript done\033[0m"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Auto-generated by lcm-ts. DO NOT EDIT.
2+
3+
import { Time } from "../std_msgs/Time.ts";
4+
5+
export class GoalID {
6+
static readonly _HASH = 0xe6e8e4d2dcced2c8n;
7+
static readonly _NAME = "actionlib_msgs.GoalID";
8+
9+
stamp: Time;
10+
id: string;
11+
12+
constructor(init?: Partial<GoalID>) {
13+
this.stamp = init?.stamp ?? new Time();
14+
this.id = init?.id ?? "";
15+
}
16+
17+
static decode(data: Uint8Array): GoalID {
18+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
19+
let offset = 0;
20+
21+
// Verify fingerprint
22+
const hash = view.getBigUint64(offset, false);
23+
offset += 8;
24+
if (hash !== GoalID._HASH) {
25+
throw new Error(`Hash mismatch: expected ${GoalID._HASH.toString(16)}, got ${hash.toString(16)}`);
26+
}
27+
28+
const result = new GoalID();
29+
({ offset } = GoalID._decodeOne(view, offset, result));
30+
return result;
31+
}
32+
33+
static _decodeOne(view: DataView, offset: number, target: GoalID): { offset: number } {
34+
target.stamp = new Time();
35+
({ offset } = Time._decodeOne(view, offset, target.stamp));
36+
{
37+
const len = view.getUint32(offset, false);
38+
offset += 4;
39+
target.id = new TextDecoder().decode(new Uint8Array(view.buffer, view.byteOffset + offset, len - 1));
40+
offset += len;
41+
}
42+
return { offset };
43+
}
44+
45+
encode(): Uint8Array {
46+
const size = 8 + this._encodedSize();
47+
const data = new Uint8Array(size);
48+
const view = new DataView(data.buffer);
49+
let offset = 0;
50+
51+
// Write fingerprint
52+
view.setBigUint64(offset, GoalID._HASH, false);
53+
offset += 8;
54+
55+
offset = this._encodeOne(view, offset);
56+
return data;
57+
}
58+
59+
_encodeOne(view: DataView, offset: number): number {
60+
offset = this.stamp._encodeOne(view, offset);
61+
{
62+
const encoded = new TextEncoder().encode(this.id);
63+
view.setUint32(offset, encoded.length + 1, false);
64+
offset += 4;
65+
new Uint8Array(view.buffer, view.byteOffset + offset).set(encoded);
66+
offset += encoded.length;
67+
view.setUint8(offset, 0); // null terminator
68+
offset += 1;
69+
}
70+
return offset;
71+
}
72+
73+
_encodedSize(): number {
74+
let size = 0;
75+
size += this.stamp._encodedSize();
76+
size += 4 + new TextEncoder().encode(this.id).length + 1;
77+
return size;
78+
}
79+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Auto-generated by lcm-ts. DO NOT EDIT.
2+
3+
import { GoalID } from "./GoalID.ts";
4+
5+
export class GoalStatus {
6+
static readonly _HASH = 0xe4d2dccee8caf0e8n;
7+
static readonly _NAME = "actionlib_msgs.GoalStatus";
8+
9+
static readonly PENDING = 0;
10+
static readonly ACTIVE = 1;
11+
static readonly PREEMPTED = 2;
12+
static readonly SUCCEEDED = 3;
13+
static readonly ABORTED = 4;
14+
static readonly REJECTED = 5;
15+
static readonly PREEMPTING = 6;
16+
static readonly RECALLING = 7;
17+
static readonly RECALLED = 8;
18+
static readonly LOST = 9;
19+
20+
goal_id: GoalID;
21+
status: number;
22+
text: string;
23+
24+
constructor(init?: Partial<GoalStatus>) {
25+
this.goal_id = init?.goal_id ?? new GoalID();
26+
this.status = init?.status ?? 0;
27+
this.text = init?.text ?? "";
28+
}
29+
30+
static decode(data: Uint8Array): GoalStatus {
31+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
32+
let offset = 0;
33+
34+
// Verify fingerprint
35+
const hash = view.getBigUint64(offset, false);
36+
offset += 8;
37+
if (hash !== GoalStatus._HASH) {
38+
throw new Error(`Hash mismatch: expected ${GoalStatus._HASH.toString(16)}, got ${hash.toString(16)}`);
39+
}
40+
41+
const result = new GoalStatus();
42+
({ offset } = GoalStatus._decodeOne(view, offset, result));
43+
return result;
44+
}
45+
46+
static _decodeOne(view: DataView, offset: number, target: GoalStatus): { offset: number } {
47+
target.goal_id = new GoalID();
48+
({ offset } = GoalID._decodeOne(view, offset, target.goal_id));
49+
target.status = view.getUint8(offset);
50+
offset += 1;
51+
{
52+
const len = view.getUint32(offset, false);
53+
offset += 4;
54+
target.text = new TextDecoder().decode(new Uint8Array(view.buffer, view.byteOffset + offset, len - 1));
55+
offset += len;
56+
}
57+
return { offset };
58+
}
59+
60+
encode(): Uint8Array {
61+
const size = 8 + this._encodedSize();
62+
const data = new Uint8Array(size);
63+
const view = new DataView(data.buffer);
64+
let offset = 0;
65+
66+
// Write fingerprint
67+
view.setBigUint64(offset, GoalStatus._HASH, false);
68+
offset += 8;
69+
70+
offset = this._encodeOne(view, offset);
71+
return data;
72+
}
73+
74+
_encodeOne(view: DataView, offset: number): number {
75+
offset = this.goal_id._encodeOne(view, offset);
76+
view.setUint8(offset, this.status);
77+
offset += 1;
78+
{
79+
const encoded = new TextEncoder().encode(this.text);
80+
view.setUint32(offset, encoded.length + 1, false);
81+
offset += 4;
82+
new Uint8Array(view.buffer, view.byteOffset + offset).set(encoded);
83+
offset += encoded.length;
84+
view.setUint8(offset, 0); // null terminator
85+
offset += 1;
86+
}
87+
return offset;
88+
}
89+
90+
_encodedSize(): number {
91+
let size = 0;
92+
size += this.goal_id._encodedSize();
93+
size += 1;
94+
size += 4 + new TextEncoder().encode(this.text).length + 1;
95+
return size;
96+
}
97+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Auto-generated by lcm-ts. DO NOT EDIT.
2+
3+
import { Header } from "../std_msgs/Header.ts";
4+
import { GoalStatus } from "./GoalStatus.ts";
5+
6+
export class GoalStatusArray {
7+
static readonly _HASH = 0xeae6bed8d2e6e800n;
8+
static readonly _NAME = "actionlib_msgs.GoalStatusArray";
9+
10+
status_list_length: number;
11+
header: Header;
12+
status_list: GoalStatus[];
13+
14+
constructor(init?: Partial<GoalStatusArray>) {
15+
this.status_list_length = init?.status_list_length ?? 0;
16+
this.header = init?.header ?? new Header();
17+
this.status_list = init?.status_list ?? [];
18+
}
19+
20+
static decode(data: Uint8Array): GoalStatusArray {
21+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
22+
let offset = 0;
23+
24+
// Verify fingerprint
25+
const hash = view.getBigUint64(offset, false);
26+
offset += 8;
27+
if (hash !== GoalStatusArray._HASH) {
28+
throw new Error(`Hash mismatch: expected ${GoalStatusArray._HASH.toString(16)}, got ${hash.toString(16)}`);
29+
}
30+
31+
const result = new GoalStatusArray();
32+
({ offset } = GoalStatusArray._decodeOne(view, offset, result));
33+
return result;
34+
}
35+
36+
static _decodeOne(view: DataView, offset: number, target: GoalStatusArray): { offset: number } {
37+
target.status_list_length = view.getInt32(offset, false);
38+
offset += 4;
39+
target.header = new Header();
40+
({ offset } = Header._decodeOne(view, offset, target.header));
41+
target.status_list = new Array(target.status_list_length);
42+
for (let i0 = 0; i0 < target.status_list_length; i0++) {
43+
target.status_list[i0] = new GoalStatus();
44+
({ offset } = GoalStatus._decodeOne(view, offset, target.status_list[i0]));
45+
}
46+
return { offset };
47+
}
48+
49+
encode(): Uint8Array {
50+
const size = 8 + this._encodedSize();
51+
const data = new Uint8Array(size);
52+
const view = new DataView(data.buffer);
53+
let offset = 0;
54+
55+
// Write fingerprint
56+
view.setBigUint64(offset, GoalStatusArray._HASH, false);
57+
offset += 8;
58+
59+
offset = this._encodeOne(view, offset);
60+
return data;
61+
}
62+
63+
_encodeOne(view: DataView, offset: number): number {
64+
view.setInt32(offset, this.status_list_length, false);
65+
offset += 4;
66+
offset = this.header._encodeOne(view, offset);
67+
for (let i0 = 0; i0 < this.status_list_length; i0++) {
68+
offset = this.status_list[i0]._encodeOne(view, offset);
69+
}
70+
return offset;
71+
}
72+
73+
_encodedSize(): number {
74+
let size = 0;
75+
size += 4;
76+
size += this.header._encodedSize();
77+
for (let i0 = 0; i0 < this.status_list_length; i0++) {
78+
size += this.status_list[i0]._encodedSize();
79+
}
80+
return size;
81+
}
82+
}

0 commit comments

Comments
 (0)