[ProtoBuf]ProtoBuf命令生成的Cpp文件分析
来源:互联网 发布:如何评价涛哥 知乎 编辑:程序博客网 时间:2024/06/05 06:29
生成文件
在[ProtocolBuffer]定义ProtocolBuffer消息中的Person.proto文件用命令protoc.exe --cpp_out=./ Person.proto
生成的Person.pb.h和Person.pb.cc;Person.pb.h其关键部分代码如下:
namespace tutorial {// Internal implementation detail -- do not call these.void protobuf_AddDesc_Person_2eproto();void protobuf_AssignDesc_Person_2eproto();void protobuf_ShutdownFile_Person_2eproto();class Person;class Person_PhoneNumber;class AddressBook;enum Person_PhoneType { Person_PhoneType_MOBILE = 0, Person_PhoneType_HOME = 1, Person_PhoneType_WORK = 2};...class Person_PhoneNumber : public ::google::protobuf::Message { public: Person_PhoneNumber(); virtual ~Person_PhoneNumber();... Person_PhoneNumber(const Person_PhoneNumber& from); inline Person_PhoneNumber& operator=(const Person_PhoneNumber& from) { CopyFrom(from); return *this; } void Swap(Person_PhoneNumber* other);... // implements Message ---------------------------------------------- Person_PhoneNumber* New() const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const Person_PhoneNumber& from); void MergeFrom(const Person_PhoneNumber& from); void Clear(); bool IsInitialized() const; int GetCachedSize() const { return _cached_size_; } public:... // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required string number = 1; inline bool has_number() const; inline void clear_number(); static const int kNumberFieldNumber = 1; inline const ::std::string& number() const; inline void set_number(const ::std::string& value); inline void set_number(const char* value); inline void set_number(const char* value, size_t size); inline ::std::string* mutable_number(); inline ::std::string* release_number(); inline void set_allocated_number(::std::string* number); // optional .tutorial.Person.PhoneType type = 2 [default = HOME]; inline bool has_type() const; inline void clear_type(); static const int kTypeFieldNumber = 2; inline ::tutorial::Person_PhoneType type() const; inline void set_type(::tutorial::Person_PhoneType value); // @@protoc_insertion_point(class_scope:tutorial.Person.PhoneNumber) private: inline void set_has_number(); inline void clear_has_number(); inline void set_has_type(); inline void clear_has_type(); ::std::string* number_; int type_;... static Person_PhoneNumber* default_instance_;};
如何使用
使用形式1
int main(void) { Person msg1; msg1.set_id(101); msg1.set_name("hello"); cout<<msg1.id()<<endl; cout<<msg1.name()<<endl; system("pause"); return 0; } /*输出 101 hello */
阅读全文
0 0
- [ProtoBuf]ProtoBuf命令生成的Cpp文件分析
- protobuf 生成对应的文件
- protobuf 生成C++文件
- [ProtoBuf]protobuf编译命令
- protobuf的使用误区(cpp)
- vs2013编译google protobuf生成的消息文件错误。
- android使用wire方式生成protobuf的Java文件
- windows C++ protobuf的文件
- protobuf
- ProtoBuf
- protobuf
- protobuf
- protobuf
- Protobuf
- protobuf
- Protobuf
- protobuf
- protobuf
- 31. Next Permutation
- 认识HDFS分布式文件系统
- 数据结构 1 概念
- 第三章习题
- 分布式文件系统HDFS解读
- [ProtoBuf]ProtoBuf命令生成的Cpp文件分析
- Centos克隆后修改主机名称和网络IP
- 为什么Tensorflow需要使用"图计算"来表示计算过程
- 叉积极角排序
- C++ Primer 7.0~7.3部分节练习&笔记
- 实现计算器4则运算算法-分离算法
- hdu 1255 矩形面积交
- for-in循环和for循环遍历数组
- 多线程:线程同步