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::Message; 10 use protobuf_codegen::*; 11 write_file(bin: &str)12fn write_file(bin: &str) { 13 let mut is = File::open(&Path::new(bin)).unwrap(); 14 let fds = FileDescriptorSet::parse_from_reader(&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 main()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 } 38