# @foxglove/rosmsg2-serialization

> ROS 2 message serialization, for reading and writing bags and network messages

Latest version **3.1.2** (published 2026-05-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @foxglove/rosmsg2-serialization
pnpm add @foxglove/rosmsg2-serialization
yarn add @foxglove/rosmsg2-serialization
bun add @foxglove/rosmsg2-serialization
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2026-05-28 |
| First published | 2021-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 20 |
| Dependencies | 3 |
| Unpacked size | 143.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 30 |
| Author | Foxglove Technologies Inc |
| Maintainers | foxglovebot, amacneil |
| Keywords | ros, ros2, robot, operating, system, cdr, serialization, deserialization, serde, rosbag |

## Links

- npm: https://www.npmjs.com/package/@foxglove/rosmsg2-serialization
- Repository: https://github.com/foxglove/ros-typescript
- npm.io page: https://npm.io/package/@foxglove/rosmsg2-serialization

## Dependencies (3)

- [@foxglove/cdr](https://npm.io/package/@foxglove/cdr.md) ^3.5.1
- [@foxglove/rostime](https://npm.io/package/@foxglove/rostime.md) ^1.1.3
- [@foxglove/message-definition](https://npm.io/package/@foxglove/message-definition.md) 0.5.0

## Recent versions

- 3.1.2 (latest) — 2026-05-28
- 3.1.1 — 2026-05-20
- 3.1.0 — 2026-05-07
- 3.0.3 — 2025-10-13
- 3.0.2 — 2025-01-07
- 3.0.1 — 2024-12-05
- 3.0.0 — 2024-12-04
- 2.0.4 — 2024-06-06
- 2.0.3 — 2023-10-24
- 2.0.2 — 2023-06-26
- 2.0.1 — 2023-06-07
- 2.0.0 — 2023-02-28
- 1.1.1 — 2022-11-24
- 1.1.0 — 2022-11-24
- 1.0.7 — 2022-09-12
- … 9 more at https://npm.io/package/@foxglove/rosmsg2-serialization/versions

## README

# @foxglove/rosmsg2-serialization

> _ROS 2 (Robot Operating System) message serialization, for reading and writing bags and network messages_

[![npm version](https://img.shields.io/npm/v/@foxglove/rosmsg2-serialization.svg?style=flat)](https://www.npmjs.com/package/@foxglove/rosmsg2-serialization)

## MessageReader

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

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

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

// specify a different `timeType` for time objects compatible with ROS 1 and @foxglove/rostime
const reader = new MessageReader(messageDefinition, { timeType: "sec,nsec" });

// deserialize a buffer into an object
const message = reader.readMessage([0x00, 0x01, ...]);

// access message fields
message.header.stamp;
```

## MessageWriter

Convert an object, array, or primitive value into binary data using ROS 2 CDR message serialization.

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

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

// serialize the passed in object to a Uint8Array as a geometry_msgs/PointStamped message
const uint8Array = writer.writeMessage({
  header: {
    stamp: { sec: 0, nanosec: 0 },
    frame_id: ""
  },
  x: 1,
  y: 0,
  z: 0
});
```

### Test

`yarn test`

## License

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

## Releasing

1. Run `yarn version --[major|minor|patch]` to bump version
2. Run `git push && git push --tags` to push new tag
3. GitHub Actions will take care of the rest

## Stay in touch

Join our [Discord community](https://foxglove.dev/chat) to ask questions, share feedback, and stay up to date on what our team is working on.

---
_Source: https://npm.io/package/@foxglove/rosmsg2-serialization · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
