Did you manage to solve the problem? I am running into similar situation. Thanks On Wednesday, August 5, 2015 at 10:11:33 PM UTC+2, wpc062 wrote: > > I am using dynamic reflection functionality of python protobuf v2.6.1, and > have a function like below: > # initilization code > > des_db_ = descriptor_database.DescriptorDatabase() > des_pool_ = descriptor_pool.DescriptorPool(des_db_) > > > fdp = descriptor_pb2.FileDescriptorProto.FromString( > a_pb_module.DESCRIPTOR.serialized_pb) > des_db_.Add(fdp) > > > def unpack_PB_msg(type_name, pb_msg_str) > factory = message_factory.MessageFactory(des_pool_) > msg_class = factory.GetPrototype(des_pool_.FindMessageTypeByName( > type_name)) > > pb_msg = msg_class() > pb_msg.ParseFromString(pb_msg_str) > > return pb_msg > > > But following client code will fail > > hello = Hello_msg() > hello_str = hello.SerializeToString() > hello2 = unpack_PB_msg(Hello_msg.DESCRIPTOR.full_name, hello_str) > > hello3 = Hello_msg() > hello3.CopyFrom(hello2)# failed here!!! > > > The error message is: > hello3.CopyFrom(hello2) > File > "C:\Localdata\Python27\lib\site-packages\google\protobuf\message.py", line > 119, in CopyFrom > self.MergeFrom(other_msg) > File > "C:\Localdata\Python27\lib\site-packages\google\protobuf\internal\python_message.py", > > line 971, in MergeFrom > "expected %s got %s." % (cls.__name__, type(msg).__name__)) > TypeError: Parameter to MergeFrom() must be instance of same class: > expected Hello_msg got Hello_msg. > > > > It seems CopyFrom fails because isinstance fails. > def MergeFrom(self, msg): > if not isinstance(msg, cls): > raise TypeError( > "Parameter to MergeFrom() must be instance of same class: " > "expected %s got %s." % (cls.__name__, type(msg).__name__)) > > > Is this a protobuf bug? > > Thanks, >
-- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
