proto-parse is a simple utility to parse a proto file describing a Google Protocol Buffer. Look here for more information on Proto Buffers. This is yet just a simple wrapper around a parser generated by peg.js. It is optimized for proto3 files and yet does not work for proto2. This parser strictly follows the proto 3 specs from Google;
- Add proto2 support
- Do more checking, e.g. check whether userdefined type really exists.
- Check stream support in services. Documentation does not specify the syntax, so I am waiting for Google to fix this.
Please feel free to request any feature on github.
const parse = require('proto-parse');
var data = parse(fs.readFileSync('example.proto').toString());
No options or other parameters are currently used. Just pass the string containing the proto description to the function.
The function returns an array containing the following elements.
{
syntax: "proto3",
content: [
// Top Level Elements, see below
]
}
{
"type": "package",
"package": "MyCompany.MyPackage"
}
{
"type": "service",
"name": "a",
"content": [ // Containing RPCs
...
]
}
{
"type": "rpc",
"name": "MyRPC",
"param":, ... // Containing type of param
"returns": ... // Containing type of return value
}
{
"type": "message",
"name": "MY_MESSAGE" // Name of the message
"content": [ // is an array containing messages, fields, enums
...
]
}
{
"type": "userdef", // userdef, primitive or map
"typename": "abc" // Name of the type
}
map<int32, string> bla = 1;
results in:
{
"type": "field",
"typename": "map",
"key": "int32",
"value": "string",
"name": "bla",
"fieldNo": 1,
"opts": {}
}
- v0.0.1 Initial commit.
- v0.0.2 Just fixed some bugs in the Readme file.