| Chih-Hung Hsieh | 92ff605 | 2020-06-10 20:18:39 -0700 | [diff] [blame] | 1 | extern crate protobuf; |
| 2 | extern crate protobuf_codegen; |
| 3 | |
| 4 | use std::fs::*; |
| 5 | use std::io::Read; |
| 6 | use std::path::Path; |
| 7 | |
| 8 | use protobuf::descriptor::*; |
| 9 | use protobuf::parse_from_reader; |
| 10 | use protobuf_codegen::*; |
| 11 | |
| 12 | fn write_file(bin: &str) { |
| 13 | let mut is = File::open(&Path::new(bin)).unwrap(); |
| 14 | let fds = parse_from_reader::<FileDescriptorSet>(&mut is as &mut dyn Read).unwrap(); |
| 15 | |
| 16 | let file_names: Vec<String> = fds |
| 17 | .get_file() |
| 18 | .iter() |
| 19 | .map(|f| f.get_name().to_string()) |
| 20 | .collect(); |
| 21 | gen_and_write( |
| 22 | fds.get_file(), |
| 23 | &file_names, |
| 24 | Path::new("."), |
| 25 | &Default::default(), |
| 26 | ) |
| 27 | .expect("gen_and_write"); |
| 28 | } |
| 29 | |
| 30 | fn main() { |
| 31 | let args: Vec<String> = std::env::args().collect(); |
| 32 | if args.len() != 2 { |
| 33 | panic!("must have exactly one argument"); |
| 34 | } |
| 35 | let ref pb_bin = args[1]; |
| 36 | write_file(&pb_bin); |
| 37 | } |