protocol-buffers-schema

No nonsense protocol buffers schema parser written in Javascript

MIT 22 个版本
安装
npm install protocol-buffers-schema
yarn add protocol-buffers-schema
pnpm add protocol-buffers-schema
bun add protocol-buffers-schema
README

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

版本列表
3.6.1 2026-04-06
3.6.0 2021-09-09
3.5.2 2021-08-11
3.5.1 2021-01-19
3.5.0 2021-01-19
3.4.0 2020-01-24
3.3.3 2020-01-14
3.3.2 2017-09-22
3.3.1 2017-05-08
3.3.0 2017-04-11
3.2.0 2017-04-10
3.1.1 2016-11-25
3.1.0 2016-04-09
3.0.0 2015-12-14
2.2.0 2015-12-05
2.1.0 2015-11-29
2.0.4 2015-09-20
2.0.3 2015-08-28
2.0.2 2015-05-25
2.0.1 2015-04-23
2.0.0 2015-04-23
1.5.1 2015-04-23