title: How to define and (de)serialize an IPAddress in protobuf / C#?
body: <pre><code>public class Example
  {
      public DateTime Date { get; set; }
      public IPAddress Ip { get; set; }
      public string ExampleDescription { get; set; }
  }
  </code></pre>
  <p>And the <code>.proto</code>:</p>
  <pre><code>syntax = &quot;proto3&quot;;
  package example;
  
  import &quot;google/protobuf/timestamp.proto&quot;;
  
  message Register {
      google.protobuf.Timestamp Date = 1;
      ??? Ip = 2;
      string ExampleDescription = 3;
  }
  </code></pre>
  <p>I would like to send the above example message from client &lt;-&gt; server over UDP using Protobuf and I'm not sure how I would handle an IPAddress correctly. I could serialize it as string (which would probably improve interop with other languages) but I've also seen a <code>.proto</code> like:</p>
  <pre><code>oneof ip_addr {
      fixed32 v4 = 1;
      bytes v6 = 2;
  }
  </code></pre>
  <p>I would prefer to keep my (above 'example') class intact. I also need to support both IPv4 and IPv6. I prefer small, optimal, messages and (de)serialization since I'm processing many thousands p/sec and I expect that number to go up in the future.</p>
  <p>Either way ((de)serializing as string or using the <code>oneof</code> method), I'll need to implement my own custom (de)serializer for this? What would be the best way to go about that or does anyone have a pointer to a good tutorial/documentation on how to implement this in C#?</p>
  <p>Also in the future I might want to use an <code>IpEndpoint</code>; I would probably re-use the &quot;ip proto&quot; and stick an <code>int32 Port</code> on it?</p>