title: Getting tag number of a field in google protobuf
body: <p>How to get the tag number of a particular field from a protobuf object after compiling into a C++ class?</p>
  
  <p>Consider the below example protobuf message and I had compiled this message to get the corresponding C++ header for <em>Person</em> class</p>
  
  <p>File: <em>person.proto</em></p>
  
  <pre><code>message Person {
    required string name = 1;
    required int32 id = 2;
    optional string email = 3;
  }
  </code></pre>
  
  <p>In my C++ code</p>
  
  <pre><code>Person *foo = new Person();
  foo-&gt;set_id(123);
  foo-&gt;set_name("bar");
  foo-&gt;set_email("baz@qux.com");
  </code></pre>
  
  <p>Now I want to get the tag number of each field in the person message like the below one</p>
  
  <pre><code>int tag_id = foo-&gt;some_method_to_get_tag_number_of_id(); \\tag number of id is 1
  int tag_name = foo-&gt;some_method_to_get_tag_number_of_name(); \\tag number is 2
  int tag_email = foo-&gt;some_method_to_get_tag_number_of_email(); \\tag number is 3
  </code></pre>
  
  <p>Is it possible to get the tag number, if so how?</p>