照着例子学习 protobuf-lua

参考文章:cocos2dx使用lua和protobuf

首先得下载protobuf-gen-lua的插件,插件Git地址在此。

下载完之后进入到protoc-gen-lua\plugin这个目录,并在其中建立一个批处理文件:

@python E:\3rd\quick-x-protobuf\proto-gen-lua\protoc-gen-lua\plugin\protoc-gen-lua

然后进入到上一篇笔记中的addressbook.proto所在的文件夹内,运行如下命令:

protoc --lua_out=生成的lua存放地址 --plugin=protoc-gen-lua=上面新建的bat的完整地址 addressbook.proto

回车。

我们到目标地址下面就会看到一个addressbook_pb.lua文件,内容如下:

-- Generated By protoc-gen-lua Do not Edit
local protobuf = require "protobuf"
module(‘addressbook_pb‘)

local PERSON = protobuf.Descriptor();
local PERSON_PHONENUMBER = protobuf.Descriptor();
local PERSON_PHONENUMBER_NUMBER_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONENUMBER_TYPE_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONETYPE = protobuf.EnumDescriptor();
local PERSON_PHONETYPE_MOBILE_ENUM = protobuf.EnumValueDescriptor();
local PERSON_PHONETYPE_HOME_ENUM = protobuf.EnumValueDescriptor();
local PERSON_PHONETYPE_WORK_ENUM = protobuf.EnumValueDescriptor();
local PERSON_NAME_FIELD = protobuf.FieldDescriptor();
local PERSON_ID_FIELD = protobuf.FieldDescriptor();
local PERSON_EMAIL_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONE_FIELD = protobuf.FieldDescriptor();
local ADDRESSBOOK = protobuf.Descriptor();
local ADDRESSBOOK_PERSON_FIELD = protobuf.FieldDescriptor();

PERSON_PHONENUMBER_NUMBER_FIELD.name = "number"
PERSON_PHONENUMBER_NUMBER_FIELD.full_name = ".tutorial.Person.PhoneNumber.number"
PERSON_PHONENUMBER_NUMBER_FIELD.number = 1
PERSON_PHONENUMBER_NUMBER_FIELD.index = 0
PERSON_PHONENUMBER_NUMBER_FIELD.label = 2
PERSON_PHONENUMBER_NUMBER_FIELD.has_default_value = false
PERSON_PHONENUMBER_NUMBER_FIELD.default_value = ""
PERSON_PHONENUMBER_NUMBER_FIELD.type = 9
PERSON_PHONENUMBER_NUMBER_FIELD.cpp_type = 9

PERSON_PHONENUMBER_TYPE_FIELD.name = "type"
PERSON_PHONENUMBER_TYPE_FIELD.full_name = ".tutorial.Person.PhoneNumber.type"
PERSON_PHONENUMBER_TYPE_FIELD.number = 2
PERSON_PHONENUMBER_TYPE_FIELD.index = 1
PERSON_PHONENUMBER_TYPE_FIELD.label = 1
PERSON_PHONENUMBER_TYPE_FIELD.has_default_value = true
PERSON_PHONENUMBER_TYPE_FIELD.default_value = HOME
PERSON_PHONENUMBER_TYPE_FIELD.enum_type = _PERSON_PHONETYPE
PERSON_PHONENUMBER_TYPE_FIELD.type = 14
PERSON_PHONENUMBER_TYPE_FIELD.cpp_type = 8

