title: What is the most efficient protobuf type (in C++) for storing ipv4 or ipv6 address? My address is a boost::asio::ip::address_v4 (or v6)
body: <p>I read that protobuf has a type called "<strong>bytes</strong>" which can store arbitrary number of bytes and is the equivalent of "C++ string". The reason why I don't prefer to use "bytes" is that it expects input as a C++ string i.e., boost IP will need to be converted to a string. Now my concern lies here : I want to perform serialize and send the encoded protobuf message over TCP socket. I want to ensure that the <strong>encoded message size is as small as possible</strong>.</p>
  
  <p>Currently, I am using the below .proto file :</p>
  
  <pre><code>syntax = "proto2";
  
  message profile
  
  {
  
  repeated **uint32** localEndpoint = 1;
  
  repeated **uint32** remoteEndpoint = 2;
  
  }
  </code></pre>
  
  <p>In order to save boost IP in the protobuf message, I am first converting boost IP into byte-format array by using "boost::asio::ip::address_v4::to_bytes()". So for a v4 IP, resultant array size is 4. Then I am converting 1st 4 bytes from the resultant byte-array into one uint32_t number and then storing in "localEndpoint" field of the protobuf message. Likewise, I repeat for the next 4 bytes (for v6). I am taking 4 bytes at a time so as to utilize full 32 bits of the uint32.</p>
  
  <p>Hence for a v4 address, 1 occurrence of "localEndpoint" field is used.
  Similarly, for a v6 address, 4 occurrence of "localEndpoint" field is used.</p>
  
  <p>Please allow me to highlight that if I had used "bytes" here, my input string itself would have been of size 15 bytes for a v4 ip like 111.111.111.111</p>
  
  <p>Using uint32 instead of "bytes" does save me some encoded-data-size but I am looking for a more efficient protobuf type requiring lesser number of bytes.</p>
  
  <p>Sorry for a long description but I wanted to explain my query in details. Please help me.. Thanks a lot in advance :)</p>