主要分为下面几个步骤:
1,开始前的准备工作
首先从github上下载Google的protobuf编译出protoc.exe 地址
然后也是从github上下载云风大侠的pbc
2,将pbc中的相关代码加入到vs(我用的是vs2013)工程项目中
在frameworks\runtime-src\Classes目录下加入protobuf文件夹文件夹中加入pbc相关代码,它们的结构是这样的
1 2 3 4 | protobuf\src protobuf\pbc.h protobuf\pbc-lua.c protobuf\pbc-lua.h |
#ifndef__LUA_PBC_EXTRA_H_ #define__LUA_PBC_EXTRA_H_ #if__cplusplus extern "C" { #endif #include"lauxlib.h" int luaopen_protobuf_c(lua_State*L); #if__cplusplus } #endif #endif | @H_502_53@
packagetest.protocol.sgp; messagePerson{ requiredint32ID=1; requiredstringname=2; optionalstringemail=3; } | @H_502_53@
@echooff setDIR=%~dp0 cd/d "%DIR%" setlocalenabledelayedexpansion for /r%%iin(*.proto) do ( setpbname=%%i setpbname=!pbname:~0,-5!b protoc-I%DIR%--descriptor_set_out!pbname!%%i ) if exist "./pb" rmdir/s/q "./pb" mkdir "./pb" move*.pb./pb echo "finished" | @H_502_53@
require( "config" ) "cocos.init" ) "framework.init" ) "app.protobuf.protobuf" ) MyGame={} MyGame.protobuf=protobuf localMyApp= class ( "MyApp" ,cc.mvc.AppBase) functionMyApp:ctor() MyApp.super.ctor(self) end functionMyApp.registerallProtobuf() localpbAllname={ "pb/person.pb" } i=1,#pbAllname do localfileData=cc.HelperFunc:getfileData(pbAllname[i]) MyGame.protobuf. register (fileData) end end functionMyApp:run() cc.fileUtils:getInstance():addSearchPath( "res/" ) MyApp.registerallProtobuf() self:enterScene( "MainScene" ) end return MyApp | @H_502_53@
localMainScene= display.newScene( end) functionMainScene:ctor() localdata={} data.ID=12 data.name= "xiaoming" localstrData=MyGame.protobuf.encode( "test.protocol.sgp.Person" localperson=MyGame.protobuf.decode( dump(person) end MainScene | @H_502_53@
评论列表(0条)