Socket
Socket
Sign inDemoInstall

protocol-buffers-schema

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

protocol-buffers-schema

No nonsense protocol buffers schema parser written in Javascript


Version published
Maintainers
1
Weekly downloads
1,153,203
decreased by-15.15%
Install size
68.0 kB

Weekly downloads

Package description

What is protocol-buffers-schema?

The protocol-buffers-schema npm package is a tool for parsing .proto files, which define Protocol Buffers schemas. Protocol Buffers is a method of serializing structured data, and this package allows you to parse the schema definitions into a usable JSON format programmatically in JavaScript.

What are protocol-buffers-schema's main functionalities?

Parsing .proto files

This feature allows you to parse .proto files to get a JSON representation of the Protocol Buffers schema. The code sample demonstrates how to read a .proto file from the filesystem and parse it using the package.

const fs = require('fs');
const Schema = require('protocol-buffers-schema');

const schema = Schema.parse(fs.readFileSync('example.proto'));
console.log(JSON.stringify(schema, null, 2));

Other packages similar to protocol-buffers-schema

Readme

Source

protocol-buffers-schema

No nonsense protocol buffers schema parser written in Javascript

npm install protocol-buffers-schema

build status

Usage

First save the following file as example.proto

syntax = "proto2";

message Point {
  required int32 x = 1;
  required int32 y=2;
  optional string label = 3;
}

message Line {
  required Point start = 1;
  required Point end = 2;
  optional string label = 3;
}

The run the following example

var fs = require('fs')
var schema = require('protocol-buffers-schema')

// pass a buffer or string to schema.parse
var sch = schema.parse(fs.readFileSync('example.proto'))

// will print out the schema as a javascript object
console.log(sch)

Running the above example will print something like

{
  syntax: 2,
  package: null,
  enums: [],
  messages: [{
    name: 'Point',
    enums: [],
    messages: [],
    options: {},
    fields: [{
      name: 'x',
      type: 'int32',
      tag: 1,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'y',
      type: 'int32',
      tag: 2,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'label',
      type: 'string',
      tag: 3,
      required: false,
      repeated: false,
      options: {}
    }]
  }, {
    name: 'Line',
    enums: [],
    messages: [],
    options: {},
    fields: [{
      name: 'start',
      type: 'Point',
      tag: 1,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'end',
      type: 'Point',
      tag: 2,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'label',
      type: 'string',
      tag: 3,
      required: false,
      repeated: false,
      options: {}
    }]
  }],
  options:{}
}

API

schema.parse(protobufSchemaBufferOrString)

Parses a .proto schema into a javascript object

schema.stringify(schema)

Stringifies a parsed schema back into .proto format

License

MIT

Keywords

FAQs

Last updated on 09 Sep 2021

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