Skip to content

Commit

Permalink
输出格式文档
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Mar 26, 2018
1 parent 8c08f63 commit 02c440e
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 4 deletions.
139 changes: 135 additions & 4 deletions source/users/output_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,151 @@
导出为json、xml、lua代码等文本数据 (可选)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

对应 ``-t json`` 、 ``-t xml`` 、 ``-t lua`` 。

对于文本数据,可以通过 ``--pretty 缩进数量`` 来设置格式化输出。
对应 ``-t json`` 、 ``-t xml`` 、 ``-t lua`` 、 ``-t js`` 。 输出的格式也是header+数据body的形式。

Json的数据格式是:

.. code-block:: json
[{
"count": 数据条目数量,
"xres_ver":"xresloader版本号",
"hash_code":"文本输出无hash码",
"data_ver":"数据版本号"
}, {
"协议名":[
{"Excel数据Key": "Excel数据内容"},
{"每行一条": "数据内容..."}
]
}]
Xml的数据格式是:

.. code-block:: xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<!--this file is generated by xresloader, please don't edit it.-->
<header>
<xres_ver>xresloader版本号</xres_ver>
<hash_code>文本输出无hash码</hash_code>
<data_ver>数据版本号</data_ver>
<count>数据条目数量</count>
</header>
<body>
<协议名>每行一条,数据内容
<Excel数据Key>Excel数据内容</Excel数据Key>
</协议名>
</body>
</root>
Lua和Javacript的输出方式和输出设置有关,也很容易看懂,这里就不全部列举了。只列举一个Lua的其中一种输出方式:

.. code-block:: lua
-- this file is generated by xresloader, please don't edit it.
return {
[1] = {
xres_ver = "xresloader版本号",
hash_code = "文本输出无hash码",
data_ver = "数据版本号",
count = 数据条目数量,
},
协议名 = {
{ Excel数据Key: Excel数据内容 } -- 每行一条,数据内容
}
}
默认情况,文本数据的输出是紧缩的。就没有上面格式列举出的看起来美观,可以通过 ``--pretty 缩进数量`` 来设置格式化输出。

.. _output-format-export msgpack:

导出为Msgpack打包的二进制数据 (可选)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

对应 ``-t msgpack``
对应 ``-t msgpack`` 。 如果不希望引入复杂的加载库,又希望打包出的数据是紧缩的二进制数据。我们提供了打包成msgpack格式的选项。
读取msgpack的工具和库很多,并且效率也很高,语言支持很很好。数据输出结构是:

.. code-block:: bash
{
xres_ver: "xresloader版本号",
data_ver: "数据版本号",
count: 数据条目数量,
hash_code: "hash算法:hash值",
}
配置协议名: [
{配置内容},
{配置内容},
{配置内容},
]
使用Msgpack的话, https://github.com/xresloader/xresloader/tree/master/loader-binding/msgpack 里有python2和node.js的读取示例。

.. _output-format-export enum:

导出枚举类型成代码 (可选)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

对应 ``-c`` 然后可以使用 ``-t json`` 、 ``-t xml`` 、 ``-t lua`` 、 ``-t js`` 来指定按哪种方式输出枚举量。
比如把protobuf协议里的枚举输出成Lua代码,proto文件:

.. code-block:: proto
// 常量类型
enum game_const_config {
option allow_alias = true;
EN_GCC_UNKNOWN = 0;
EN_GCC_PERCENT_BASE = 10000;
EN_GCC_RANDOM_RANGE_UNIT = 10;
EN_GCC_RESOURCE_MAX_LIMIT = 9999999;
EN_GCC_LEVEL_LIMIT = 999;
EN_GCC_SOLDIER_TYPE_MASK = 100;
EN_GCC_ACTIVITY_TYPE_MASK = 1000;
EN_GCC_FORMULAR_TYPE_MASK = 10;
EN_GCC_SCREEN_WIDTH = 1136;
EN_GCC_SCREEN_HEIGHT = 640;
EN_GCC_CAMERA_OFFSET = 268;
}
// 货币类型
enum cost_type {
EN_CT_UNKNOWN = 0;
EN_CT_MONEY = 10001;
EN_CT_DIAMOND = 10101;
}
Lua代码目标:

.. code-block:: lua
-- this file is generated by xresloader, please don't edit it.
local const_res = {
game_const_config = {
EN_GCC_SCREEN_WIDTH = 1136,
EN_GCC_SCREEN_HEIGHT = 640,
EN_GCC_UNKNOWN = 0,
EN_GCC_CAMERA_OFFSET = 268,
EN_GCC_FORMULAR_TYPE_MASK = 10,
EN_GCC_LEVEL_LIMIT = 999,
EN_GCC_RESOURCE_MAX_LIMIT = 9999999,
EN_GCC_SOLDIER_TYPE_MASK = 100,
EN_GCC_PERCENT_BASE = 10000,
EN_GCC_RANDOM_RANGE_UNIT = 10,
EN_GCC_ACTIVITY_TYPE_MASK = 1000,
},
cost_type = {
EN_CT_DIAMOND = 10101,
EN_CT_MONEY = 10001,
EN_CT_UNKNOWN = 0,
},
}
return const_res
对于导出的代码,可以通过 ``--pretty 缩进数量`` 来设置格式化输出。

数据加载
Expand Down Expand Up @@ -69,6 +198,8 @@ Step-6-4(可选): 使用node.js加载javascript文本数据

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

https://github.com/xresloader/xresloader/tree/master/loader-binding/msgpack

Step-6-5(可选): 使用lua加载导出的枚举类型
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
23 changes: 23 additions & 0 deletions source/users/xresloader_core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ xresloader-可用参数列表

如果我们需要一次性转出多个表,可以使用 ``--stdin`` 选项,然后再标准输入里输入其他的配置参数。这时候我们认为每个非空行都是一个数据转换组。

比如在 `xresloader sample`_ 的bash命令中:

.. code-block:: bash
echo '
-t json -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -s '$XLSX_FILE' -m scheme_kind -n "/(?i)\.bin$/\.json/"
-t xml -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -s '$XLSX_FILE' -m scheme_kind -n "/(?i)\.bin$/\.xml/"
-t msgpack -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -s '$XLSX_FILE' -m scheme_kind -n "/(?i)\.bin$/\.msgpack.bin/"
-t js -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' --pretty 2 -s '$XLSX_FILE' -m scheme_kind -n "/(?i)\.bin$/\.js/" --javascript-global sample
-t js -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' --pretty 2 -m DataSource='$XLSX_FILE'|kind|3,1 -m MacroSource='$XLSX_FILE'|macro|2,1 -m ProtoName=role_cfg -m OutputFile=role_cfg.n.js -m KeyRow=2 -m KeyCase=lower -m KeyWordSplit=_ -m "KeyWordRegex=[A-Z_\$ \t\r\n]|[_\$ \t\r\n]|[a-zA-Z_\$]" --javascript-export nodejs
-t js -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' --pretty 2 -s '$XLSX_FILE' -m scheme_kind -n "/(?i)\.bin$/\.amd\.js/" --javascript-export amd
-t lua -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' --pretty 2 -m DataSource='$XLSX_FILE'|arr_in_arr|3,1 -m MacroSource='$XLSX_FILE'|macro|2,1 -m ProtoName=arr_in_arr_cfg -m OutputFile=arr_in_arr_cfg.lua -m KeyRow=2 -o proto_v3
-t bin -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -m DataSource='$XLSX_FILE'|arr_in_arr|3,1 -m MacroSource='$XLSX_FILE'|macro|2,1 -m ProtoName=arr_in_arr_cfg -m OutputFile=arr_in_arr_cfg.bin -m KeyRow=2 -o proto_v3
-t json -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -s '$XLSX_FILE' -m scheme_upgrade -n "/(?i)\.bin$/\.json/"
-t lua -p protobuf -o '$proto_dir' -f '$proto_dir/kind.pb' -s '$XLSX_FILE' -m scheme_upgrade -n "/(?i)\.bin$/\.lua/"
' | java -client -jar "$XRESLOADER" --stdin;
这里就有10项转出文件。批处理有个优势是java在运行时会对字节码做JIT,批处理则会只对字节码编译一次,能比每个转出文件运行一次命令快很多。

| 我们之前的一个项在profile时发现每次运行java编译时间大约在1.5s,JIT编译前(一般Excel数据行的前10行)转表运行时间大约是0.5s,JIT编译后(即便是成百上千行数据行)运行时间大约是0.2s。
| 所以增加了批量转表功能,总体上把转表时间缩减到了分开执行的10%。这样我们在最后转出50多个表的时候也只需要几秒钟。

直接使用xresloader
---------------------------------------------

Expand Down

0 comments on commit 02c440e

Please sign in to comment.