protocol buffer使用指南
来源:互联网 发布:淘宝买苹果手机可靠吗 编辑:程序博客网 时间:2024/06/05 10:57
学习一个知识不是简单的下载,编译安装,就完事了.
一、protocol buffer的语法
1、包名
package tutorial;
为了区分不同proto文件中的相同消息对象
2、消息对象
在protocol buffer中
一个消息对象 = 一个结构化数据
消息对象用message修饰符修饰
message消息对象中的字段 = 结构化数据中的成员变量或函数
一个完整的消息对象的定义
// [START messages]message Person { string name = 1; int32 id = 2; // Unique ID number for this person. string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { string number = 1; PhoneType type = 2; } repeated PhoneNumber phones = 4;}// Our address book file is just one of these.message AddressBook { repeated Person people = 1;}// [END messages]
一个.proto文件中可定义多个消息对象
尽可能将与 某一消息类型 对应的响应消息格式 定义到相同的 .proto文件 中
应用场景
有时我们需要在A.proto文件中引用A.proto文件中的消息类型.
使用”import”关键字导入即可.
二、通过protocol buffer编译器编译proto文件
protoc -I=
1.SRC_DIR是proto文件所在的目录
2. –xxx_out:xxx根据需要生成代码的类型进行设置
// 对于 Java ,xxx = java ,即 – java_out
// 对于 C++ ,xxx = cpp ,即 –cpp_out
// 对于 Python,xxx = python,即 –python_out
3.DST_DIR :编译后代码生成的目录 (通常设置与$SRC_DIR相同)
4.最后的路径参数:需要编译的.proto 文件的具体路径
三、将根据平台生成的文件拷贝到项目中使用之
阅读全文
0 0
- protocol buffer使用指南
- protocol buffer
- protocol buffer
- Protocol Buffer
- protocol Buffer
- protocol buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Google Protocol Buffer
- Protocol Buffer(Google) 學習筆記一
- Linux用户管理
- cropper js基于vue的图片裁剪上传功能。
- 配置qemu时遇到disanbling libtool due to broken toolchain support问题的解决办法
- JAVA 第八次作业(1)
- 一道经典的Java多线程编程题
- protocol buffer使用指南
- Git远程仓库地址管理
- 为Eclipse安装功能扩展插件
- 将应用部署到Tomcat根目录的方法
- python_numpy.linalg_部分解释
- KMP模式匹配算法
- OSI模型
- Linux I2C工具查看配置I2C设备
- 使用cordova将Ext JS 6.2的Modern应用程序打包为安卓APP