+ -
当前位置:首页 → 问答吧 → [C++] Google Protocol Buffer 使用疑问

[C++] Google Protocol Buffer 使用疑问

时间:2010-09-16

来源:互联网

本帖最后由 ronat 于 2010-09-16 16:58 编辑

现有服务端用C++写, 里面通讯的数据包定义都是结构体,结构体里面都定义基本内置类型,
假如以下的结构体为客户端发送到服务端的数据包,
  1. struct  {
  2.     int nUserID;
  3.     char szUserPwd[48];
  4. }
复制代码
现在用Google Protocol Buffer生成的
  1. message Pack {
  2.     required int32 UserID = 1;
  3.     required string UserPwd = 2;
  4. }
复制代码
生成后
Pack.set_UserPwd("xxxxxxxx"; 或者Pack.set_UserPwd("xxxxxxxx",4;后,其中"xxxxxxxx"的字符不够48个

用google protocol buffer生成的类序列化数据,和我在C++中直接发送结构体的数据不一样;
如图:
下载 (91.78 KB)
2010-09-16 16:44


主要是客户端直接发送结构体的话包含有很多00,00的数据,而google protocol buffer生成的类序列化后没有,如果我服务端不更改的情况下,发送
出去肯定不行。

怎样能够让google protocol buffer生成的类里面string自动被全空白?

google protocol buffer 参考网址
http://code.google.com/intl/zh-C ... cs/cpptutorial.html

作者: ronat   发布时间: 2010-09-16

两边都得用吧,不然有啥意义呢

作者: hellioncu   发布时间: 2010-09-16