ProtoBuf c++ 使用
2016-11-24 16:03
363 查看
以下针对protobuf 2.6版本
下载:
https://github.com/google/protobuf/releases/download/v2.6.0/protobuf-2.6.0.zip
https://github.com/google/protobuf/releases/download/v2.6.0/protoc-2.6.0-win32.zip
1.解压protobuf-2.6.0.zip
编译 vsprojects/protobuf.sln
在vsprojects\Debug生成三个文件: libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib
2.拷贝protobuf-2.6.0/src/google到Code/common/ 下面,拷贝上面三个lib到你的工程目录某个文件夹下 面(这里我们放在tlib/Debug)。
3.配置文件
4.增加宏 _SCL_SECURE_NO_WARNINGS
、
5.编译环境搭建好后开始生成协议
*.proto文件
c++使用代码:
下载:
https://github.com/google/protobuf/releases/download/v2.6.0/protobuf-2.6.0.zip
https://github.com/google/protobuf/releases/download/v2.6.0/protoc-2.6.0-win32.zip
1.解压protobuf-2.6.0.zip
编译 vsprojects/protobuf.sln
在vsprojects\Debug生成三个文件: libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib
2.拷贝protobuf-2.6.0/src/google到Code/common/ 下面,拷贝上面三个lib到你的工程目录某个文件夹下 面(这里我们放在tlib/Debug)。
3.配置文件
4.增加宏 _SCL_SECURE_NO_WARNINGS
、
5.编译环境搭建好后开始生成协议
*.proto文件
package com.game.Protobuf; option optimize_for = LITE_RUNTIME; message SGOMsMapInfo { required int32 mapid = 1; }
c++使用代码:
#include "stdafx.h" #include <vector> #include <string.h> #include <assert.h> #include "GameServer.pb.h" using namespace std; using namespace com::game::Protobuf; int main() { SGOMsMapInfo gs; gs.set_mapid(1); string strSend = ""; gs.SerializeToString(&strSend); //gs.SerailzeToString(strSend); string strAccept = strSend; SGOMsMapInfo gsAccept; if(gsAccept.ParseFromString(strAccept)) // 解析该字符串 { printf("val :%d\n", gsAccept.mapid()); } getchar(); return 0; }
相关文章推荐
- go语言使用protobuf与c++做数据通信。
- protobuf使用方法(c++为例)
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- 在Javascript中使用protobuf与c++进行通信
- 在Javascript中使用protobuf与c++进行通信
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- 【protobuf 001】 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- c++ 使用pbc 解决lua 解析protobuf 问题
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- c++使用Protobuf Message转Json字符串(Json库使用Json cpp)
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- Protobuf c++使用小坑(set_allocated函数)
- 最经常使用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- 最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
- protobuf C++ 使用示例
- 使用protobuf(c++)的构建通用的数据系统(转)
- protobuf C++ 使用示例
- protobuf C++ 使用示例