Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ protobuf3映射不可修改?_C++_Protocol Buffers - Fatal编程技术网

C++ protobuf3映射不可修改?

C++ protobuf3映射不可修改?,c++,protocol-buffers,C++,Protocol Buffers,protobuf消息定义:带有protobuf-3.6.1 syntax = "proto3"; message UserMessage { message Int64List { repeated int64 value = 1; }; int64 uid = 1; int64 gid = 2; repeated int32 cat = 3; map<string, int32> simple_m

protobuf消息定义:带有protobuf-3.6.1

syntax = "proto3";

message UserMessage {
    message Int64List {
        repeated int64 value = 1;
    };
    int64 uid = 1;
    int64 gid = 2;
    repeated int32 cat = 3;
    map<string, int32> simple_map = 4;
    map<string, Int64List> map_list = 5;
};

我用map struct声明了一条消息,并插入了一些对并打印出来。然后我更新了其中一些,并再次打印。结果对我来说很奇怪。为什么消息中的地图未更新?但独立打印是否正确?

无法重现protobuf-3.10.1的问题。您可以尝试更新protobuf版本。@对于堆栈,我的版本是v3.6.1。
UserMessage message;
auto m = message.mutable_simple_map();
(*m)["aaa"] = 2;
(*m)["bbb"] = 5;
{
    std::cout << message.ShortDebugString() << std::endl;
    auto a = message.simple_map();
    for (auto& b : a) {
        std::cout << "new  " << b.first << ":" << b.second << std::endl;
    }
}
(*m)["aaa"] = 20;
(*m)["bcb"] = 5;
{
    std::cout << message.ShortDebugString() << std::endl;
    auto a = message.simple_map();
    for (auto& b : a) {
        std::cout << "new  " << b.first << ":" << b.second << std::endl;
    }
}
simple_map { key: "aaa" value: 2 } simple_map { key: "bbb" value: 5 }
new  bbb:5
new  aaa:2
simple_map { key: "aaa" value: 2 } simple_map { key: "bbb" value: 5 }
new  bbb:5
new  aaa:20
new  bcb:5