protobuf3,python如何将元素设置为map<string,OtherMessage>dict?

2024-06-28 19:53:39 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图设置map<string,Y> dict of X的元素时 引发了ValueError。在

"Direct assignment of submessage not allowed"

我的实验代码是

syntax = "proto3";

message X {
  map<string,Y> dict = 1;
}

message Y {
  int32 v = 1;
}

和python代码

^{pr2}$

然后出现错误

Traceback (most recent call last):
  File "x.py", line 8, in <module>
    x.data['a'] = y
ValueError: Direct assignment of submessage not allowed

我如何解决这个问题?在


Tags: of代码元素mapmessagestringnotdict