# tsprotobuf-codec

> A browser-compatible protocol buffer encoder/decoder in typescript

Latest version **1.0.0** (published 2024-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install tsprotobuf-codec
pnpm add tsprotobuf-codec
yarn add tsprotobuf-codec
bun add tsprotobuf-codec
```

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-01-31 |
| First published | 2024-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 192.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Warren Falk |
| Maintainers | warrenfalk |

## Links

- npm: https://www.npmjs.com/package/tsprotobuf-codec
- Repository: https://github.com/dmgtech/tsgrpc-protobuf-codec
- Homepage: https://github.com/dmgtech/tsgrpc-protobuf-codec#readme
- Issues: https://github.com/dmgtech/tsgrpc-protobuf-codec/issues
- npm.io page: https://npm.io/package/tsprotobuf-codec

## Dependencies (5)

- [long](https://npm.io/package/long.md) ^5.2.3
- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [@types/long](https://npm.io/package/@types/long.md) ^5.0.0
- [assert-never](https://npm.io/package/assert-never.md) ^1.2.1
- [@js-joda/core](https://npm.io/package/@js-joda/core.md) ^5.6.1

## Recent versions

- 1.0.0 (latest) — 2024-01-31

## README

# tsprotobuf-codec
A browser-compatible protocol buffer encoder/decoder in typescript

## Using

Note: this package is designed to be used from code generated by a protocol buffer code generator, but it can be used in any low-level library or to dynamically construct any arbitrary protocol buffer message.  The example here shows one way of doing that.

```
yarn add tsprotobuf-codec
```

This provides read and write functions for translating between the wire format and javascript representation of the various proto3 types, such as int32, double, fixed32, etc..

So if you had a protocol buffer that looked something like this:

```protobuf
message MyMessage {
    int32 my_number = 1;
    string my_string = 2;
}
```

Then you could write that with the following code (normally raw access like this would be through generated code)

```typescript
  import {WriteField as write, allocateNestingWriter, arrayCollector} from "tsprotobuf-codec";

  const myNumber = 42;
  const myNumber_field = 1;

  const myString = "The ultimate answer";
  const myString_field = 2;

  // Preallocate a buffer
  const writer = allocateNestingWriter(1024);

  // Write the fields to the buffer
  write.int32(writer, myNumber, myNumber_field);
  write.string(writer, myString, myString_field);

  // and then get the resulting blob
  const encoded = writer.finish(arrayCollector);
```

## Building

```
yarn install
yarn test
```

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