Skip to content

Utility to parse a proto file, which describes a Google protocol buffer.

License

Notifications You must be signed in to change notification settings

godsonhand/proto-parse

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proto-parse

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;

TODO

  • 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.

Usage

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.

Returns

The function returns an array containing the following elements.

{
	syntax: "proto3",
	content: [
		// Top Level Elements, see below
	]
}

Package

{
  "type": "package",
  "package": "MyCompany.MyPackage"
}

Service

{
	"type": "service",
	"name": "a",
	"content": [ // Containing RPCs
		...
	]
}

RPC

{
	"type": "rpc",
	"name": "MyRPC",
	"param":, ... // Containing type of param
	"returns": ... // Containing type of return value
}

Message

{
  "type": "message",
  "name": "MY_MESSAGE" // Name of the message
  "content": [ // is an array containing messages, fields, enums
     ...
  ]

}

Type

{
	"type": "userdef", // userdef, primitive or map
	"typename": "abc" // Name of the type
}

Special case map

map<int32, string> bla = 1;

results in:

{
	"type": "field",
	"typename": "map",
	"key": "int32",
	"value": "string",
	"name": "bla",
	"fieldNo": 1,
	"opts": {}
}

Changes

  • v0.0.1 Initial commit.
  • v0.0.2 Just fixed some bugs in the Readme file.

About

Utility to parse a proto file, which describes a Google protocol buffer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%