blob: fc66d27a31dda66bdfd2e122d6ee1b90d33113d9 [file] [log] [blame]
Chih-Hung Hsieh92ff6052020-06-10 20:18:39 -07001extern crate protobuf;
2extern crate protobuf_codegen;
3
4use std::fs::*;
5use std::io::Read;
6use std::path::Path;
7
8use protobuf::descriptor::*;
9use protobuf::parse_from_reader;
10use protobuf_codegen::*;
11
12fn 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
30fn 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}