jeudi 24 septembre 2015

Retrieve the field name in the parent message with a field descriptor using Protocol Buffers

Is it possible with Google Protocol Buffers to retrieve the field name (not the field type) of the parent message by using descriptors in C++?

Consider the following minimal example:

message MessageHeader {
  string addressee = 1;
}

message Message {
  MessageHeader header = 1;
}

I want to retrieve the string "header.addresse" with the following function:

std::string createFieldQueryFrom(
    const google::protobuf::FieldDescriptor* const descriptor)
{
  // TODO(wolters): The descriptor for the containing FIELD is required. Is
  // there a way to retrieve it?
  //
  // containing_descriptor->name() returns "Message", what I want is
  // "header"!
  const google::protobuf::Descriptor* containing_descriptor{
      descriptor->containing_type()};

  // TODO(wolters): Add recursion if able to get the actual attribute name of
  // the containing FIELD.

  return "";
}

  1. Is this possible, or doesn't a google::protobuf::FieldDescriptor instance provide the information required to fulfil that task?
  2. If the answer to 1. is no: Is this possible at all (if so, can you provide me an example)?




Aucun commentaire:

Enregistrer un commentaire