Skip to content

Commit

Permalink
再补点文档。就快写完啦
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Mar 27, 2018
1 parent 02c440e commit c72f122
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
16 changes: 16 additions & 0 deletions source/users/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ Windows下控制台里执行执行会报文件编码错误?(java.nio.charset

+ 第一种: 执行xresloader之前先执行 chcp 936,切换到GBK编码
+ 第二种: 在powershell里执行


C++加载代码编译时出现xresloader符号重定义(multiple definition of `` com::owent::xresloader::pb::xresloader_XXX)``
---------------------------------------------------------------------------------------------------------------------
pb_header.pb.cc 和 pb_header_v3.pb.cc 只能保留一个

如果系统采用的是proto v3则保留pb_header_v3.pb.cc

如果系统采用的是老版本的proto v2则保留pb_header.pb.cc

C++加载代码编译时出现xresloader版本检查错误
----------------------------------------------------------------------------------------------------------------

具体表现为编译时输出 ``This file was generated by an older version of protoc ...`` 或 ``This file was generated by a newer version of protoc ...`` 。

这是因为protoc版本和目前所用的protobuf版本不一致,请尝试重新用目前所用的protoc根据配置的proto文件和header目录中的 ``pb_header_v3.proto`` 或 ``pb_header.proto`` 重新生成c++代码文件。
69 changes: 68 additions & 1 deletion source/users/output_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,90 @@ Lua代码目标:
数据加载
-----------------------------------------------

加载数据可以有多种方法,项目可以根据自己的需要选择任意一种或几种合适的加载方法
前面小节我们大致展示了转出数据的结构,以此比较容易理解加载的方式。本小节则是对一些环境和语言的简单加载库

Step-6-1(推荐): 使用C++加载二进制数据
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

此加载方式需要上面的 :ref:`output-format-export binary`

:ref:`快速上手-Step-6.1: 使用读取库解析 <quick_start-load-with-libresloader>` 里我们已经给出了这种加载方式的具体使用,这里不再复述。
这里提供的方式也支持protobuf的lite模式。

Step-6-2(推荐): 使用lua-pbc加载二进制数据
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

此加载方式需要上面的 :ref:`output-format-export binary`

对于一些中使用lua的项目,也可以选择使用 `pbc <protobuf-lite>`_ 来加载数据。
我们在 https://github.com/xresloader/xresloader/tree/master/loader-binding/pbc 有使用pbc进行加载的manager封装。
在 https://github.com/owent-utils/lua/tree/master/src/data 里有对多项数据集的封装。这两部分都依赖 https://github.com/owent-utils/lua 仓库里提供的utility层。

简要的加载代码如下:

.. code-block:: lua
-- 加载lua加载器
local class = require('utils.class')
local loader = require('utils.loader')
-- 必须保证pbc已经载入
local pbc = protobuf
pbc.register(io.open('pb_header.pb', 'rb'):read('a')) -- 注册转表头描述文件
pbc.register(io.open('用户协议.pb', 'rb'):read('a')) -- 注册转表协议描述文件
local cfg = loader.load('data.pbc_config_data_set')
-- 设置路径规则 (一定要带一个%s)
-- 当读取协议message类型为PROTO的配置时,实际查找的协议名称为string.format(rule, PROTO)
-- 比如protobuf的package名称是config,那么这里rule填 config.%s
cfg:set_path_rule('%s')
-- 设置配置列表加载文件
-- cfg:set_list('data.conf_list') -- cfg:reload() 会在清空配置数据后执行require('data.conf_list')
简要的配置清单代码( ``data/conf_list.lua`` )如下:

.. code-block:: lua
local class = require('utils.class')
local loader = require('utils.loader')
local cfg = loader.load('data.pbc_config_data_set')
-- role_cfg, 第二个参数是个函数,返回key,这样读入的数据可以按key-value模式组织起来
cfg:load_buffer_kv('role_cfg', io.open('role_cfg.bin', 'rb'):read('a'), function(k, v)
return v.id or k
end)
-- 第三个参数是个别名
cfg:load_buffer_kv('role_cfg', io.open('role_cfg.bin', 'rb'):read('a'), function(k, v)
return v.id or k
end, 'alias_name')
-- 这后面的时读取,不是加载
-- 别名和非别名的数据一样的
vardump(cfg:get('role_cfg'):get(10002)) -- dump id=10002的role_cfg表的数据
vardump(cfg:get('alias_name'):get(10002)) -- dump id=10002的role_cfg表的数据
-- 直接读取里面的字段
print(string.format('kind id=%d, name=%s, dep_test.name=%s', kind.id, kind.name, kind.dep_test.name))
| proto v3请注意: pbc不支持[packed=true]属性。在proto v3中,所有的repeated整数都默认是[packed=true],要使用pbc解码请注意这些field要显示申明为[packed=false]
| 或者使用我修改过的 `pbc的proto_v3分支 <https://github.com/owent-contrib/pbc/tree/proto_v3>`_ 。
|
| 主要接口注册形式
| pbc_config_manager:load_buffer_kv(协议名, 二进制, function(序号, 转出的lua table) return key的值 end, 别名) -- 读取key-value型数据接口
| pbc_config_manager:load_buffer_kl(协议名, 二进制, function(序号, 转出的lua table) return key的值 end, 别名) -- 读取key-list型数据接口
Step-6-3(推荐): 使用C#和DynamicMessage-net加载二进制数据
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

此加载方式需要上面的 :ref:`output-format-export binary`

为了方便Unity能够不依赖反射动态获取类型和读取配置,我们提供了 `DynamicMessage-net <https://github.com/xresloader/DynamicMessage-net>`_ 项目。
这个项目依赖 `protobuf-net <https://github.com/mgravell/protobuf-net>`_ 的底层。 详见项目主页: https://github.com/xresloader/DynamicMessage-net

Step-6-4(可选): 使用node.js加载javascript文本数据
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions source/users/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Step-6: 加载数据

然后你可以选择使用我们封装过的读取库解析或手动解析。

.. _quick_start-load-with-libresloader:

Step-6.1: 使用读取库解析
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit c72f122

Please sign in to comment.