Hello again, Adam,
If I understand you correctly, the key would be to obtain the
mutable-message (by name) for the child from the parent as I descend the
tree.
It think that would work!
Thank you very much for your light, I'm a newbie to protobuf and this
demystifies part of it. I'll see if I
Here's how you could set that nested field in your example (this code is
untested so may not work exactly, but should be pretty close):
const FieldDescriptor* health_report_field =
parent.GetDescriptor()->FindFieldByName("healthreport");
Message* health_report =
Hi Adam,
OK, but would I need to know the fields in the message ahead of time? That
is what I am trying to avoid.
The paths of the nested messages are in a table, such as
"healthreport/os/version", 3
So the healthreport variable is allocated, and it contains a component
called os, which
I think the reason this is getting tricky is because you're trying to
traverse the descriptors first and then look at the message tree afterward.
I would expect it to be much easier if you traverse the message and look at
the descriptors at the same time.
On Tue, Jun 22, 2021 at 10:58 AM J G
Hi Adam,
That works for the first iteration, but I descend the tree like so:
bool enumpb( const char * pszpath, ENUMPROTOPROC f, const
google::protobuf::Descriptor * d, uintptr_t param ) {
std::string path = pszpath;
for ( int i = 0; i < d->field_count(); i++ ) {
auto field
I think the easiest thing would be that wherever you're now storing a
google::protobuf::FieldDescriptor*, you can also store a
google::protobuf::Message* pointing to the parent message.
On Tue, Jun 22, 2021 at 10:41 AM J G wrote:
> Hi Adam,
>
> Yes, the HealthReport variable is the parent, and
Hi Adam,
Yes, the HealthReport variable is the parent, and it contains a
HardwareComponent variable, but I am enumerating the from the parent,
meaning I am trying to not hard-code the structure of the contained items.
So how would I obtain a pointer to the message for each leaf without
So is it correct that HealthReport is the top-level message type and
HardwareComponent is nested somewhere within that? I think what you're
trying to do is doable, but when you call reflection->SetString(), you have
to pass the immediate parent message containing the field, not the
top-level
Hi again Adam, and thank you for taking the time to help me.
Maybe I haven't explained what I am trying to do properly.
I have a protobuf variable, which itself is composed of more nested
variables.
I am enumerating the fields of the variable.
Where the item is a leaf, the field is a simple
It looks to me like r->report points to a vafmsg.HealthReport but the field
descriptor refers to a field in another message (vafmsg.HardwareComponent).
On Tue, Jun 22, 2021 at 7:42 AM J G wrote:
> Hello Adam,
>
> OK, I understand, so I've tried this, but I get an error.
>
> void my_set_value(
Hello Adam,
OK, I understand, so I've tried this, but I get an error.
void my_set_value( class healthreport * r, const char * defaultvalue, const
google::protobuf::FieldDescriptor * descriptor ) {
auto reflection = r->report->GetReflection();
switch( descriptor->type() ) {
Each descriptor describes part of the schema (e.g. a message type, enum
type, etc.) but is unrelated to any particular instance of it. As a result,
if you have a descriptor by itself then you can't really modify anything
because you separately need an instance of the thing you want to modify.
The
12 matches
Mail list logo