0.0
No commit activity in last 3 years
No release in over 3 years
Parser of JSON dumps generated by protoc-gen-json.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.11
~> 10.0
~> 3.8
 Project Readme

PbJsonParser

PbJsonParser parses JSON dumps generated by protoc-gen-json and returns the information of fields and associations of each message types.

Installation

Add this line to your application's Gemfile:

gem 'pb_json_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pb_json_parser

Usage

First, prepare .proto file.

// resources.proto
syntax = "proto3";
package south37.users_prototype;

import "google/protobuf/timestamp.proto";

message User {
  int32 id = 1;
  Profile profile = 2;
}

message Profile {
  int32 id = 1;
  google.protobuf.Timestamp birthday = 2;
}

Then, generate .proto.json by protoc with protoc-gen-json plugin.

$ REPOLIST=( \
>   sourcegraph.com/sourcegraph/prototools/cmd/protoc-gen-json \
> )
> for REPO in ${REPOLIST[@]}; do
>   if [ ! -d $GOPATH/src/$REPO ]; then
>     go get -u $REPO
>   fi
> done

$ protoc \
>   -I ./protos \
>   --json_out=out=resources.proto.json:./protos \
>   ./protos/resources.proto

Finally you can parse the json by PbJsonParser.

[6] pry(main)> PbJsonParser.parse(json: File.read('./protos/resources.proto.json'), filename: 'resources.proto').map(&:to_h)
=> [
 {:name=>"User", :fields=>[{:name=>"id", :type=>"int32"}], :assocs=>[{:name=>"profile", :kind=>"has_one", :class_name=>"Profile"}]},
 {:name=>"Profile", :fields=>[{:name=>"id", :type=>"int32"}, {:name=>"birthday", :type=>".google.protobuf.Timestamp"}], :assocs=>[]}
]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake true to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/south37/pb_json_parser.

License

The gem is available as open source under the terms of the MIT License.