probuf安装
Window上安装protobuf。首先需要配置好vcpkg.exe
。可以参考:vcpkg安装,或者网上其他更加详细的教程。
vcpkg.exe install protobuf
Linux上安装probuf
sudo apt install libprotobuf-dev protobuf-compiler
protobuf在c++中的简单使用
官方文档:Protocol Buffer Basics: C++ – 官方的示例挺好了
如果需要在cmake中使用,见:FindProtobuf、CMake with Google Protocol Buffers
基本逻辑是:编写.proto
文件,以定义消息格式;使用protoc
将.proto
文件转换成指定语言的类接口;使用 C++ protocol buffer API 读写消息;
具体的细节,见官方文档。