protocol-buffers-schema
No nonsense protocol buffers schema parser written in Javascript
npm install protocol-buffers-schema
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 =var schema =// pass a buffer or string to schema.parsevar sch = schema// will print out the schema as a javascript objectconsole
Running the above example will print something like
syntax: 2package: nullenums:messages:name: 'Point'enums:messages:fields:name: 'x'type: 'int32'tag: 1required: truerepeated: falseoptions: {}name: 'y'type: 'int32'tag: 2required: truerepeated: falseoptions: {}name: 'label'type: 'string'tag: 3required: falserepeated: falseoptions: {}name: 'Line'enums:messages:fields:name: 'start'type: 'Point'tag: 1required: truerepeated: falseoptions: {}name: 'end'type: 'Point'tag: 2required: truerepeated: falseoptions: {}name: 'label'type: 'string'tag: 3required: falserepeated: falseoptions: {}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