資源簡介
在window下c++使用云風(fēng)的protobuf
資源附帶有:
1.pbc-master.zip
2.protobuf-2.5.0.zip
3.protoc-2.5.0-win32.zip
4.一個完整實(shí)例gametest

代碼片段和文件信息
//?gametest.cpp?:?定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?“pbc.h“
#pragma?comment(lib?“pbc.lib“)
using?namespace?std;
struct?pbc_env?*?env?=?pbc_new();
static?void?read_file?(const?char?*filename??struct?pbc_slice?*slice)?{
FILE*?f;
fopen_s(&f?filename?“rb“);
if?(f?==?NULL)?{
slice->buffer?=?NULL;
slice->len?=?0;
return;
}
fseek(f0SEEK_END);
slice->len?=?ftell(f);
fseek(f0SEEK_SET);
slice->buffer?=?malloc(slice->len);
fread(slice->buffer?1??slice->len??f);
fclose(f);
}
static?void?test(struct?pbc_env?*env)?{
struct?pbc_wmessage*?w_msg?=?pbc_wmessage_new(env?“S2c_login_info“);
//賬號
pbc_wmessage_string(w_msg?“l(fā)ist_id“?“12345“?0);
//角色數(shù)據(jù)1
struct?pbc_wmessage?*?user?=?pbc_wmessage_message(w_msg??“l(fā)ist“);
pbc_wmessage_string(user??“uid“?“111“??0);
pbc_wmessage_string(user??“name“?“aaa“??0);
pbc_wmessage_integer(user??“photo“?12345??0);
//角色數(shù)據(jù)2
user?=?pbc_wmessage_message(w_msg??“l(fā)ist“);
pbc_wmessage_string(user??“uid“?“222“??0);
pbc_wmessage_string(user??“name“?“bbb“??0);
pbc_wmessage_integer(user??“photo“?54321??0);
struct?pbc_slice?sl;
char?buffer[1024];
sl.buffer?=?buffer?sl.len?=?1024;
pbc_wmessage_buffer(w_msg?&sl);
struct?pbc_rmessage*?r_msg?=?NULL;
r_msg?=?pbc_rmessage_new(env?“S2c_login_info“?&sl);
//讀取賬號ID
string?list_id?=?pbc_rmessage_string(r_msg?“l(fā)ist_id“?0??NULL);
printf(“l(fā)ist_id:%s?\n“?list_id.c_str());
//讀取角色數(shù)據(jù)
int?user_n?=?pbc_rmessage_size(r_msg?“l(fā)ist“);
for?(int?i=0;i struct?pbc_rmessage?*?p?=?pbc_rmessage_message(r_msg??“l(fā)ist“?i);
string?uid?=?pbc_rmessage_string(p??“uid“?i?NULL);
string?name?=?pbc_rmessage_string(p?“name“?i?NULL);
int?photo?=?pbc_rmessage_integer(p?“photo“?i?NULL);
printf(“uid:%s?name:%s?photo:%d?\n“?uid.c_str()?name.c_str()?photo);
}
pbc_rmessage_delete(r_msg);
pbc_wmessage_delete(w_msg);
}
int?_tmain(int?argc?_TCHAR*?argv[])
{
struct?pbc_slice?slice;
read_file(“l(fā)ogin.pb“?&slice);
int?ret?=?pbc_register(env?&slice);
assert(ret?==?0);
test(env);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-01-18?15:34??window_c++_protobuf\
?????目錄???????????0??2014-01-18?15:38??window_c++_protobuf\gametest\
?????目錄???????????0??2014-01-18?15:37??window_c++_protobuf\gametest\gametest\
?????文件?????????891??2014-01-18?15:12??window_c++_protobuf\gametest\gametest.sln
?????文件???????21504??2014-01-18?15:38??window_c++_protobuf\gametest\gametest.v11.suo
?????文件????????2249??2014-01-18?15:32??window_c++_protobuf\gametest\gametest\gametest.cpp
?????文件????????4471??2014-01-18?15:22??window_c++_protobuf\gametest\gametest\gametest.vcxproj
?????文件????????1397??2014-01-18?15:22??window_c++_protobuf\gametest\gametest\gametest.vcxproj.filters
?????文件?????????181??2014-01-14?18:00??window_c++_protobuf\gametest\gametest\login.pb
?????文件?????????399??2014-01-14?13:15??window_c++_protobuf\gametest\gametest\login.proto
?????文件????????3467??2013-07-30?15:09??window_c++_protobuf\gametest\gametest\pbc.h
?????文件??????328872??2014-01-14?11:17??window_c++_protobuf\gametest\gametest\pbc.lib
?????文件????????1517??2014-01-18?15:12??window_c++_protobuf\gametest\gametest\ReadMe.txt
?????文件?????????213??2014-01-18?15:12??window_c++_protobuf\gametest\gametest\stdafx.cpp
?????文件?????????233??2014-01-18?15:12??window_c++_protobuf\gametest\gametest\stdafx.h
?????文件?????????236??2014-01-18?15:12??window_c++_protobuf\gametest\gametest\targetver.h
?????文件??????113193??2014-01-13?22:34??window_c++_protobuf\pbc-master.zip
?????文件?????3054683??2014-01-18?15:34??window_c++_protobuf\protobuf-2.5.0.zip
?????文件??????652943??2014-01-18?15:34??window_c++_protobuf\protoc-2.5.0-win32.zip
評論
共有 條評論