# @dxos/codec-protobuf

> There's an associated @dxos/protobuf-compiler package that does codegen based on protobuf schema.

Latest version **0.11.1** (published 2026-08-05) · FSL-1.1-Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @dxos/codec-protobuf
pnpm add @dxos/codec-protobuf
yarn add @dxos/codec-protobuf
bun add @dxos/codec-protobuf
```

## Health

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

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.11.1 |
| Published | 2026-08-05 |
| First published | 2019-11-13 |
| Weekly downloads | 0 |
| License | FSL-1.1-Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 9 |
| Unpacked size | 330.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 532 |
| Author | DXOS.org |
| Maintainers | richburdon, marik_d, wittjosiah, dxos-bot, mykola-vrmchk |

## Links

- npm: https://www.npmjs.com/package/@dxos/codec-protobuf
- Repository: https://github.com/dxos/dxos
- Homepage: https://dxos.org
- Issues: https://github.com/dxos/dxos/issues
- npm.io page: https://npm.io/package/@dxos/codec-protobuf

## Dependencies (9)

- [@dxos/log](https://npm.io/package/@dxos/log.md) 0.11.1
- [@dxos/util](https://npm.io/package/@dxos/util.md) 0.11.1
- [protobufjs](https://npm.io/package/protobufjs.md) ^8.0.0
- [@dxos/async](https://npm.io/package/@dxos/async.md) 0.11.1
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2
- [@dxos/context](https://npm.io/package/@dxos/context.md) 0.11.1
- [compress-json](https://npm.io/package/compress-json.md) ^2.1.2
- [@dxos/node-std](https://npm.io/package/@dxos/node-std.md) 0.11.1
- [@dxos/invariant](https://npm.io/package/@dxos/invariant.md) 0.11.1

## Recent versions

- 0.11.1 (latest) — 2026-08-05
- 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264 (next) — 2026-08-27
- 0.9.1-main.c7dcc2e112 (main) — 2026-06-19
- 0.7.5-labs.d199c0f (labs) — 2025-03-12
- 2.33.9-dev.a2586ac4 (dev) — 2022-08-17
- 0.12.0-next-2800d0376abcc62d5544afdd744b16b2b960434e — 2026-08-27
- 0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a — 2026-08-27
- 1.0.0-next-bbabc02363f18d7643ea4160e3a7a7809870fd0d — 2026-08-10
- 0.11.0 — 2026-08-05
- 0.10.0 — 2026-07-02
- 0.9.1-staging.ee54ba693a — 2026-07-02
- 0.9.0 — 2026-06-15
- 0.8.4-staging.60fe92afc8 — 2026-06-12
- 0.8.4-main.43cb759274 — 2026-06-04
- 0.8.4-main.d9fc60f731 — 2026-06-04
- … 3182 more at https://npm.io/package/@dxos/codec-protobuf/versions

## README

# codec-protobuf

There's an associated @dxos/protobuf-compiler package that does codegen based on protobuf schema.

## Handling of scalar fields with default values

Based on:

- https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
- https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md

In protobuf scalar fields (numbers, booleans, strings, bytes, enums) may have an implicit default value:

- 0 for number types
- false for booleans
- '' (empty string) for strings
- [] for bytes
- First enum value for enums

### Non-optional fields

Example:

```protobuf
int32 number = 1;
```

If the field is set to it's default value (0 in this example) it MAY be missing in the wire encoding (Go implementation) or present with the value set to 0 (JS implementation).

When decoding, the missing fields MUST be treated as having the default implicit value (0 in this case).

### Optional fields

```protobuf
optional int32 number = 1;
```

If the field is set to it's default value (0 in this example) it MUST be present in the wire encoding with the value set to 0.

When decoding, the missing fields it MUST be set as undefined. If the field is present in the wire format, it must be set to its numeric value.

## Toolchain

This package must NOT use `toolchain` to avoid cyclic dependencies.

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