PERSON_PHONENUMBER.name = "PhoneNumber"
PERSON_PHONENUMBER.full_name = ".tutorial.Person.PhoneNumber"
PERSON_PHONENUMBER.nested_types = {}
PERSON_PHONENUMBER.enum_types = {}
PERSON_PHONENUMBER.fields = {PERSON_PHONENUMBER_NUMBER_FIELD, PERSON_PHONENUMBER_TYPE_FIELD}
PERSON_PHONENUMBER.is_extendable = false
PERSON_PHONENUMBER.extensions = {}
PERSON_PHONENUMBER.containing_type = PERSON
PERSON_PHONETYPE_MOBILE_ENUM.name = "MOBILE"
PERSON_PHONETYPE_MOBILE_ENUM.index = 0
PERSON_PHONETYPE_MOBILE_ENUM.number = 0
PERSON_PHONETYPE_HOME_ENUM.name = "HOME"
PERSON_PHONETYPE_HOME_ENUM.index = 1
PERSON_PHONETYPE_HOME_ENUM.number = 1
PERSON_PHONETYPE_WORK_ENUM.name = "WORK"
PERSON_PHONETYPE_WORK_ENUM.index = 2
PERSON_PHONETYPE_WORK_ENUM.number = 2
PERSON_PHONETYPE.name = "PhoneType"
PERSON_PHONETYPE.full_name = ".tutorial.Person.PhoneType"
PERSON_PHONETYPE.values = {PERSON_PHONETYPE_MOBILE_ENUM,PERSON_PHONETYPE_HOME_ENUM,PERSON_PHONETYPE_WORK_ENUM}
PERSON_NAME_FIELD.name = "name"
PERSON_NAME_FIELD.full_name = ".tutorial.Person.name"
PERSON_NAME_FIELD.number = 1
PERSON_NAME_FIELD.index = 0
PERSON_NAME_FIELD.label = 2
PERSON_NAME_FIELD.has_default_value = false
PERSON_NAME_FIELD.default_value = ""
PERSON_NAME_FIELD.type = 9
PERSON_NAME_FIELD.cpp_type = 9

PERSON_ID_FIELD.name = "id"
PERSON_ID_FIELD.full_name = ".tutorial.Person.id"
PERSON_ID_FIELD.number = 2
PERSON_ID_FIELD.index = 1
PERSON_ID_FIELD.label = 2
PERSON_ID_FIELD.has_default_value = false
PERSON_ID_FIELD.default_value = 0
PERSON_ID_FIELD.type = 5
PERSON_ID_FIELD.cpp_type = 1

PERSON_EMAIL_FIELD.name = "email"
PERSON_EMAIL_FIELD.full_name = ".tutorial.Person.email"
PERSON_EMAIL_FIELD.number = 3
PERSON_EMAIL_FIELD.index = 2
PERSON_EMAIL_FIELD.label = 1
PERSON_EMAIL_FIELD.has_default_value = false
PERSON_EMAIL_FIELD.default_value = ""
PERSON_EMAIL_FIELD.type = 9
PERSON_EMAIL_FIELD.cpp_type = 9

PERSON_PHONE_FIELD.name = "phone"
PERSON_PHONE_FIELD.full_name = ".tutorial.Person.phone"
PERSON_PHONE_FIELD.number = 4
PERSON_PHONE_FIELD.index = 3
PERSON_PHONE_FIELD.label = 3
PERSON_PHONE_FIELD.has_default_value = false
PERSON_PHONE_FIELD.default_value = {}
PERSON_PHONE_FIELD.message_type = PERSON_PHONENUMBER
PERSON_PHONE_FIELD.type = 11
PERSON_PHONE_FIELD.cpp_type = 10

PERSON.name = "Person"
PERSON.full_name = ".tutorial.Person"
PERSON.nested_types = {PERSON_PHONENUMBER}
PERSON.enum_types = {PERSON_PHONETYPE}
PERSON.fields = {PERSON_NAME_FIELD, PERSON_ID_FIELD, PERSON_EMAIL_FIELD, PERSON_PHONE_FIELD}
PERSON.is_extendable = false
PERSON.extensions = {}
ADDRESSBOOK_PERSON_FIELD.name = "person"
ADDRESSBOOK_PERSON_FIELD.full_name = ".tutorial.AddressBook.person"
ADDRESSBOOK_PERSON_FIELD.number = 1
ADDRESSBOOK_PERSON_FIELD.index = 0
ADDRESSBOOK_PERSON_FIELD.label = 3
ADDRESSBOOK_PERSON_FIELD.has_default_value = false
ADDRESSBOOK_PERSON_FIELD.default_value = {}
ADDRESSBOOK_PERSON_FIELD.message_type = PERSON
ADDRESSBOOK_PERSON_FIELD.type = 11
ADDRESSBOOK_PERSON_FIELD.cpp_type = 10

