Skip to content

Commit 0f5b72b

Browse files
committed
Add npm readme
1 parent 8a0f8e6 commit 0f5b72b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.github/workflows/ci-typescript.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
8282
- name: Publish to npm
8383
run: |
84+
cp README.npm.md protobuf_definitions/README.md
8485
cd protobuf_definitions
8586
npm publish --access public --tag latest
8687
env:

README.npm.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @blueyerobotics/protocol-definitions
2+
3+
TypeScript protobuf definitions for Blueye Robotics protocols generated using [ts-proto](https://github.com/stephenh/ts-proto).
4+
5+
## Installation
6+
7+
```bash
8+
npm install @blueyerobotics/protocol-definitions
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { blueye } from "@blueyerobotics/protocol-definitions";
15+
16+
// Create a new GetBatteryReq message
17+
const request = blueye.protocol.GetBatteryReq.create();
18+
19+
// Serialize the message to a Uint8Array (binary)
20+
const binary = blueye.protocol.GetBatteryReq.encode(request).finish();
21+
22+
// ...
23+
24+
// For demonstration, we will simulate a response from the device
25+
const response = blueye.protocol.GetBatteryRep.create({
26+
battery: {
27+
level: 85,
28+
voltage: 12.5,
29+
temperature: 25,
30+
},
31+
});
32+
33+
const binaryResponse = blueye.protocol.GetBatteryRep.encode(response).finish();
34+
35+
// Decode a binary response back into a message
36+
const decoded = blueye.protocol.GetBatteryRep.decode(binaryResponse);
37+
38+
// Access fields
39+
console.log(decoded.battery?.level);
40+
```

0 commit comments

Comments
 (0)