Skip to content

Commit

Permalink
teach protoc-gen-ruby PB_{DUMP,LOAD}_REQUEST_BYTES
Browse files Browse the repository at this point in the history
`PB_DUMP_REQUEST_BYTES=foo.bin protoc foo.proto --plugin=protoc-gen-gem=bin/protoc-gen-ruby --gem_out=.`
will dump the raw proto request bytes generated by protoc for foo.proto to foo.bin

`PB_LOAD_REQUEST_BYTES=foo.bin bin/protoc-gen-ruby`
will read the raw request bytes from foo.bin and print the generated
code (actually it is the code gen response proto, but it is still
readable) to STDOUT
  • Loading branch information
nerdrew authored and embark committed Feb 23, 2016
1 parent 2970c0d commit da10060
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bin/protoc-gen-ruby
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ require 'protobuf'
require 'protobuf/descriptors'
require 'protobuf/code_generator'

request_bytes = STDIN.read
if ENV['PB_LOAD_REQUEST_BYTES']
request_bytes = File.read(ENV['PB_LOAD_REQUEST_BYTES'])
else
request_bytes = STDIN.read
end
if ENV['PB_DUMP_REQUEST_BYTES']
dump_file = ENV['PB_DUMP_REQUEST_BYTES']
unless File.directory?(File.dirname(dump_file))
warn "PB_DUMP_REQUEST_BYTES=#{dump_file.inspect} is not a valid path for the request bytes"
warn "Usage: PB_DUMP_REQUEST_BYTES=/path/to/desired/dump/file.bin protoc blah.proto"
exit 1
end
File.open(dump_file, 'w') do |f|
f.print(request_bytes)
end
exit 1
end
code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
response_bytes = code_generator.response_bytes
STDOUT.print(response_bytes)

0 comments on commit da10060

Please sign in to comment.