需要将python dict转换为gRPC的原始消息格式

需要将python dict转换为gRPC的原始消息格式,python,grpc,proto,Python,Grpc,Proto,我有这样一种格式,我想把我的python dict转换成这种原型格式 原型代码: message template{ message NicSettings{ string network_adapter = 1; string network_name = 2; } message NetConfig{ bool keep_mac_address =1; bool same_as_source = 2; repeated NicSettings

我有这样一种格式,我想把我的python dict转换成这种原型格式 原型代码:

message template{

 message NicSettings{
    string network_adapter = 1;
    string network_name = 2;
 }

 message NetConfig{
    bool keep_mac_address =1;
    bool same_as_source = 2;
   repeated  NicSettings nic_settings = 3;
 }

 NetworkConfig network_config = 3;
}

python格言:

 template:
  { keepMacAddress: true, 
    sameAsSource : false, 
    nicSettings: [ {networkAdapter: "ethernet0", 
                    networkName: "Calpal1"
                    } ,
                    {networkAdapter: "ethernet1", 
                    networkName: "Calpal2"
                    } 
                 ] 
   }

我如何将其转换为proto消息以将其传递给gRPC。

您的
.proto
是否正确(或者是否有拼写错误?)还不完全清楚,但这看起来应该是与


my_template_message=my_message_module_pb2.template(
keep_mac_address=我的字典['keepmacadress'],
与源代码相同=我的字典['sameAsSource'],
nic_设置=元组(
my_message_module_pb2.template.NicSettings(
网络适配器=我的子字典['networkAdapter'],
网络名称=我的子字典['networkName'])
用于my_dictionary['nicSettings']中的my_子词典
)
)
. 在
.proto
内容中,将两个消息定义嵌套在另一个消息定义中也有点奇怪-这看起来根本没有必要