执行文件:
package com.test.proto;
import java.util.Map;
import java.util.Map.Entry;
public class Test {
public static void main(String[] args) throws Exception {
ParseProto parse = new ParseProto();
String desc = parse.genProtoDesc(options.proto);
Map
extendInfo = parse.getExtendInfo(desc);
Map
msgInfo = parse.getMsgInfo(desc); System.out.println(扩展信息:); for(Entry
e : extendInfo.entrySet()) { System.out.println(e.getKey() + -> + e.getValue()); } System.out.println( 协议信息:); for(Entry
e : msgInfo.entrySet()) { System.out.println(e.getKey() + -> + e.getValue()); } } }
三、执行结果截图

四、附件
1)项目结构图

2)需要用到的options.proto
import google/protobuf/descriptor.proto;
extend google.protobuf.FileOptions {
optional string my_file_option = 50000;
}
extend google.protobuf.MessageOptions {
optional string my_option = 55555;
}
option (my_file_option) = Hello File world!;
message MyMessage {
option (my_option) = Hello world!;
}
3)需要用到的descriptor.proto(点击下载),PS可以到官网下载。
(全文完)
注:这个是本人原创的,如需转载,请尊重劳动果实,务必保持原链接(http://blog.csdn.net/lufeng20/article/details/18276557)。