Skip to content

Latest commit

 

History

History
37 lines (35 loc) · 1.02 KB

README.md

File metadata and controls

37 lines (35 loc) · 1.02 KB

ProtocolBuff

Transports the google protocol buffer in NPL

protoc-gen-lua

Setup building environment on windows

  • Install python 2.7.0
  • Install tools/setuptools-0.6c11.win32-py2.7.exe
  • Add system variable path for python.exe
  • Add system variable path for protoc.exe
  • Download protobuf-2.4.1 and unzip
cd protobuf-2.4.1/python
python setup.py install

Use cmd to make protocol files

buildProto.bat

Test codes

-- add search path
ParaIO.AddSearchPath("npl_packages/ProtocolBuff/npl_mod/ProtocolBuff");
-- activated pb state
NPL.call("protocol/pb.cpp", {});

local person_pb = NPL.load("samples/person_pb.lua");
local msg = person_pb.Person()
msg.id = 100
msg.name = "foo"
msg.email = "bar"
local pb_data = msg:SerializeToString()

-- Parse Example
local msg = person_pb.Person()
msg:ParseFromString(pb_data)
echo({msg.id, msg.name, msg.email})