def setUpClass(cls):
# At the moment, reference cycles between DescriptorPool and Message classes
# are not detected and these objects are never freed.
# To avoid errors with ReferenceLeakChecker, we create the class only once.
file_desc = """
name: "f/f.msg2"
package: "f"
message_type {
name: "msg1"
field {
name: "payload"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
}
}
message_type {
name: "msg2"
field {
name: "field"
number: 1
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
type_name: "msg1"
}
}
"""
pool = descriptor_pool.DescriptorPool()
desc = descriptor_pb2.FileDescriptorProto()
text_format.Parse(file_desc, desc)
pool.Add(desc)
cls.proto_cls = message_factory.MessageFactory(pool).GetPrototype(
pool.FindMessageTypeByName('f.msg2'))
message_test.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录