如何将实例对象分配给protobuf消息属性

时间:2019-04-20 17:01:19

标签: python protocol-buffers

带有test.photo文件:

syntax = "proto3";

message Phone {
  string number = 1;
}
message User {
  Phone phone = 1;
}

与之编译:

python -m grpc_tools.protoc -I. --python_out=. test.proto

运行:

    import test_pb2
    user = test_pb2.User()
    phone = test_pb2.Phone(number = '(123) 456 7890')
    user.phone = phone

引发AttributeError异常:

    Assignment not allowed to field "phone" in protocol message object.

是否可以将phone对象分配给user.phone属性?

0 个答案:

没有答案