https://github.com/pwmkin/protobuffers
A lightweight and performant Protocol Buffers (protobuf) encoding and decoding library for JavaScript/TypeScript, providing tools to read, write, and work with protobuf messages efficiently.
https://github.com/pwmkin/protobuffers
javascript library protobuf protobufjs protocol-buffers serialization typescript
Last synced: 2 months ago
JSON representation
A lightweight and performant Protocol Buffers (protobuf) encoding and decoding library for JavaScript/TypeScript, providing tools to read, write, and work with protobuf messages efficiently.
- Host: GitHub
- URL: https://github.com/pwmkin/protobuffers
- Owner: pwmkin
- Created: 2025-05-27T21:41:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-27T21:41:46.000Z (about 1 year ago)
- Last Synced: 2025-05-27T21:48:34.617Z (about 1 year ago)
- Topics: javascript, library, protobuf, protobufjs, protocol-buffers, serialization, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/protobuffers
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Protobuf
A lightweight and performant Protocol Buffers (protobuf) encoding and decoding library for JavaScript/TypeScript, providing tools to read, write, and work with protobuf messages efficiently.
## Features
* Encode and decode protobuf messages with full support for:
* Varint, fixed32, fixed64, length-delimited fields
* ZigZag encoding for signed integers (sint32/sint64)
* Nested messages and packed repeated fields
* Low-level wire format utilities for protobuf serialization/deserialization
* `ProtobufReader` for parsing buffers into typed values with safe bounds checks
* `ProtobufWriter` for writing protobuf-encoded data to buffers
* Declarative message class generation with `createMessageClass` and `Message` base class
* Registry to manage protobuf message descriptors and types
* Fully typed TypeScript support with detailed field and wire type definitions
## Installation
```bash
npm install protobuffers
```
or
```bash
yarn add protobuffers
```
## Usage
```ts
import { ProtobufReader, ProtobufWriter, createMessageClass, Message } from 'protobuffers';
// Writing a protobuf message
const writer = new ProtobufWriter();
writer.writeInt32(1, -1);
writer.writeString(2, "Hello, protobuf!");
const buffer = writer.finish();
// Reading a protobuf message
const reader = new ProtobufReader(buffer);
while (reader.hasMore()) {
const tag = reader.readTag();
if (!tag) break;
switch (tag.fieldNumber) {
case 1:
const intValue = reader.readInt32();
console.log('int32 field:', intValue);
break;
case 2:
const strValue = reader.readString();
console.log('string field:', strValue);
break;
default:
reader.skipField(tag.wireType);
}
}
```
---
## Contributing
Contributions and issues are welcome! Please open issues or pull requests.
## License
MIT License