Socket
Socket
Sign inDemoInstall

google-protobuf

Package Overview
Dependencies
0
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    google-protobuf


Version published
Weekly downloads
1.9M
increased by4.93%
Maintainers
1
Install size
967 B
Created
Weekly downloads
 

Package description

What is google-protobuf?

The google-protobuf npm package provides a library for serializing structured data. It is used to compile .proto files to construct and parse protocol buffers in JavaScript. Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.

What are google-protobuf's main functionalities?

Serialization and Deserialization

This feature allows you to serialize your structured data to a binary format and then deserialize it back to a JavaScript object. The code sample shows how to serialize and deserialize a message using the google-protobuf package.

const messages = require('./example_pb');

// Serialization
const message = new messages.ExampleMessage();
message.setSomeField('Hello, Protocol Buffers!');
const bytes = message.serializeBinary();

// Deserialization
const receivedMessage = messages.ExampleMessage.deserializeBinary(bytes);
console.log(receivedMessage.getSomeField());

Defining Message Structure

Before you can serialize and deserialize data, you need to define the structure of your messages using the Protocol Buffers language. This code sample is a .proto file that defines a simple message with one field.

// example.proto
syntax = 'proto3';

package example;

message ExampleMessage {
  string some_field = 1;
}

Working with Enums

Protocol Buffers allow you to define enums within your .proto files. This code sample shows how to define an enum and use it within a message.

// example.proto
syntax = 'proto3';

package example;

enum ExampleEnum {
  UNKNOWN = 0;
  STARTED = 1;
  COMPLETED = 2;
}

message ExampleMessage {
  ExampleEnum status = 1;
}

Other packages similar to google-protobuf

FAQs

Last updated on 05 Apr 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc