Skip to content

Commit

Permalink
补充proto v2的packed说明
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Apr 7, 2018
1 parent 8ebbcc5 commit 2f57276
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/users/output_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ Lua目标代码(标准形式):

其他语言和格式导出选项也类似上面的Lua的结构,具体请参考输出的文件内容加载。

.. _output-format-proto v2 and proto v3:

Proto v2和Proto v3
-----------------------------------------------
转表工具同时支持proto v2和proto v3,但是转出是使用的proto v3模式。而对于proto v2和proto v3仅在数字类型的 ``repeated`` 字段上有些许区别。

详见: https://developers.google.com/protocol-buffers/docs/proto3#specifying-field-rules

简单地说,就是proto v2里数字类型的 ``repeated`` 字段默认是 ``[ packed = false ]`` ,而在proto v3里是 ``[ packed = false ]`` 。
这可能导致转出的数据无法正常读取。解决方法也很简单,那就是对数字类型的 ``repeated`` 字段手动指定是否是packed。如:

.. code-block:: proto
message arr_in_arr {
optional string name = 1;
repeated int32 int_arr = 2 [ packed = true ];
repeated string str_arr = 3;
}
或proto v3版本。

.. code-block:: proto
message arr_in_arr {
string name = 1;
repeated int32 int_arr = 2 [ packed = true ];
repeated string str_arr = 3;
}
数据加载
-----------------------------------------------

Expand Down
7 changes: 7 additions & 0 deletions source/users/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,10 @@ Step-6.2: 手动解析
加载数据可以有多种方法,这里提供加载二进制的方法。 更多关于输出类型和加载方式的信息请参见 :doc:`./output_format` 。

上面的历程和配置可以在 https://github.com/xresloader/xresloader-docs/tree/master/source/sample/quick_start 查看。


使用proto v2加载二进制数据的特别注意事项
-----------------------------------------------
需要额外注意一点的是,如果使用proto v2生成的代码或pb加载转出的数据,如果有 ``repeated`` 的数字字段,需要在proto文件里显式指明 ``packed`` 属性。

详见 :ref:`output-format-proto v2 and proto v3`

0 comments on commit 2f57276

Please sign in to comment.