Socket
Socket
Sign inDemoInstall

@bufbuild/protobuf

Package Overview
Dependencies
Maintainers
10
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bufbuild/protobuf

A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.


Version published
Weekly downloads
511K
decreased by-25.75%
Maintainers
10
Weekly downloads
 
Created

What is @bufbuild/protobuf?

@bufbuild/protobuf is an npm package that provides tools for working with Protocol Buffers (protobufs) in JavaScript and TypeScript. It allows you to define, serialize, and deserialize structured data efficiently.

What are @bufbuild/protobuf's main functionalities?

Define Protobuf Messages

This feature allows you to define protobuf messages using JavaScript classes. The `@Field.d` decorator is used to specify the field number and type.

const { Message, Field } = require('@bufbuild/protobuf');

class Person extends Message {
  @Field.d(1, 'string')
  name = '';

  @Field.d(2, 'int32')
  age = 0;
}

const person = new Person({ name: 'John Doe', age: 30 });
console.log(person);

Serialize Protobuf Messages

This feature allows you to serialize a protobuf message into a binary format. The `encode` method is used to convert the message into a buffer.

const { Message, Field } = require('@bufbuild/protobuf');

class Person extends Message {
  @Field.d(1, 'string')
  name = '';

  @Field.d(2, 'int32')
  age = 0;
}

const person = new Person({ name: 'John Doe', age: 30 });
const buffer = Person.encode(person).finish();
console.log(buffer);

Deserialize Protobuf Messages

This feature allows you to deserialize a binary buffer back into a protobuf message. The `decode` method is used to convert the buffer back into a message object.

const { Message, Field } = require('@bufbuild/protobuf');

class Person extends Message {
  @Field.d(1, 'string')
  name = '';

  @Field.d(2, 'int32')
  age = 0;
}

const buffer = new Uint8Array([10, 8, 74, 111, 104, 110, 32, 68, 111, 101, 16, 30]);
const person = Person.decode(buffer);
console.log(person);

Other packages similar to @bufbuild/protobuf

FAQs

Package last updated on 22 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc