npm.io
3.4.0-38c6a3b0 • Published yesterday

@blueyerobotics/protocol-definitions

Licence
LGPL-3.0-only
Version
3.4.0-38c6a3b0
Deps
1
Size
1.6 MB
Vulns
0
Weekly
0
Stars
2

@blueyerobotics/protocol-definitions

TypeScript protobuf definitions for Blueye Robotics protocols generated using ts-proto.

Installation

npm install @blueyerobotics/protocol-definitions

Module format

This package ships ES modules only — there is no separate CommonJS build. Both import and require() work on current Node.js releases.

import { blueye } from "@blueyerobotics/protocol-definitions";

require() is supported on Node.js 22.12+ (or 20.19+), which can load an ES module from CommonJS:

const { blueye } = require("@blueyerobotics/protocol-definitions");

On older Node.js versions require() fails with ERR_REQUIRE_ESM — use import or a dynamic await import() instead.

The package root is the supported entry point. Individual generated modules stay reachable under ./dist/, with or without the .js extension (for example @blueyerobotics/protocol-definitions/dist/telemetry) if you want to import a single protocol file to keep bundles small.

Usage

import { blueye } from "@blueyerobotics/protocol-definitions";

// Create a new GetBatteryReq message
const request = blueye.protocol.GetBatteryReq.create();

// Serialize the message to a Uint8Array (binary)
const binary = blueye.protocol.GetBatteryReq.encode(request).finish();

// ...

// For demonstration, we will simulate a response from the device
const response = blueye.protocol.GetBatteryRep.create({
  battery: {
    level: 85,
    voltage: 12.5,
    temperature: 25,
  },
});

const binaryResponse = blueye.protocol.GetBatteryRep.encode(response).finish();

// Decode a binary response back into a message
const decoded = blueye.protocol.GetBatteryRep.decode(binaryResponse);

// Access fields
console.log(decoded.battery?.level);