title: How to choose a field number when using protobuf-net inheritance?
body: <p>I'm using protobuf-net for serializing a number of types, some of which are inherited from a base type. I know that the Protocol Buffers spec does not support inheritance, and that the support in protobuf-net is basically a workaround because of that.</p>
  
  <p>Rather than using the protobuf-net attributes I am configuring a custom <code>RuntimeTypeModel</code>, and using the <code>Add</code> and <code>AddSubType</code> methods. What I'm not quite grasping is <em>how I should determine which numbers to use</em> for the field numbers passed to the <code>AddSubType</code> method (aka the number that would be used in a <code>ProtoInclude</code> attribute).</p>
  
  <p><a href="https://stackoverflow.com/q/9278146/4265041">This SO question</a> and several others like it do not really describe how the field numbers are chosen, and indeed I've seen many different variations: 4 &amp; 5; 7 &amp; 8; 101 &amp; 102 &amp; 103; 20; 500; etc. Obviously they're chosen so as not to clash with one another, but <em>how</em> are they chosen? What determines which number to start at?</p>
  
  <p>The following code is a contrived example but it does match my heirarchy (a base <code>Event</code> type that has two derived subtypes).</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using ProtoBuf.Meta;
  
  namespace Test
  {
      public sealed class History
      {
          public History()
          {
              Events = new List&lt;Event&gt;();
          }
  
          public ICollection&lt;Event&gt; Events { get; private set; }
      }
  
      public enum EventType
      {
          ConcertStarted, ConcertFinished, SongPlayed
      }
  
      public class Event
      {
          public EventType Type { get; set; }
          public DateTimeOffset Timestamp { get; set; }
      }
  
      public sealed class Concert : Event
      {
          public string Location { get; set; }
      }
  
      public sealed class Song : Event
      {
          public string Name { get; set; }
      }
  
      public static class ModelFactory
      {
          public static RuntimeTypeModel CreateModel()
          {
              RuntimeTypeModel model = TypeModel.Create();
              model.Add(typeof(DateTimeOffset), applyDefaultBehaviour: false)
                  .SetSurrogate(typeof(DateTimeOffsetSurrogate));
              model.Add(typeof(History), applyDefaultBehaviour: false)
                  .Add("Events");
              model.Add(typeof(Concert), applyDefaultBehaviour: false)
                  .Add("Location");
              model.Add(typeof(Song), applyDefaultBehaviour: false)
                  .Add("Name");
              model.Add(typeof(Event), applyDefaultBehaviour: false)
                  .Add("Type", "Timestamp")
                  .AddSubType(???, typeof(Concert))
                  .AddSubType(???, typeof(Song));
              return model;
          }
      }
  }
  </code></pre>