Hi all. Problem solved. I have used Reflection->GetMutableMessage(_modified_msg, field_descriptor, index) to get a not const message which then I've passed it to the recursive function ParseProtobufMessage(_proto_msg.get(), _modified_msg, _proto_msg-> GetTypeName());
Thanks! On Wednesday, July 10, 2019 at 8:43:36 AM UTC+3, Mihai Muraru wrote: > > Hi Cozzette, > > I've attached all files. Maybe it will help you to help me . Thank you! > Remember that the problems is only with Repeated fields. > > On Tuesday, July 9, 2019 at 11:27:02 PM UTC+3, Adam Cozzette wrote: >> >> My guess would be that there's a lifetime issue involving >> DynamicMessageFactory. The factory has to outlive any messages created from >> it via factory.GetPrototype(...)->New(). I would have to see more of the >> code to know for sure, though. >> >> On Mon, Jul 8, 2019 at 11:55 PM Mihai Muraru <[email protected]> wrote: >> >>> Hi, >>> >>> I have a plugin which has to modify at runtime the value of field from >>> a dynamic protobuf message. First in the constructor of my class I create a >>> copy of the original message >>> auto desc_set=gproto::FileDescriptorSet(); >>> if (!desc_set.ParseFromString(channel_info.description)) >>> { >>> throw ExporterException("\"" + channel_info.description + "\" is no >>> valid protobuf descriptor."); >>> } >>> std::string error; >>> >>> auto proto_msg = >>> _proto_decoder.GetProtoMessageFromDescriptorSet(desc_set, >>> StripProtoTopicInfo(channel_info.type), error); >>> if (proto_msg != nullptr) >>> { >>> _proto_msg.reset(proto_msg); >>> } >>> else >>> { >>> throw ExporterException(error); >>> } >>> //create a copy of original message because later we have to parse the >>> original message with const parameter >>> auto new_desc_set = gproto::FileDescriptorSet(); >>> new_desc_set.ParseFromString(channel_info.description); >>> >>> _modified_msg = >>> _proto_decoder.GetProtoMessageFromDescriptorSet(new_desc_set, >>> StripProtoTopicInfo(channel_info.type), error); >>> >>> >>> , then I populate the original message fields in a using >>> void ExporterChannel::SetData(Timestamp timestamp, const MetaData& >>> meta_data, const std::string& payload) >>> .... >>> _proto_msg->ParseFromString(payload) >>> .... >>> >>> Then I parse the original message using a recursive function >>> ParseProtobufMessage(_proto_msg.get(), _modified_msg, _proto_msg-> >>> GetTypeName()); >>> by iterate in each field using >>> auto refl = msg->GetReflection(); >>> std::vector<const gproto::FieldDescriptor*> field_descs; >>> refl->ListFields(*msg, &field_descs); >>> >>> All is good until I get to repeated field. >>> refl->SetRepeatedFloat(new_msg, field_desc, index, refl-> >>> GetRepeatedFloat(*msg, field_desc, index)*signal.FactorValue.toFloat() + >>> signal.OffsetValue.toFloat()); >>> >>> When I come back from the function and try to : >>> _modified_msg->SerializeToString(&new_payload_); >>> I get this Exception error: >>> >>> [image: Capture.JPG] >>> >>> in the header: >>> >>> [image: Capture.JPG] >>> Can anyone tell me what i'm doing wrong? >>> >>> Thanks in advance! >>> >>> -- >>> 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. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/protobuf/4225aaeb-a1d1-4b76-906f-0249762dea7e%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/protobuf/4225aaeb-a1d1-4b76-906f-0249762dea7e%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/2f0a70e4-d4be-4852-8b89-7cc269638c64%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
