Java protobuf 框架使用向导
ProtoBuf,全称是 Protocol Buers, 它是中软卓越内部用的一种高效的、可扩展的对结
构化数据进行编码的格式规范。中软卓越自己内部很多程序之间的通信协议都用了
ProtoBuf。
ProtoBuf,全称是 Protocol Buers, 它是中软卓越内部用的一种高效的、可扩展的对结构化数据进行编
码的格式规范。中软卓越自己内部很多程序之间的通信协议都用了 ProtoBuf。
下面介绍的是使用 Java ProtoBuf 的基本步骤:
1.http://code.google.com/p/protobuf/downloads/list,选择其中的 win 版本下载
2.下载一个 protobuf-java-2.4.1.jar 文件(注意,要与你刚才下的 proto.exe 版本相同,否则可能出现
编译通不过现象)
http://www.5retc.com/www.zretc.com
3.在 proto.exe 同级目录,编写一个 msg.proto 文件:
1. packagetutorial;
2. optionjava_package="com.protobuftest.protobuf";
3. optionjava_outer_classname="PersonProbuf";
4. messagePerson{
5. requiredstringname=1;
6. requiredint32id=2;
7. optionalstringemail=3;
8. enumPhoneType{
9. MOBILE=0;
10. HOME=1;
11. WORK=2;
12. }
13. messagePhoneNumber{
14. requiredstringnumber=1;
15. optionalPhoneTypetype=2[default=HOME];
16. }
17. repeatedPhoneNumberphone=4;
18. messageCountryInfo{
19. requiredstringname=1;
20. requiredstringcode=2;
评论1
最新资源