Hi protobuf experts,

Let's say I have a message defined like this:


message Foo {
  // ...
  extensions 100 to 199;
}


Given an instance foo of Foo (or any message really), I was wondering if there 
was a straightforward elegant way to test if any extensions had been set rather 
than do this (WARNING: i'm not sure this code compiles...):


bool HasExtensions(const proto2::Message& msg) {

const proto2::Reflection* reflection = msg.GetReflection(); vector<const 
proto2::FieldDescriptor*> fields; reflection->ListFields(msg, &fields); for 
(auto field : fields) { if (field->is_extension()) {

      return true;
    }
  }

  return false;

}


if (!HasExtensions(foo)) {

  ...

}


Thanks much,


    Julien.

-- 
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 http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to