ADDRESSBOOK.name = "AddressBook"
ADDRESSBOOK.full_name = ".tutorial.AddressBook"
ADDRESSBOOK.nested_types = {}
ADDRESSBOOK.enum_types = {}
ADDRESSBOOK.fields = {ADDRESSBOOK_PERSON_FIELD}
ADDRESSBOOK.is_extendable = false
ADDRESSBOOK.extensions = {}

AddressBook = protobuf.Message(ADDRESSBOOK)
Person = protobuf.Message(PERSON)
Person.PhoneNumber = protobuf.Message(PERSON_PHONENUMBER)

实验完成,打算下一步把这个整合到自己的手游demo里面去,有机会我会好好阅读protoc-gen-lua代码的,现在最要紧的是下班,呵呵。

时间: 2024-10-18 03:58:41

照着例子学习 protobuf-lua的相关文章

pyqt QTableWidget例子学习(重点)

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * lista = ['aa', 'ab', 'ac'] listb = ['ba', 'bb', 'bc'] listc = ['ca', 'cb', 'cc'] mystruct = {'A':lista, 'B':

pyqt 正则表达式例子学习

def rex01(self): username=QtCore.QRegExp('[a-zA-Z0-9_]{2,10}') self.names.setValidator(QtGui.QRegExpValidator(username,self)) mainname=QtCore.QRegExp("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$") self.mains.setValidator(QtGui.QRegExpValidator(mainnam

pyqt QTimer,QThread例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * from start import Ui_Form import sys class Example(QDialog,Ui_Form): def __init__(self,parent=None): super(E

pyqt单选,复选等例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * from check1 import Ui_Dialog from check2 import Ui_Dialog1 from check3 import Ui_Dialog2 import sys QTextCod

数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇

<数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT 构建例如电信网管 3D 机房应用.水务燃气 SCADA 监控应用及智能楼宇等应用场景. HT for Web 的 3D 是完全基于 WebGL 技术实现的渲染引擎,但开发者几乎不需要了解 3D 图形数学或 Shader 渲染的底层技术,只需要掌握基本的 3D 坐标系和相机  Camera 的概念,剩下需要掌

HTML5 例子学习 HT 图形组件

HTML5 例子学习 HT 图形组件 HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打磨,如今 HT 算是达到了这样的效果,谈不上用尽洪荒之力,但我们对产品结果很满意,特别是 HT 的用户手册,将例子和文档无缝融合一体,小小 10 来兆开发包居然包含了四十五份手册,数百个活生生的 HTML5 例子,还没体验过的同学可以点击 http://www.

C++ opencv快速例子学习——读图显示

1.关键函数 1. 读入图片 imread(图片或位置,显示格式)默认为:IMREAD_COLOR 显示格式: IMREAD_UNCHANGED =-1    // 8bit, color or not IMREAD_GRAYSCALE    = 0    // 8bit, gray IMREAD_COLOR           = 1    //  color IMREAD_ANYDEPTH      = 2   // any depth, IMREAD_ANYCOLOR     = 4   

数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇

HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打磨,如今 HT 算是达到了这样的效果,谈不上用尽洪荒之力,但我们对产品结果很满意,特别是 HT 的用户手册,将例子和文档无缝融合一体,小小 10 来兆开发包居然包含了四十五份手册,数百个活生生的 HTML5 例子,还没体验过的同学可以点击 http://www.hightopo.com/guide/

pyqt columnView例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import  * from PyQt4.Qt import * from PyQt4.QtCore import * import sys class Tree(QColumnView): def __init__(self,parnet=None,*args): super(Tree,self).__init__(parnet,

pyqt 托盘例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * from tp import Ui_Form import sys from PyQt4.QtCore import Qt QTextCodec.setCodecForTr(QTextCodec.codecForNa