我对 Pyro4 完全陌生。我希望提供一个包含属性的 python 类,该属性是编译为 python 类的 protobuf 对象的实例。
import sys
import os
import Pyro4
import MPB_pb2 as mpb # My Protobuf class
@Pyro4.expose
@Pyro4.behavior(instance_mode="single")
class MyWrappedProtobuf(object):
def __init__(self):
self.setup_MyProtobuf()
def setup_MyProtobuf(self):
self.__MyProtobuf = mpb.MyProtobufMessage()
@property
def MyProtobuf(self):
return self.__MyProtobuf
设置服务器运行后,我创建服务对象的代理,并查询 MyProtobuf 属性:
u = Pyro4.Proxy('PYRONAME:{}'.format(<server name>)).MyProtobuf
我得到的是一个序列化的对象:
>>>u
{'serialized': '\n$\n\x05world\x12\x1b\t\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00'}
我从文档(https://pythonhosted.org/Pyro4/clientcode.html#sharing-the-way-your-custom-classes-are-de-serialized)中了解到“默认情况下,自定义类被序列化为一个字典. 它们不会反序列化回您的自定义类的实例。”
我正在寻找说明,或者描述如何将这个序列化字典转回我的类的示例,包括该类包含的 protobuf 消息实例。
看起来这一定是一个常见的、微不足道的操作,但我找不到一个很好的例子来展示给我看,并且文档没有提供我可以看到的明确帮助。
谢谢!