
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
protocol-buffers-schema
Advanced tools
No nonsense protocol buffers schema parser written in Javascript
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.
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));
protobufjs is a more comprehensive package that not only allows you to parse .proto files but also to serialize and deserialize data according to the Protocol Buffers schema. It provides a full suite of tools for working with Protocol Buffers in JavaScript.
pbf is a minimalistic library for reading and writing Protocol Buffers data. It is designed to be very fast and efficient, but it does not provide a schema parser like protocol-buffers-schema. Instead, it focuses on the encoding and decoding aspects.
No nonsense protocol buffers schema parser written in Javascript
npm install protocol-buffers-schema
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:{}
}
schema.parse(protobufSchemaBufferOrString)
Parses a .proto schema into a javascript object
schema.stringify(schema)
Stringifies a parsed schema back into .proto format
MIT
FAQs
No nonsense protocol buffers schema parser written in Javascript
The npm package protocol-buffers-schema receives a total of 1,728,756 weekly downloads. As such, protocol-buffers-schema popularity was classified as popular.
We found that protocol-buffers-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.