【问题标题】:erlang_protobuffs doesn't decode as expected for messages with repeated field对于具有重复字段的消息,erlang_protobuffs 未按预期解码
【发布时间】:2012-09-14 12:42:16
【问题描述】:

我正在开发一个使用 google proto 缓冲区进行内部数据交换的项目。它像宣传的那样工作正常,但是对于其中包含重复字段的消息,它不能按预期工作。这是一个例子:

示例test.proto 文件:

message Test {
    optional string t = 1;
}

message Tests {
    repeated Test testsList = 1;
}

生成erlang代码:

1> protobuffs_compile:scan_file("test.proto").
=INFO REPORT==== 14-Sep-2012::16:38:25 ===
Writing header file to "test_pb.hrl"

=INFO REPORT==== 14-Sep-2012::16:38:25 ===
Writing beam file to "test_pb.beam"
ok

生成test_pb.hrl:

-ifndef(TEST_PB_H).
-define(TEST_PB_H, true).
-record(test, {
    t
}).
-endif.

-ifndef(TESTS_PB_H).
-define(TESTS_PB_H, true).
-record(tests, {
    testslist = []
}).
-endif.

编码:

5> test_pb:encode_tests({tests, [{test, <<"t">>}]}).
<<10,3,10,1,116>>

解码:

6> test_pb:decode_tests(<<10,3,10,1,116>>).
{[{test,"t"}],undefined}

和上面的例子一样,解码不会返回预期的记录元组:

{tests, [{test, <<"t">>}]}

以前有人遇到过类似的问题吗?我在哪里错过了诀窍? 任何指示和帮助将不胜感激。

有关版本信息,请参阅我的 rebar.config 中的 deps 行:

{protobuffs, "0.7.0", {git, "git://github.com/basho/erlang_protobuffs.git", {tag, "0.7.0"}}}

【问题讨论】:

    标签: erlang protocol-buffers


    【解决方案1】:

    只是为了更新。

    0.7.00.6.0HEAD 都给了我与上述相同的问题。

    在讨论#riak IRC 之后,我意识到我们需要使用这个提交哈希标记的稳定版本:e0f5f6ea4c3dcb4e7b824496d2b48333fbd5a8c8,它可以解决上述问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-16
    • 2020-12-21
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多