Skip to content

Commit da10060

Browse files
nerdrewembark
authored andcommitted
teach protoc-gen-ruby PB_{DUMP,LOAD}_REQUEST_BYTES
`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
1 parent 2970c0d commit da10060

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bin/protoc-gen-ruby

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@ require 'protobuf'
1010
require 'protobuf/descriptors'
1111
require 'protobuf/code_generator'
1212

13-
request_bytes = STDIN.read
13+
if ENV['PB_LOAD_REQUEST_BYTES']
14+
request_bytes = File.read(ENV['PB_LOAD_REQUEST_BYTES'])
15+
else
16+
request_bytes = STDIN.read
17+
end
18+
if ENV['PB_DUMP_REQUEST_BYTES']
19+
dump_file = ENV['PB_DUMP_REQUEST_BYTES']
20+
unless File.directory?(File.dirname(dump_file))
21+
warn "PB_DUMP_REQUEST_BYTES=#{dump_file.inspect} is not a valid path for the request bytes"
22+
warn "Usage: PB_DUMP_REQUEST_BYTES=/path/to/desired/dump/file.bin protoc blah.proto"
23+
exit 1
24+
end
25+
File.open(dump_file, 'w') do |f|
26+
f.print(request_bytes)
27+
end
28+
exit 1
29+
end
1430
code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
1531
response_bytes = code_generator.response_bytes
1632
STDOUT.print(response_bytes)

0 commit comments

Comments
 (0)