// <auto-generated>
//     Generated by the protocol buffer compiler.  DO NOT EDIT!
//     source: csharp/protos/unittest.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code

using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace Google.Protobuf.TestProtos.Proto2 {

  /// <summary>Holder for reflection information generated from csharp/protos/unittest.proto</summary>
  public static partial class UnittestReflection {

    #region Descriptor
    /// <summary>File descriptor for csharp/protos/unittest.proto</summary>
    public static pbr::FileDescriptor Descriptor {
      get { return descriptor; }
    }
    private static pbr::FileDescriptor descriptor;

    static UnittestReflection() {
      byte[] descriptorData = global::System.Convert.FromBase64String(
          string.Concat(
            "Chxjc2hhcnAvcHJvdG9zL3VuaXR0ZXN0LnByb3RvEhhwcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIaI2NzaGFycC9wcm90b3MvdW5pdHRlc3RfaW1wb3J0LnBy",
            "b3RvIoAaCgxUZXN0QWxsVHlwZXMSFgoOb3B0aW9uYWxfaW50MzIYASABKAUS",
            "FgoOb3B0aW9uYWxfaW50NjQYAiABKAMSFwoPb3B0aW9uYWxfdWludDMyGAMg",
            "ASgNEhcKD29wdGlvbmFsX3VpbnQ2NBgEIAEoBBIXCg9vcHRpb25hbF9zaW50",
            "MzIYBSABKBESFwoPb3B0aW9uYWxfc2ludDY0GAYgASgSEhgKEG9wdGlvbmFs",
            "X2ZpeGVkMzIYByABKAcSGAoQb3B0aW9uYWxfZml4ZWQ2NBgIIAEoBhIZChFv",
            "cHRpb25hbF9zZml4ZWQzMhgJIAEoDxIZChFvcHRpb25hbF9zZml4ZWQ2NBgK",
            "IAEoEBIWCg5vcHRpb25hbF9mbG9hdBgLIAEoAhIXCg9vcHRpb25hbF9kb3Vi",
            "bGUYDCABKAESFQoNb3B0aW9uYWxfYm9vbBgNIAEoCBIXCg9vcHRpb25hbF9z",
            "dHJpbmcYDiABKAkSFgoOb3B0aW9uYWxfYnl0ZXMYDyABKAwSSwoNb3B0aW9u",
            "YWxncm91cBgQIAEoCjI0LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0",
            "QWxsVHlwZXMuT3B0aW9uYWxHcm91cBJVChdvcHRpb25hbF9uZXN0ZWRfbWVz",
            "c2FnZRgSIAEoCzI0LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxs",
            "VHlwZXMuTmVzdGVkTWVzc2FnZRJKChhvcHRpb25hbF9mb3JlaWduX21lc3Nh",
            "Z2UYEyABKAsyKC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbk1l",
            "c3NhZ2USTwoXb3B0aW9uYWxfaW1wb3J0X21lc3NhZ2UYFCABKAsyLi5wcm90",
            "b2J1Zl91bml0dGVzdF9pbXBvcnRfcHJvdG8yLkltcG9ydE1lc3NhZ2USTwoU",
            "b3B0aW9uYWxfbmVzdGVkX2VudW0YFSABKA4yMS5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdEFsbFR5cGVzLk5lc3RlZEVudW0SRAoVb3B0aW9uYWxf",
            "Zm9yZWlnbl9lbnVtGBYgASgOMiUucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LkZvcmVpZ25FbnVtEkkKFG9wdGlvbmFsX2ltcG9ydF9lbnVtGBcgASgOMisu",
            "cHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0X3Byb3RvMi5JbXBvcnRFbnVtEiEK",
            "FW9wdGlvbmFsX3N0cmluZ19waWVjZRgYIAEoCUICCAISGQoNb3B0aW9uYWxf",
            "Y29yZBgZIAEoCUICCAESXAoeb3B0aW9uYWxfcHVibGljX2ltcG9ydF9tZXNz",
            "YWdlGBogASgLMjQucHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0X3Byb3RvMi5Q",
            "dWJsaWNJbXBvcnRNZXNzYWdlElcKFW9wdGlvbmFsX2xhenlfbWVzc2FnZRgb",
            "IAEoCzI0LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMu",
            "TmVzdGVkTWVzc2FnZUICKAESFgoOcmVwZWF0ZWRfaW50MzIYHyADKAUSFgoO",
            "cmVwZWF0ZWRfaW50NjQYICADKAMSFwoPcmVwZWF0ZWRfdWludDMyGCEgAygN",
            "EhcKD3JlcGVhdGVkX3VpbnQ2NBgiIAMoBBIXCg9yZXBlYXRlZF9zaW50MzIY",
            "IyADKBESFwoPcmVwZWF0ZWRfc2ludDY0GCQgAygSEhgKEHJlcGVhdGVkX2Zp",
            "eGVkMzIYJSADKAcSGAoQcmVwZWF0ZWRfZml4ZWQ2NBgmIAMoBhIZChFyZXBl",
            "YXRlZF9zZml4ZWQzMhgnIAMoDxIZChFyZXBlYXRlZF9zZml4ZWQ2NBgoIAMo",
            "EBIWCg5yZXBlYXRlZF9mbG9hdBgpIAMoAhIXCg9yZXBlYXRlZF9kb3VibGUY",
            "KiADKAESFQoNcmVwZWF0ZWRfYm9vbBgrIAMoCBIXCg9yZXBlYXRlZF9zdHJp",
            "bmcYLCADKAkSFgoOcmVwZWF0ZWRfYnl0ZXMYLSADKAwSSwoNcmVwZWF0ZWRn",
            "cm91cBguIAMoCjI0LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxs",
            "VHlwZXMuUmVwZWF0ZWRHcm91cBJVChdyZXBlYXRlZF9uZXN0ZWRfbWVzc2Fn",
            "ZRgwIAMoCzI0LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlw",
            "ZXMuTmVzdGVkTWVzc2FnZRJKChhyZXBlYXRlZF9mb3JlaWduX21lc3NhZ2UY",
            "MSADKAsyKC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbk1lc3Nh",
            "Z2USTwoXcmVwZWF0ZWRfaW1wb3J0X21lc3NhZ2UYMiADKAsyLi5wcm90b2J1",
            "Zl91bml0dGVzdF9pbXBvcnRfcHJvdG8yLkltcG9ydE1lc3NhZ2USTwoUcmVw",
            "ZWF0ZWRfbmVzdGVkX2VudW0YMyADKA4yMS5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdEFsbFR5cGVzLk5lc3RlZEVudW0SRAoVcmVwZWF0ZWRfZm9y",
            "ZWlnbl9lbnVtGDQgAygOMiUucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLkZv",
            "cmVpZ25FbnVtEkkKFHJlcGVhdGVkX2ltcG9ydF9lbnVtGDUgAygOMisucHJv",
            "dG9idWZfdW5pdHRlc3RfaW1wb3J0X3Byb3RvMi5JbXBvcnRFbnVtEiEKFXJl",
            "cGVhdGVkX3N0cmluZ19waWVjZRg2IAMoCUICCAISGQoNcmVwZWF0ZWRfY29y",
            "ZBg3IAMoCUICCAESVwoVcmVwZWF0ZWRfbGF6eV9tZXNzYWdlGDkgAygLMjQu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxUeXBlcy5OZXN0ZWRN",
            "ZXNzYWdlQgIoARIZCg1kZWZhdWx0X2ludDMyGD0gASgFOgI0MRIZCg1kZWZh",
            "dWx0X2ludDY0GD4gASgDOgI0MhIaCg5kZWZhdWx0X3VpbnQzMhg/IAEoDToC",
            "NDMSGgoOZGVmYXVsdF91aW50NjQYQCABKAQ6AjQ0EhsKDmRlZmF1bHRfc2lu",
            "dDMyGEEgASgROgMtNDUSGgoOZGVmYXVsdF9zaW50NjQYQiABKBI6AjQ2EhsK",
            "D2RlZmF1bHRfZml4ZWQzMhhDIAEoBzoCNDcSGwoPZGVmYXVsdF9maXhlZDY0",
            "GEQgASgGOgI0OBIcChBkZWZhdWx0X3NmaXhlZDMyGEUgASgPOgI0ORIdChBk",
            "ZWZhdWx0X3NmaXhlZDY0GEYgASgQOgMtNTASGwoNZGVmYXVsdF9mbG9hdBhH",
            "IAEoAjoENTEuNRIdCg5kZWZhdWx0X2RvdWJsZRhIIAEoAToFNTIwMDASGgoM",
            "ZGVmYXVsdF9ib29sGEkgASgIOgR0cnVlEh0KDmRlZmF1bHRfc3RyaW5nGEog",
            "ASgJOgVoZWxsbxIcCg1kZWZhdWx0X2J5dGVzGEsgASgMOgV3b3JsZBJTChNk",
            "ZWZhdWx0X25lc3RlZF9lbnVtGFEgASgOMjEucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RBbGxUeXBlcy5OZXN0ZWRFbnVtOgNCQVISUAoUZGVmYXVs",
            "dF9mb3JlaWduX2VudW0YUiABKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90",
            "bzIuRm9yZWlnbkVudW06C0ZPUkVJR05fQkFSElQKE2RlZmF1bHRfaW1wb3J0",
            "X2VudW0YUyABKA4yKy5wcm90b2J1Zl91bml0dGVzdF9pbXBvcnRfcHJvdG8y",
            "LkltcG9ydEVudW06CklNUE9SVF9CQVISJQoUZGVmYXVsdF9zdHJpbmdfcGll",
            "Y2UYVCABKAk6A2FiY0ICCAISHQoMZGVmYXVsdF9jb3JkGFUgASgJOgMxMjNC",
            "AggBEhYKDG9uZW9mX3VpbnQzMhhvIAEoDUgAElQKFG9uZW9mX25lc3RlZF9t",
            "ZXNzYWdlGHAgASgLMjQucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RB",
            "bGxUeXBlcy5OZXN0ZWRNZXNzYWdlSAASFgoMb25lb2Zfc3RyaW5nGHEgASgJ",
            "SAASFQoLb25lb2ZfYnl0ZXMYciABKAxIABobCg1OZXN0ZWRNZXNzYWdlEgoK",
            "AmJiGAEgASgFGhoKDU9wdGlvbmFsR3JvdXASCQoBYRgRIAEoBRoaCg1SZXBl",
            "YXRlZEdyb3VwEgkKAWEYLyABKAUiOQoKTmVzdGVkRW51bRIHCgNGT08QARIH",
            "CgNCQVIQAhIHCgNCQVoQAxIQCgNORUcQ////////////AUINCgtvbmVvZl9m",
            "aWVsZCLQAQoSTmVzdGVkVGVzdEFsbFR5cGVzEjsKBWNoaWxkGAEgASgLMiwu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLk5lc3RlZFRlc3RBbGxUeXBlcxI3",
            "CgdwYXlsb2FkGAIgASgLMiYucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRl",
            "c3RBbGxUeXBlcxJECg5yZXBlYXRlZF9jaGlsZBgDIAMoCzIsLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5OZXN0ZWRUZXN0QWxsVHlwZXMibQoUVGVzdERl",
            "cHJlY2F0ZWRGaWVsZHMSHAoQZGVwcmVjYXRlZF9pbnQzMhgBIAEoBUICGAES",
            "JwoZZGVwcmVjYXRlZF9pbnQzMl9pbl9vbmVvZhgCIAEoBUICGAFIAEIOCgxv",
            "bmVvZl9maWVsZHMiGwoVVGVzdERlcHJlY2F0ZWRNZXNzYWdlOgIYASImCg5G",
            "b3JlaWduTWVzc2FnZRIJCgFjGAEgASgFEgkKAWQYAiABKAUiMAoSVGVzdFJl",
            "c2VydmVkRmllbGRzSgQIAhADSgQIDxAQSgQICRAMUgNiYXJSA2JheiIdChFU",
            "ZXN0QWxsRXh0ZW5zaW9ucyoICAEQgICAgAIiJAoXT3B0aW9uYWxHcm91cF9l",
            "eHRlbnNpb24SCQoBYRgRIAEoBSIkChdSZXBlYXRlZEdyb3VwX2V4dGVuc2lv",
            "bhIJCgFhGC8gASgFIrcBCglUZXN0R3JvdXASSAoNb3B0aW9uYWxncm91cBgQ",
            "IAEoCjIxLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0R3JvdXAuT3B0",
            "aW9uYWxHcm91cBJEChVvcHRpb25hbF9mb3JlaWduX2VudW0YFiABKA4yJS5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW0aGgoNT3B0aW9u",
            "YWxHcm91cBIJCgFhGBEgASgFIh4KElRlc3RHcm91cEV4dGVuc2lvbioICAEQ",
            "gICAgAIi4QMKE1Rlc3ROZXN0ZWRFeHRlbnNpb24aJAoXT3B0aW9uYWxHcm91",
            "cF9leHRlbnNpb24SCQoBYRgRIAEoBTJACgR0ZXN0EisucHJvdG9idWZfdW5p",
            "dHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGOoHIAEoCToEdGVzdDJN",
            "ChduZXN0ZWRfc3RyaW5nX2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxjrByABKAkylAEKF29wdGlvbmFs",
            "Z3JvdXBfZXh0ZW5zaW9uEiwucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRl",
            "c3RHcm91cEV4dGVuc2lvbhgQIAEoCjJFLnByb3RvYnVmX3VuaXR0ZXN0X3By",
            "b3RvMi5UZXN0TmVzdGVkRXh0ZW5zaW9uLk9wdGlvbmFsR3JvdXBfZXh0ZW5z",
            "aW9uMnwKH29wdGlvbmFsX2ZvcmVpZ25fZW51bV9leHRlbnNpb24SLC5wcm90",
            "b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEdyb3VwRXh0ZW5zaW9uGBYgASgO",
            "MiUucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLkZvcmVpZ25FbnVtIvEFCgxU",
            "ZXN0UmVxdWlyZWQSCQoBYRgBIAIoBRIOCgZkdW1teTIYAiABKAUSCQoBYhgD",
            "IAIoBRIOCgZkdW1teTQYBCABKAUSDgoGZHVtbXk1GAUgASgFEg4KBmR1bW15",
            "NhgGIAEoBRIOCgZkdW1teTcYByABKAUSDgoGZHVtbXk4GAggASgFEg4KBmR1",
            "bW15ORgJIAEoBRIPCgdkdW1teTEwGAogASgFEg8KB2R1bW15MTEYCyABKAUS",
            "DwoHZHVtbXkxMhgMIAEoBRIPCgdkdW1teTEzGA0gASgFEg8KB2R1bW15MTQY",
            "DiABKAUSDwoHZHVtbXkxNRgPIAEoBRIPCgdkdW1teTE2GBAgASgFEg8KB2R1",
            "bW15MTcYESABKAUSDwoHZHVtbXkxOBgSIAEoBRIPCgdkdW1teTE5GBMgASgF",
            "Eg8KB2R1bW15MjAYFCABKAUSDwoHZHVtbXkyMRgVIAEoBRIPCgdkdW1teTIy",
            "GBYgASgFEg8KB2R1bW15MjMYFyABKAUSDwoHZHVtbXkyNBgYIAEoBRIPCgdk",
            "dW1teTI1GBkgASgFEg8KB2R1bW15MjYYGiABKAUSDwoHZHVtbXkyNxgbIAEo",
            "BRIPCgdkdW1teTI4GBwgASgFEg8KB2R1bW15MjkYHSABKAUSDwoHZHVtbXkz",
            "MBgeIAEoBRIPCgdkdW1teTMxGB8gASgFEg8KB2R1bW15MzIYICABKAUSCQoB",
            "YxghIAIoBTJkCgZzaW5nbGUSKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbEV4dGVuc2lvbnMY6AcgASgLMiYucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RSZXF1aXJlZDJjCgVtdWx0aRIrLnByb3RvYnVmX3VuaXR0",
            "ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxjpByADKAsyJi5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuVGVzdFJlcXVpcmVkIqgBChNUZXN0UmVxdWly",
            "ZWRGb3JlaWduEkAKEG9wdGlvbmFsX21lc3NhZ2UYASABKAsyJi5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuVGVzdFJlcXVpcmVkEkAKEHJlcGVhdGVkX21l",
            "c3NhZ2UYAiADKAsyJi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdFJl",
            "cXVpcmVkEg0KBWR1bW15GAMgASgFItsBChNUZXN0UmVxdWlyZWRNZXNzYWdl",
            "EkAKEG9wdGlvbmFsX21lc3NhZ2UYASABKAsyJi5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdFJlcXVpcmVkEkAKEHJlcGVhdGVkX21lc3NhZ2UYAiAD",
            "KAsyJi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdFJlcXVpcmVkEkAK",
            "EHJlcXVpcmVkX21lc3NhZ2UYAyACKAsyJi5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdFJlcXVpcmVkImEKEVRlc3RGb3JlaWduTmVzdGVkEkwKDmZv",
            "cmVpZ25fbmVzdGVkGAEgASgLMjQucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RBbGxUeXBlcy5OZXN0ZWRNZXNzYWdlIhIKEFRlc3RFbXB0eU1lc3Nh",
            "Z2UiKgoeVGVzdEVtcHR5TWVzc2FnZVdpdGhFeHRlbnNpb25zKggIARCAgICA",
            "AiI3ChtUZXN0TXVsdGlwbGVFeHRlbnNpb25SYW5nZXMqBAgqECsqBgivIBCU",
            "ISoKCICABBCAgICAAiI0ChhUZXN0UmVhbGx5TGFyZ2VUYWdOdW1iZXISCQoB",
            "YRgBIAEoBRINCgJiYhj///9/IAEoBSJcChRUZXN0UmVjdXJzaXZlTWVzc2Fn",
            "ZRI5CgFhGAEgASgLMi4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RS",
            "ZWN1cnNpdmVNZXNzYWdlEgkKAWkYAiABKAUihAMKFFRlc3RNdXR1YWxSZWN1",
            "cnNpb25BEjoKAmJiGAEgASgLMi4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RNdXR1YWxSZWN1cnNpb25CEkkKCHN1Ymdyb3VwGAIgASgKMjcucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RNdXR1YWxSZWN1cnNpb25BLlN1",
            "Ykdyb3VwGkcKClN1Yk1lc3NhZ2USOQoBYhgBIAEoCzIuLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0TXV0dWFsUmVjdXJzaW9uQhqbAQoIU3ViR3Jv",
            "dXASTgoLc3ViX21lc3NhZ2UYAyABKAsyOS5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdE11dHVhbFJlY3Vyc2lvbkEuU3ViTWVzc2FnZRI/Cg9ub3Rf",
            "aW5fdGhpc19zY2MYBCABKAsyJi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbFR5cGVzImkKFFRlc3RNdXR1YWxSZWN1cnNpb25CEjkKAWEYASAB",
            "KAsyLi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdE11dHVhbFJlY3Vy",
            "c2lvbkESFgoOb3B0aW9uYWxfaW50MzIYAiABKAUi2AEKEVRlc3RJc0luaXRp",
            "YWxpemVkEksKC3N1Yl9tZXNzYWdlGAEgASgLMjYucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RJc0luaXRpYWxpemVkLlN1Yk1lc3NhZ2UadgoKU3Vi",
            "TWVzc2FnZRJRCghzdWJncm91cBgBIAEoCjI/LnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0SXNJbml0aWFsaXplZC5TdWJNZXNzYWdlLlN1Ykdyb3Vw",
            "GhUKCFN1Ykdyb3VwEgkKAWkYAiACKAUiwQEKElRlc3REdXBGaWVsZE51bWJl",
            "chIJCgFhGAEgASgFEj0KA2ZvbxgCIAEoCjIwLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0RHVwRmllbGROdW1iZXIuRm9vEj0KA2JhchgDIAEoCjIw",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0RHVwRmllbGROdW1iZXIu",
            "QmFyGhAKA0ZvbxIJCgFhGAEgASgFGhAKA0JhchIJCgFhGAEgASgFIlMKEFRl",
            "c3RFYWdlck1lc3NhZ2USPwoLc3ViX21lc3NhZ2UYASABKAsyJi5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVzQgIoACJSCg9UZXN0TGF6",
            "eU1lc3NhZ2USPwoLc3ViX21lc3NhZ2UYASABKAsyJi5wcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVzQgIoASKOAgoYVGVzdE5lc3RlZE1l",
            "c3NhZ2VIYXNCaXRzEmEKF29wdGlvbmFsX25lc3RlZF9tZXNzYWdlGAEgASgL",
            "MkAucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3ROZXN0ZWRNZXNzYWdl",
            "SGFzQml0cy5OZXN0ZWRNZXNzYWdlGo4BCg1OZXN0ZWRNZXNzYWdlEiQKHG5l",
            "c3RlZG1lc3NhZ2VfcmVwZWF0ZWRfaW50MzIYASADKAUSVwolbmVzdGVkbWVz",
            "c2FnZV9yZXBlYXRlZF9mb3JlaWdubWVzc2FnZRgCIAMoCzIoLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5Gb3JlaWduTWVzc2FnZSKBBAoXVGVzdENhbWVs",
            "Q2FzZUZpZWxkTmFtZXMSFgoOUHJpbWl0aXZlRmllbGQYASABKAUSEwoLU3Ry",
            "aW5nRmllbGQYAiABKAkSOAoJRW51bUZpZWxkGAMgASgOMiUucHJvdG9idWZf",
            "dW5pdHRlc3RfcHJvdG8yLkZvcmVpZ25FbnVtEj4KDE1lc3NhZ2VGaWVsZBgE",
            "IAEoCzIoLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5Gb3JlaWduTWVzc2Fn",
            "ZRIcChBTdHJpbmdQaWVjZUZpZWxkGAUgASgJQgIIAhIVCglDb3JkRmllbGQY",
            "BiABKAlCAggBEh4KFlJlcGVhdGVkUHJpbWl0aXZlRmllbGQYByADKAUSGwoT",
            "UmVwZWF0ZWRTdHJpbmdGaWVsZBgIIAMoCRJAChFSZXBlYXRlZEVudW1GaWVs",
            "ZBgJIAMoDjIlLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5Gb3JlaWduRW51",
            "bRJGChRSZXBlYXRlZE1lc3NhZ2VGaWVsZBgKIAMoCzIoLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5Gb3JlaWduTWVzc2FnZRIkChhSZXBlYXRlZFN0cmlu",
            "Z1BpZWNlRmllbGQYCyADKAlCAggCEh0KEVJlcGVhdGVkQ29yZEZpZWxkGAwg",
            "AygJQgIIASLcAQoSVGVzdEZpZWxkT3JkZXJpbmdzEhEKCW15X3N0cmluZxgL",
            "IAEoCRIOCgZteV9pbnQYASABKAMSEAoIbXlfZmxvYXQYZSABKAISXAoXb3B0",
            "aW9uYWxfbmVzdGVkX21lc3NhZ2UYyAEgASgLMjoucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RGaWVsZE9yZGVyaW5ncy5OZXN0ZWRNZXNzYWdlGicK",
            "DU5lc3RlZE1lc3NhZ2USCgoCb28YAiABKAMSCgoCYmIYASABKAUqBAgCEAsq",
            "BAgMEGUiqgEKF1Rlc3RFeHRlbnNpb25PcmRlcmluZ3MxEhEKCW15X3N0cmlu",
            "ZxgBIAEoCTJ8ChN0ZXN0X2V4dF9vcmRlcmluZ3MxEiwucHJvdG9idWZfdW5p",
            "dHRlc3RfcHJvdG8yLlRlc3RGaWVsZE9yZGVyaW5ncxgNIAEoCzIxLnByb3Rv",
            "YnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0RXh0ZW5zaW9uT3JkZXJpbmdzMSLw",
            "AgoXVGVzdEV4dGVuc2lvbk9yZGVyaW5nczISEQoJbXlfc3RyaW5nGAEgASgJ",
            "GsMBChdUZXN0RXh0ZW5zaW9uT3JkZXJpbmdzMxIRCglteV9zdHJpbmcYASAB",
            "KAkylAEKE3Rlc3RfZXh0X29yZGVyaW5nczMSLC5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdEZpZWxkT3JkZXJpbmdzGA4gASgLMkkucHJvdG9idWZf",
            "dW5pdHRlc3RfcHJvdG8yLlRlc3RFeHRlbnNpb25PcmRlcmluZ3MyLlRlc3RF",
            "eHRlbnNpb25PcmRlcmluZ3MzMnwKE3Rlc3RfZXh0X29yZGVyaW5nczISLC5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEZpZWxkT3JkZXJpbmdzGAwg",
            "ASgLMjEucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RFeHRlbnNpb25P",
            "cmRlcmluZ3MyIrYHChhUZXN0RXh0cmVtZURlZmF1bHRWYWx1ZXMSPwoNZXNj",
            "YXBlZF9ieXRlcxgBIAEoDDooXDAwMFwwMDFcMDA3XDAxMFwwMTRcblxyXHRc",
            "MDEzXFxcJ1wiXDM3NhIgCgxsYXJnZV91aW50MzIYAiABKA06CjQyOTQ5Njcy",
            "OTUSKgoMbGFyZ2VfdWludDY0GAMgASgEOhQxODQ0Njc0NDA3MzcwOTU1MTYx",
            "NRIgCgtzbWFsbF9pbnQzMhgEIAEoBToLLTIxNDc0ODM2NDcSKQoLc21hbGxf",
            "aW50NjQYBSABKAM6FC05MjIzMzcyMDM2ODU0Nzc1ODA3EicKEnJlYWxseV9z",
            "bWFsbF9pbnQzMhgVIAEoBToLLTIxNDc0ODM2NDgSMAoScmVhbGx5X3NtYWxs",
            "X2ludDY0GBYgASgDOhQtOTIyMzM3MjAzNjg1NDc3NTgwOBIYCgt1dGY4X3N0",
            "cmluZxgGIAEoCToD4Yi0EhUKCnplcm9fZmxvYXQYByABKAI6ATASFAoJb25l",
            "X2Zsb2F0GAggASgCOgExEhgKC3NtYWxsX2Zsb2F0GAkgASgCOgMxLjUSHgoS",
            "bmVnYXRpdmVfb25lX2Zsb2F0GAogASgCOgItMRIcCg5uZWdhdGl2ZV9mbG9h",
            "dBgLIAEoAjoELTEuNRIaCgtsYXJnZV9mbG9hdBgMIAEoAjoFMmUrMDgSJAoU",
            "c21hbGxfbmVnYXRpdmVfZmxvYXQYDSABKAI6Bi04ZS0yOBIXCgppbmZfZG91",
            "YmxlGA4gASgBOgNpbmYSHAoObmVnX2luZl9kb3VibGUYDyABKAE6BC1pbmYS",
            "FwoKbmFuX2RvdWJsZRgQIAEoAToDbmFuEhYKCWluZl9mbG9hdBgRIAEoAjoD",
            "aW5mEhsKDW5lZ19pbmZfZmxvYXQYEiABKAI6BC1pbmYSFgoJbmFuX2Zsb2F0",
            "GBMgASgCOgNuYW4SKwoMY3BwX3RyaWdyYXBoGBQgASgJOhU/ID8gPz8gPz8g",
            "Pz8/ID8/LyA/Py0SIAoQc3RyaW5nX3dpdGhfemVybxgXIAEoCToGaGVsAGxv",
            "EiIKD2J5dGVzX3dpdGhfemVybxgYIAEoDDoJd29yXDAwMGxkEigKFnN0cmlu",
            "Z19waWVjZV93aXRoX3plcm8YGSABKAk6BGFiAGNCAggCEiAKDmNvcmRfd2l0",
            "aF96ZXJvGBogASgJOgQxMgAzQgIIARImChJyZXBsYWNlbWVudF9zdHJpbmcY",
            "GyABKAk6CiR7dW5rbm93bn0iUgoRU3BhcnNlRW51bU1lc3NhZ2USPQoLc3Bh",
            "cnNlX2VudW0YASABKA4yKC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVz",
            "dFNwYXJzZUVudW0iGQoJT25lU3RyaW5nEgwKBGRhdGEYASABKAkiGgoKTW9y",
            "ZVN0cmluZxIMCgRkYXRhGAEgAygJIhgKCE9uZUJ5dGVzEgwKBGRhdGEYASAB",
            "KAwiGQoJTW9yZUJ5dGVzEgwKBGRhdGEYASADKAwiHAoMSW50MzJNZXNzYWdl",
            "EgwKBGRhdGEYASABKAUiHQoNVWludDMyTWVzc2FnZRIMCgRkYXRhGAEgASgN",
            "IhwKDEludDY0TWVzc2FnZRIMCgRkYXRhGAEgASgDIh0KDVVpbnQ2NE1lc3Nh",
            "Z2USDAoEZGF0YRgBIAEoBCIbCgtCb29sTWVzc2FnZRIMCgRkYXRhGAEgASgI",
            "It4BCglUZXN0T25lb2YSEQoHZm9vX2ludBgBIAEoBUgAEhQKCmZvb19zdHJp",
            "bmcYAiABKAlIABI9Cgtmb29fbWVzc2FnZRgDIAEoCzImLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXNIABJACghmb29ncm91cBgEIAEo",
            "CjIsLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0T25lb2YuRm9vR3Jv",
            "dXBIABogCghGb29Hcm91cBIJCgFhGAUgASgFEgkKAWIYBiABKAlCBQoDZm9v",
            "IvUBChxUZXN0T25lb2ZCYWNrd2FyZHNDb21wYXRpYmxlEg8KB2Zvb19pbnQY",
            "ASABKAUSEgoKZm9vX3N0cmluZxgCIAEoCRI7Cgtmb29fbWVzc2FnZRgDIAEo",
            "CzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMSUQoI",
            "Zm9vZ3JvdXAYBCABKAoyPy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVz",
            "dE9uZW9mQmFja3dhcmRzQ29tcGF0aWJsZS5Gb29Hcm91cBogCghGb29Hcm91",
            "cBIJCgFhGAUgASgFEgkKAWIYBiABKAkiwQYKClRlc3RPbmVvZjISEQoHZm9v",
            "X2ludBgBIAEoBUgAEhQKCmZvb19zdHJpbmcYAiABKAlIABIWCghmb29fY29y",
            "ZBgDIAEoCUICCAFIABIeChBmb29fc3RyaW5nX3BpZWNlGAQgASgJQgIIAkgA",
            "EhMKCWZvb19ieXRlcxgFIAEoDEgAEkMKCGZvb19lbnVtGAYgASgOMi8ucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RPbmVvZjIuTmVzdGVkRW51bUgA",
            "EkkKC2Zvb19tZXNzYWdlGAcgASgLMjIucHJvdG9idWZfdW5pdHRlc3RfcHJv",
            "dG8yLlRlc3RPbmVvZjIuTmVzdGVkTWVzc2FnZUgAEkEKCGZvb2dyb3VwGAgg",
            "ASgKMi0ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RPbmVvZjIuRm9v",
            "R3JvdXBIABJSChBmb29fbGF6eV9tZXNzYWdlGAsgASgLMjIucHJvdG9idWZf",
            "dW5pdHRlc3RfcHJvdG8yLlRlc3RPbmVvZjIuTmVzdGVkTWVzc2FnZUICKAFI",
            "ABIUCgdiYXJfaW50GAwgASgFOgE1SAESHAoKYmFyX3N0cmluZxgNIAEoCToG",
            "U1RSSU5HSAESHAoIYmFyX2NvcmQYDiABKAk6BENPUkRCAggBSAESJgoQYmFy",
            "X3N0cmluZ19waWVjZRgPIAEoCToGU1BJRUNFQgIIAkgBEhoKCWJhcl9ieXRl",
            "cxgQIAEoDDoFQllURVNIARJICghiYXJfZW51bRgRIAEoDjIvLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0T25lb2YyLk5lc3RlZEVudW06A0JBUkgB",
            "Eg8KB2Jhel9pbnQYEiABKAUSFwoKYmF6X3N0cmluZxgTIAEoCToDQkFaGiAK",
            "CEZvb0dyb3VwEgkKAWEYCSABKAUSCQoBYhgKIAEoCRozCg1OZXN0ZWRNZXNz",
            "YWdlEg8KB3F1eF9pbnQYASABKAMSEQoJY29yZ2VfaW50GAIgAygFIicKCk5l",
            "c3RlZEVudW0SBwoDRk9PEAESBwoDQkFSEAISBwoDQkFaEANCBQoDZm9vQgUK",
            "A2JhciK/AQoRVGVzdFJlcXVpcmVkT25lb2YSEQoHZm9vX2ludBgBIAEoBUgA",
            "EhQKCmZvb19zdHJpbmcYAiABKAlIABJQCgtmb29fbWVzc2FnZRgDIAEoCzI5",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0UmVxdWlyZWRPbmVvZi5O",
            "ZXN0ZWRNZXNzYWdlSAAaKAoNTmVzdGVkTWVzc2FnZRIXCg9yZXF1aXJlZF9k",
            "b3VibGUYASACKAFCBQoDZm9vIuABCg9UZXN0UmVxdWlyZWRNYXASPwoDZm9v",
            "GAEgAygLMjIucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RSZXF1aXJl",
            "ZE1hcC5Gb29FbnRyeRpjCghGb29FbnRyeRILCgNrZXkYASABKAUSRgoFdmFs",
            "dWUYAiABKAsyNy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdFJlcXVp",
            "cmVkTWFwLk5lc3RlZE1lc3NhZ2U6AjgBGicKDU5lc3RlZE1lc3NhZ2USFgoO",
            "cmVxdWlyZWRfaW50MzIYASACKAUisQMKD1Rlc3RQYWNrZWRUeXBlcxIYCgxw",
            "YWNrZWRfaW50MzIYWiADKAVCAhABEhgKDHBhY2tlZF9pbnQ2NBhbIAMoA0IC",
            "EAESGQoNcGFja2VkX3VpbnQzMhhcIAMoDUICEAESGQoNcGFja2VkX3VpbnQ2",
            "NBhdIAMoBEICEAESGQoNcGFja2VkX3NpbnQzMhheIAMoEUICEAESGQoNcGFj",
            "a2VkX3NpbnQ2NBhfIAMoEkICEAESGgoOcGFja2VkX2ZpeGVkMzIYYCADKAdC",
            "AhABEhoKDnBhY2tlZF9maXhlZDY0GGEgAygGQgIQARIbCg9wYWNrZWRfc2Zp",
            "eGVkMzIYYiADKA9CAhABEhsKD3BhY2tlZF9zZml4ZWQ2NBhjIAMoEEICEAES",
            "GAoMcGFja2VkX2Zsb2F0GGQgAygCQgIQARIZCg1wYWNrZWRfZG91YmxlGGUg",
            "AygBQgIQARIXCgtwYWNrZWRfYm9vbBhmIAMoCEICEAESPgoLcGFja2VkX2Vu",
            "dW0YZyADKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVu",
            "dW1CAhABIs8DChFUZXN0VW5wYWNrZWRUeXBlcxIaCg51bnBhY2tlZF9pbnQz",
            "MhhaIAMoBUICEAASGgoOdW5wYWNrZWRfaW50NjQYWyADKANCAhAAEhsKD3Vu",
            "cGFja2VkX3VpbnQzMhhcIAMoDUICEAASGwoPdW5wYWNrZWRfdWludDY0GF0g",
            "AygEQgIQABIbCg91bnBhY2tlZF9zaW50MzIYXiADKBFCAhAAEhsKD3VucGFj",
            "a2VkX3NpbnQ2NBhfIAMoEkICEAASHAoQdW5wYWNrZWRfZml4ZWQzMhhgIAMo",
            "B0ICEAASHAoQdW5wYWNrZWRfZml4ZWQ2NBhhIAMoBkICEAASHQoRdW5wYWNr",
            "ZWRfc2ZpeGVkMzIYYiADKA9CAhAAEh0KEXVucGFja2VkX3NmaXhlZDY0GGMg",
            "AygQQgIQABIaCg51bnBhY2tlZF9mbG9hdBhkIAMoAkICEAASGwoPdW5wYWNr",
            "ZWRfZG91YmxlGGUgAygBQgIQABIZCg11bnBhY2tlZF9ib29sGGYgAygIQgIQ",
            "ABJACg11bnBhY2tlZF9lbnVtGGcgAygOMiUucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLkZvcmVpZ25FbnVtQgIQACIgChRUZXN0UGFja2VkRXh0ZW5zaW9u",
            "cyoICAEQgICAgAIiIgoWVGVzdFVucGFja2VkRXh0ZW5zaW9ucyoICAEQgICA",
            "gAIitQQKFVRlc3REeW5hbWljRXh0ZW5zaW9ucxIZChBzY2FsYXJfZXh0ZW5z",
            "aW9uGNAPIAEoBxI+Cg5lbnVtX2V4dGVuc2lvbhjRDyABKA4yJS5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW0SYAoWZHluYW1pY19lbnVt",
            "X2V4dGVuc2lvbhjSDyABKA4yPy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdER5bmFtaWNFeHRlbnNpb25zLkR5bmFtaWNFbnVtVHlwZRJEChFtZXNz",
            "YWdlX2V4dGVuc2lvbhjTDyABKAsyKC5wcm90b2J1Zl91bml0dGVzdF9wcm90",
            "bzIuRm9yZWlnbk1lc3NhZ2USZgoZZHluYW1pY19tZXNzYWdlX2V4dGVuc2lv",
            "bhjUDyABKAsyQi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdER5bmFt",
            "aWNFeHRlbnNpb25zLkR5bmFtaWNNZXNzYWdlVHlwZRIbChJyZXBlYXRlZF9l",
            "eHRlbnNpb24Y1Q8gAygJEh0KEHBhY2tlZF9leHRlbnNpb24Y1g8gAygRQgIQ",
            "ARosChJEeW5hbWljTWVzc2FnZVR5cGUSFgoNZHluYW1pY19maWVsZBi0ECAB",
            "KAUiRwoPRHluYW1pY0VudW1UeXBlEhAKC0RZTkFNSUNfRk9PEJgREhAKC0RZ",
            "TkFNSUNfQkFSEJkREhAKC0RZTkFNSUNfQkFaEJoRIsABCiNUZXN0UmVwZWF0",
            "ZWRTY2FsYXJEaWZmZXJlbnRUYWdTaXplcxIYChByZXBlYXRlZF9maXhlZDMy",
            "GAwgAygHEhYKDnJlcGVhdGVkX2ludDMyGA0gAygFEhkKEHJlcGVhdGVkX2Zp",
            "eGVkNjQY/g8gAygGEhcKDnJlcGVhdGVkX2ludDY0GP8PIAMoAxIYCg5yZXBl",
            "YXRlZF9mbG9hdBj+/w8gAygCEhkKD3JlcGVhdGVkX3VpbnQ2NBj//w8gAygE",
            "IoMLChBUZXN0UGFyc2luZ01lcmdlEkIKEnJlcXVpcmVkX2FsbF90eXBlcxgB",
            "IAIoCzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMS",
            "QgoSb3B0aW9uYWxfYWxsX3R5cGVzGAIgASgLMiYucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RBbGxUeXBlcxJCChJyZXBlYXRlZF9hbGxfdHlwZXMY",
            "AyADKAsyJi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVz",
            "Ek8KDW9wdGlvbmFsZ3JvdXAYCiABKAoyOC5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdFBhcnNpbmdNZXJnZS5PcHRpb25hbEdyb3VwEk8KDXJlcGVh",
            "dGVkZ3JvdXAYFCADKAoyOC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVz",
            "dFBhcnNpbmdNZXJnZS5SZXBlYXRlZEdyb3VwGukEChdSZXBlYXRlZEZpZWxk",
            "c0dlbmVyYXRvchI2CgZmaWVsZDEYASADKAsyJi5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdEFsbFR5cGVzEjYKBmZpZWxkMhgCIAMoCzImLnByb3Rv",
            "YnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMSNgoGZmllbGQzGAMg",
            "AygLMiYucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxUeXBlcxJZ",
            "CgZncm91cDEYCiADKAoySS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVz",
            "dFBhcnNpbmdNZXJnZS5SZXBlYXRlZEZpZWxkc0dlbmVyYXRvci5Hcm91cDES",
            "WQoGZ3JvdXAyGBQgAygKMkkucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRl",
            "c3RQYXJzaW5nTWVyZ2UuUmVwZWF0ZWRGaWVsZHNHZW5lcmF0b3IuR3JvdXAy",
            "EjUKBGV4dDEY6AcgAygLMiYucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRl",
            "c3RBbGxUeXBlcxI1CgRleHQyGOkHIAMoCzImLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0QWxsVHlwZXMaQAoGR3JvdXAxEjYKBmZpZWxkMRgLIAEo",
            "CzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMaQAoG",
            "R3JvdXAyEjYKBmZpZWxkMRgVIAEoCzImLnByb3RvYnVmX3VuaXR0ZXN0X3By",
            "b3RvMi5UZXN0QWxsVHlwZXMaWQoNT3B0aW9uYWxHcm91cBJIChhvcHRpb25h",
            "bF9ncm91cF9hbGxfdHlwZXMYCyABKAsyJi5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdEFsbFR5cGVzGlkKDVJlcGVhdGVkR3JvdXASSAoYcmVwZWF0",
            "ZWRfZ3JvdXBfYWxsX3R5cGVzGBUgASgLMiYucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RBbGxUeXBlcyoJCOgHEICAgIACMmkKDG9wdGlvbmFsX2V4",
            "dBIqLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0UGFyc2luZ01lcmdl",
            "GOgHIAEoCzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlw",
            "ZXMyaQoMcmVwZWF0ZWRfZXh0EioucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RQYXJzaW5nTWVyZ2UY6QcgAygLMiYucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RBbGxUeXBlcyJEChtUZXN0Q29tbWVudEluamVjdGlvbk1l",
            "c3NhZ2USJQoBYRgBIAEoCToaKi8gPC0gTmVpdGhlciBzaG91bGQgdGhpcy4i",
            "DAoKRm9vUmVxdWVzdCINCgtGb29SZXNwb25zZSISChBGb29DbGllbnRNZXNz",
            "YWdlIhIKEEZvb1NlcnZlck1lc3NhZ2UiDAoKQmFyUmVxdWVzdCINCgtCYXJS",
            "ZXNwb25zZSKSAQoMVGVzdEpzb25OYW1lEhMKC2ZpZWxkX25hbWUxGAEgASgF",
            "EhIKCmZpZWxkTmFtZTIYAiABKAUSEgoKRmllbGROYW1lMxgDIAEoBRIUCgxf",
            "ZmllbGRfbmFtZTQYBCABKAUSEwoLRklFTERfTkFNRTUYBSABKAUSGgoLZmll",
            "bGRfbmFtZTYYBiABKAVSBUB0eXBlIqAGChRUZXN0SHVnZUZpZWxkTnVtYmVy",
            "cxIaCg5vcHRpb25hbF9pbnQzMhjw+P//ASABKAUSFAoIZml4ZWRfMzIY8fj/",
            "/wEgASgFEh4KDnJlcGVhdGVkX2ludDMyGPL4//8BIAMoBUICEAASHAoMcGFj",
            "a2VkX2ludDMyGPP4//8BIAMoBUICEAESQAoNb3B0aW9uYWxfZW51bRj0+P//",
            "ASABKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW0S",
            "GwoPb3B0aW9uYWxfc3RyaW5nGPX4//8BIAEoCRIaCg5vcHRpb25hbF9ieXRl",
            "cxj2+P//ASABKAwSRgoQb3B0aW9uYWxfbWVzc2FnZRj3+P//ASABKAsyKC5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbk1lc3NhZ2USVwoNb3B0",
            "aW9uYWxncm91cBj4+P//ASABKAoyPC5wcm90b2J1Zl91bml0dGVzdF9wcm90",
            "bzIuVGVzdEh1Z2VGaWVsZE51bWJlcnMuT3B0aW9uYWxHcm91cBJiChFzdHJp",
            "bmdfc3RyaW5nX21hcBj6+P//ASADKAsyQy5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdEh1Z2VGaWVsZE51bWJlcnMuU3RyaW5nU3RyaW5nTWFwRW50",
            "cnkSGgoMb25lb2ZfdWludDMyGPv4//8BIAEoDUgAEkoKFG9uZW9mX3Rlc3Rf",
            "YWxsX3R5cGVzGPz4//8BIAEoCzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3Rv",
            "Mi5UZXN0QWxsVHlwZXNIABIaCgxvbmVvZl9zdHJpbmcY/fj//wEgASgJSAAS",
            "GQoLb25lb2ZfYnl0ZXMY/vj//wEgASgMSAAaJAoNT3B0aW9uYWxHcm91cBIT",
            "Cgdncm91cF9hGPn4//8BIAEoBRo2ChRTdHJpbmdTdHJpbmdNYXBFbnRyeRIL",
            "CgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBKgwI4Kr//wEQ8Pj//wFC",
            "DQoLb25lb2ZfZmllbGQisQEKGFRlc3RFeHRlbnNpb25JbnNpZGVUYWJsZRIO",
            "CgZmaWVsZDEYASABKAUSDgoGZmllbGQyGAIgASgFEg4KBmZpZWxkMxgDIAEo",
            "BRIOCgZmaWVsZDQYBCABKAUSDgoGZmllbGQ2GAYgASgFEg4KBmZpZWxkNxgH",
            "IAEoBRIOCgZmaWVsZDgYCCABKAUSDgoGZmllbGQ5GAkgASgFEg8KB2ZpZWxk",
            "MTAYCiABKAUqBAgFEAYqQAoLRm9yZWlnbkVudW0SDwoLRk9SRUlHTl9GT08Q",
            "BBIPCgtGT1JFSUdOX0JBUhAFEg8KC0ZPUkVJR05fQkFaEAYqSwoUVGVzdEVu",
            "dW1XaXRoRHVwVmFsdWUSCAoERk9PMRABEggKBEJBUjEQAhIHCgNCQVoQAxII",
            "CgRGT08yEAESCAoEQkFSMhACGgIQASqJAQoOVGVzdFNwYXJzZUVudW0SDAoI",
            "U1BBUlNFX0EQexIOCghTUEFSU0VfQhCm5wMSDwoIU1BBUlNFX0MQsrGABhIV",
            "CghTUEFSU0VfRBDx//////////8BEhUKCFNQQVJTRV9FELTe/P///////wES",
            "DAoIU1BBUlNFX0YQABIMCghTUEFSU0VfRxACKosPCg1WZXJ5TGFyZ2VFbnVt",
            "EhYKEkVOVU1fTEFCRUxfREVGQVVMVBAAEhAKDEVOVU1fTEFCRUxfMRABEhAK",
            "DEVOVU1fTEFCRUxfMhACEhAKDEVOVU1fTEFCRUxfMxADEhAKDEVOVU1fTEFC",
            "RUxfNBAEEhAKDEVOVU1fTEFCRUxfNRAFEhAKDEVOVU1fTEFCRUxfNhAGEhAK",
            "DEVOVU1fTEFCRUxfNxAHEhAKDEVOVU1fTEFCRUxfOBAIEhAKDEVOVU1fTEFC",
            "RUxfORAJEhEKDUVOVU1fTEFCRUxfMTAQChIRCg1FTlVNX0xBQkVMXzExEAsS",
            "EQoNRU5VTV9MQUJFTF8xMhAMEhEKDUVOVU1fTEFCRUxfMTMQDRIRCg1FTlVN",
            "X0xBQkVMXzE0EA4SEQoNRU5VTV9MQUJFTF8xNRAPEhEKDUVOVU1fTEFCRUxf",
            "MTYQEBIRCg1FTlVNX0xBQkVMXzE3EBESEQoNRU5VTV9MQUJFTF8xOBASEhEK",
            "DUVOVU1fTEFCRUxfMTkQExIRCg1FTlVNX0xBQkVMXzIwEBQSEQoNRU5VTV9M",
            "QUJFTF8yMRAVEhEKDUVOVU1fTEFCRUxfMjIQFhIRCg1FTlVNX0xBQkVMXzIz",
            "EBcSEQoNRU5VTV9MQUJFTF8yNBAYEhEKDUVOVU1fTEFCRUxfMjUQGRIRCg1F",
            "TlVNX0xBQkVMXzI2EBoSEQoNRU5VTV9MQUJFTF8yNxAbEhEKDUVOVU1fTEFC",
            "RUxfMjgQHBIRCg1FTlVNX0xBQkVMXzI5EB0SEQoNRU5VTV9MQUJFTF8zMBAe",
            "EhEKDUVOVU1fTEFCRUxfMzEQHxIRCg1FTlVNX0xBQkVMXzMyECASEQoNRU5V",
            "TV9MQUJFTF8zMxAhEhEKDUVOVU1fTEFCRUxfMzQQIhIRCg1FTlVNX0xBQkVM",
            "XzM1ECMSEQoNRU5VTV9MQUJFTF8zNhAkEhEKDUVOVU1fTEFCRUxfMzcQJRIR",
            "Cg1FTlVNX0xBQkVMXzM4ECYSEQoNRU5VTV9MQUJFTF8zORAnEhEKDUVOVU1f",
            "TEFCRUxfNDAQKBIRCg1FTlVNX0xBQkVMXzQxECkSEQoNRU5VTV9MQUJFTF80",
            "MhAqEhEKDUVOVU1fTEFCRUxfNDMQKxIRCg1FTlVNX0xBQkVMXzQ0ECwSEQoN",
            "RU5VTV9MQUJFTF80NRAtEhEKDUVOVU1fTEFCRUxfNDYQLhIRCg1FTlVNX0xB",
            "QkVMXzQ3EC8SEQoNRU5VTV9MQUJFTF80OBAwEhEKDUVOVU1fTEFCRUxfNDkQ",
            "MRIRCg1FTlVNX0xBQkVMXzUwEDISEQoNRU5VTV9MQUJFTF81MRAzEhEKDUVO",
            "VU1fTEFCRUxfNTIQNBIRCg1FTlVNX0xBQkVMXzUzEDUSEQoNRU5VTV9MQUJF",
            "TF81NBA2EhEKDUVOVU1fTEFCRUxfNTUQNxIRCg1FTlVNX0xBQkVMXzU2EDgS",
            "EQoNRU5VTV9MQUJFTF81NxA5EhEKDUVOVU1fTEFCRUxfNTgQOhIRCg1FTlVN",
            "X0xBQkVMXzU5EDsSEQoNRU5VTV9MQUJFTF82MBA8EhEKDUVOVU1fTEFCRUxf",
            "NjEQPRIRCg1FTlVNX0xBQkVMXzYyED4SEQoNRU5VTV9MQUJFTF82MxA/EhEK",
            "DUVOVU1fTEFCRUxfNjQQQBIRCg1FTlVNX0xBQkVMXzY1EEESEQoNRU5VTV9M",
            "QUJFTF82NhBCEhEKDUVOVU1fTEFCRUxfNjcQQxIRCg1FTlVNX0xBQkVMXzY4",
            "EEQSEQoNRU5VTV9MQUJFTF82ORBFEhEKDUVOVU1fTEFCRUxfNzAQRhIRCg1F",
            "TlVNX0xBQkVMXzcxEEcSEQoNRU5VTV9MQUJFTF83MhBIEhEKDUVOVU1fTEFC",
            "RUxfNzMQSRIRCg1FTlVNX0xBQkVMXzc0EEoSEQoNRU5VTV9MQUJFTF83NRBL",
            "EhEKDUVOVU1fTEFCRUxfNzYQTBIRCg1FTlVNX0xBQkVMXzc3EE0SEQoNRU5V",
            "TV9MQUJFTF83OBBOEhEKDUVOVU1fTEFCRUxfNzkQTxIRCg1FTlVNX0xBQkVM",
            "XzgwEFASEQoNRU5VTV9MQUJFTF84MRBREhEKDUVOVU1fTEFCRUxfODIQUhIR",
            "Cg1FTlVNX0xBQkVMXzgzEFMSEQoNRU5VTV9MQUJFTF84NBBUEhEKDUVOVU1f",
            "TEFCRUxfODUQVRIRCg1FTlVNX0xBQkVMXzg2EFYSEQoNRU5VTV9MQUJFTF84",
            "NxBXEhEKDUVOVU1fTEFCRUxfODgQWBIRCg1FTlVNX0xBQkVMXzg5EFkSEQoN",
            "RU5VTV9MQUJFTF85MBBaEhEKDUVOVU1fTEFCRUxfOTEQWxIRCg1FTlVNX0xB",
            "QkVMXzkyEFwSEQoNRU5VTV9MQUJFTF85MxBdEhEKDUVOVU1fTEFCRUxfOTQQ",
            "XhIRCg1FTlVNX0xBQkVMXzk1EF8SEQoNRU5VTV9MQUJFTF85NhBgEhEKDUVO",
            "VU1fTEFCRUxfOTcQYRIRCg1FTlVNX0xBQkVMXzk4EGISEQoNRU5VTV9MQUJF",
            "TF85ORBjEhIKDkVOVU1fTEFCRUxfMTAwEGQytQEKC1Rlc3RTZXJ2aWNlElIK",
            "A0ZvbxIkLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5Gb29SZXF1ZXN0GiUu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLkZvb1Jlc3BvbnNlElIKA0JhchIk",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5CYXJSZXF1ZXN0GiUucHJvdG9i",
            "dWZfdW5pdHRlc3RfcHJvdG8yLkJhclJlc3BvbnNlOk0KGG9wdGlvbmFsX2lu",
            "dDMyX2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0",
            "QWxsRXh0ZW5zaW9ucxgBIAEoBTpNChhvcHRpb25hbF9pbnQ2NF9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYAiABKAM6TgoZb3B0aW9uYWxfdWludDMyX2V4dGVuc2lvbhIrLnByb3Rv",
            "YnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgDIAEoDTpO",
            "ChlvcHRpb25hbF91aW50NjRfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGAQgASgEOk4KGW9wdGlvbmFs",
            "X3NpbnQzMl9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbEV4dGVuc2lvbnMYBSABKBE6TgoZb3B0aW9uYWxfc2ludDY0X2V4",
            "dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0",
            "ZW5zaW9ucxgGIAEoEjpPChpvcHRpb25hbF9maXhlZDMyX2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgH",
            "IAEoBzpPChpvcHRpb25hbF9maXhlZDY0X2V4dGVuc2lvbhIrLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgIIAEoBjpQChtv",
            "cHRpb25hbF9zZml4ZWQzMl9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYCSABKA86UAobb3B0aW9uYWxf",
            "c2ZpeGVkNjRfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RBbGxFeHRlbnNpb25zGAogASgQOk0KGG9wdGlvbmFsX2Zsb2F0X2V4",
            "dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0",
            "ZW5zaW9ucxgLIAEoAjpOChlvcHRpb25hbF9kb3VibGVfZXh0ZW5zaW9uEisu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGAwg",
            "ASgBOkwKF29wdGlvbmFsX2Jvb2xfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5p",
            "dHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGA0gASgIOk4KGW9wdGlv",
            "bmFsX3N0cmluZ19leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90",
            "bzIuVGVzdEFsbEV4dGVuc2lvbnMYDiABKAk6TQoYb3B0aW9uYWxfYnl0ZXNf",
            "ZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxF",
            "eHRlbnNpb25zGA8gASgMOn8KF29wdGlvbmFsZ3JvdXBfZXh0ZW5zaW9uEisu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGBAg",
            "ASgKMjEucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLk9wdGlvbmFsR3JvdXBf",
            "ZXh0ZW5zaW9uOowBCiFvcHRpb25hbF9uZXN0ZWRfbWVzc2FnZV9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYEiABKAsyNC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5",
            "cGVzLk5lc3RlZE1lc3NhZ2U6gQEKIm9wdGlvbmFsX2ZvcmVpZ25fbWVzc2Fn",
            "ZV9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFs",
            "bEV4dGVuc2lvbnMYEyABKAsyKC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "Rm9yZWlnbk1lc3NhZ2U6hgEKIW9wdGlvbmFsX2ltcG9ydF9tZXNzYWdlX2V4",
            "dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0",
            "ZW5zaW9ucxgUIAEoCzIuLnByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydF9wcm90",
            "bzIuSW1wb3J0TWVzc2FnZTqGAQoeb3B0aW9uYWxfbmVzdGVkX2VudW1fZXh0",
            "ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRl",
            "bnNpb25zGBUgASgOMjEucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RB",
            "bGxUeXBlcy5OZXN0ZWRFbnVtOnsKH29wdGlvbmFsX2ZvcmVpZ25fZW51bV9l",
            "eHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4",
            "dGVuc2lvbnMYFiABKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9y",
            "ZWlnbkVudW06gAEKHm9wdGlvbmFsX2ltcG9ydF9lbnVtX2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgX",
            "IAEoDjIrLnByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydF9wcm90bzIuSW1wb3J0",
            "RW51bTpYCh9vcHRpb25hbF9zdHJpbmdfcGllY2VfZXh0ZW5zaW9uEisucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGBggASgJ",
            "QgIIAjpQChdvcHRpb25hbF9jb3JkX2V4dGVuc2lvbhIrLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgZIAEoCUICCAE6kwEK",
            "KG9wdGlvbmFsX3B1YmxpY19pbXBvcnRfbWVzc2FnZV9leHRlbnNpb24SKy5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYGiAB",
            "KAsyNC5wcm90b2J1Zl91bml0dGVzdF9pbXBvcnRfcHJvdG8yLlB1YmxpY0lt",
            "cG9ydE1lc3NhZ2U6jgEKH29wdGlvbmFsX2xhenlfbWVzc2FnZV9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYGyABKAsyNC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5",
            "cGVzLk5lc3RlZE1lc3NhZ2VCAigBOk0KGHJlcGVhdGVkX2ludDMyX2V4dGVu",
            "c2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5z",
            "aW9ucxgfIAMoBTpNChhyZXBlYXRlZF9pbnQ2NF9leHRlbnNpb24SKy5wcm90",
            "b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYICADKAM6",
            "TgoZcmVwZWF0ZWRfdWludDMyX2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0",
            "ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxghIAMoDTpOChlyZXBlYXRl",
            "ZF91aW50NjRfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RBbGxFeHRlbnNpb25zGCIgAygEOk4KGXJlcGVhdGVkX3NpbnQzMl9l",
            "eHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4",
            "dGVuc2lvbnMYIyADKBE6TgoZcmVwZWF0ZWRfc2ludDY0X2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgk",
            "IAMoEjpPChpyZXBlYXRlZF9maXhlZDMyX2V4dGVuc2lvbhIrLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxglIAMoBzpPChpy",
            "ZXBlYXRlZF9maXhlZDY0X2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgmIAMoBjpQChtyZXBlYXRlZF9z",
            "Zml4ZWQzMl9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbEV4dGVuc2lvbnMYJyADKA86UAobcmVwZWF0ZWRfc2ZpeGVkNjRf",
            "ZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxF",
            "eHRlbnNpb25zGCggAygQOk0KGHJlcGVhdGVkX2Zsb2F0X2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgp",
            "IAMoAjpOChlyZXBlYXRlZF9kb3VibGVfZXh0ZW5zaW9uEisucHJvdG9idWZf",
            "dW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGCogAygBOkwKF3Jl",
            "cGVhdGVkX2Jvb2xfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJv",
            "dG8yLlRlc3RBbGxFeHRlbnNpb25zGCsgAygIOk4KGXJlcGVhdGVkX3N0cmlu",
            "Z19leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFs",
            "bEV4dGVuc2lvbnMYLCADKAk6TQoYcmVwZWF0ZWRfYnl0ZXNfZXh0ZW5zaW9u",
            "EisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25z",
            "GC0gAygMOn8KF3JlcGVhdGVkZ3JvdXBfZXh0ZW5zaW9uEisucHJvdG9idWZf",
            "dW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGC4gAygKMjEucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlJlcGVhdGVkR3JvdXBfZXh0ZW5zaW9u",
            "OowBCiFyZXBlYXRlZF9uZXN0ZWRfbWVzc2FnZV9leHRlbnNpb24SKy5wcm90",
            "b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYMCADKAsy",
            "NC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVzLk5lc3Rl",
            "ZE1lc3NhZ2U6gQEKInJlcGVhdGVkX2ZvcmVpZ25fbWVzc2FnZV9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYMSADKAsyKC5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbk1l",
            "c3NhZ2U6hgEKIXJlcGVhdGVkX2ltcG9ydF9tZXNzYWdlX2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxgy",
            "IAMoCzIuLnByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydF9wcm90bzIuSW1wb3J0",
            "TWVzc2FnZTqGAQoecmVwZWF0ZWRfbmVzdGVkX2VudW1fZXh0ZW5zaW9uEisu",
            "cHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGDMg",
            "AygOMjEucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxUeXBlcy5O",
            "ZXN0ZWRFbnVtOnsKH3JlcGVhdGVkX2ZvcmVpZ25fZW51bV9leHRlbnNpb24S",
            "Ky5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMY",
            "NCADKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW06",
            "gAEKHnJlcGVhdGVkX2ltcG9ydF9lbnVtX2V4dGVuc2lvbhIrLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxg1IAMoDjIrLnBy",
            "b3RvYnVmX3VuaXR0ZXN0X2ltcG9ydF9wcm90bzIuSW1wb3J0RW51bTpYCh9y",
            "ZXBlYXRlZF9zdHJpbmdfcGllY2VfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5p",
            "dHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGDYgAygJQgIIAjpQChdy",
            "ZXBlYXRlZF9jb3JkX2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3By",
            "b3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxg3IAMoCUICCAE6jgEKH3JlcGVhdGVk",
            "X2xhenlfbWVzc2FnZV9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9w",
            "cm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYOSADKAsyNC5wcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVzLk5lc3RlZE1lc3NhZ2VCAigBOlAK",
            "F2RlZmF1bHRfaW50MzJfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGD0gASgFOgI0MTpQChdkZWZhdWx0",
            "X2ludDY0X2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5U",
            "ZXN0QWxsRXh0ZW5zaW9ucxg+IAEoAzoCNDI6UQoYZGVmYXVsdF91aW50MzJf",
            "ZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxF",
            "eHRlbnNpb25zGD8gASgNOgI0MzpRChhkZWZhdWx0X3VpbnQ2NF9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYQCABKAQ6AjQ0OlIKGGRlZmF1bHRfc2ludDMyX2V4dGVuc2lvbhIrLnBy",
            "b3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhBIAEo",
            "EToDLTQ1OlEKGGRlZmF1bHRfc2ludDY0X2V4dGVuc2lvbhIrLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhCIAEoEjoCNDY6",
            "UgoZZGVmYXVsdF9maXhlZDMyX2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0",
            "ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhDIAEoBzoCNDc6UgoZZGVm",
            "YXVsdF9maXhlZDY0X2V4dGVuc2lvbhIrLnByb3RvYnVmX3VuaXR0ZXN0X3By",
            "b3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhEIAEoBjoCNDg6UwoaZGVmYXVsdF9z",
            "Zml4ZWQzMl9leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbEV4dGVuc2lvbnMYRSABKA86AjQ5OlQKGmRlZmF1bHRfc2ZpeGVk",
            "NjRfZXh0ZW5zaW9uEisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RB",
            "bGxFeHRlbnNpb25zGEYgASgQOgMtNTA6UgoXZGVmYXVsdF9mbG9hdF9leHRl",
            "bnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVu",
            "c2lvbnMYRyABKAI6BDUxLjU6VAoYZGVmYXVsdF9kb3VibGVfZXh0ZW5zaW9u",
            "EisucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25z",
            "GEggASgBOgU1MjAwMDpRChZkZWZhdWx0X2Jvb2xfZXh0ZW5zaW9uEisucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGEkgASgI",
            "OgR0cnVlOlQKGGRlZmF1bHRfc3RyaW5nX2V4dGVuc2lvbhIrLnByb3RvYnVm",
            "X3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhKIAEoCToFaGVs",
            "bG86UwoXZGVmYXVsdF9ieXRlc19leHRlbnNpb24SKy5wcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYSyABKAw6BXdvcmxkOooB",
            "Ch1kZWZhdWx0X25lc3RlZF9lbnVtX2V4dGVuc2lvbhIrLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhRIAEoDjIxLnByb3Rv",
            "YnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsVHlwZXMuTmVzdGVkRW51bToD",
            "QkFSOocBCh5kZWZhdWx0X2ZvcmVpZ25fZW51bV9leHRlbnNpb24SKy5wcm90",
            "b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYUiABKA4y",
            "JS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW06C0ZPUkVJ",
            "R05fQkFSOosBCh1kZWZhdWx0X2ltcG9ydF9lbnVtX2V4dGVuc2lvbhIrLnBy",
            "b3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhTIAEo",
            "DjIrLnByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydF9wcm90bzIuSW1wb3J0RW51",
            "bToKSU1QT1JUX0JBUjpcCh5kZWZhdWx0X3N0cmluZ19waWVjZV9leHRlbnNp",
            "b24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lv",
            "bnMYVCABKAk6A2FiY0ICCAI6VAoWZGVmYXVsdF9jb3JkX2V4dGVuc2lvbhIr",
            "LnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhV",
            "IAEoCToDMTIzQgIIATpLChZvbmVvZl91aW50MzJfZXh0ZW5zaW9uEisucHJv",
            "dG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RBbGxFeHRlbnNpb25zGG8gASgN",
            "OokBCh5vbmVvZl9uZXN0ZWRfbWVzc2FnZV9leHRlbnNpb24SKy5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbEV4dGVuc2lvbnMYcCABKAsyNC5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdEFsbFR5cGVzLk5lc3RlZE1l",
            "c3NhZ2U6SwoWb25lb2Zfc3RyaW5nX2V4dGVuc2lvbhIrLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0QWxsRXh0ZW5zaW9ucxhxIAEoCTpKChVvbmVv",
            "Zl9ieXRlc19leHRlbnNpb24SKy5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIu",
            "VGVzdEFsbEV4dGVuc2lvbnMYciABKAw6SQoTbXlfZXh0ZW5zaW9uX3N0cmlu",
            "ZxIsLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0RmllbGRPcmRlcmlu",
            "Z3MYMiABKAk6RgoQbXlfZXh0ZW5zaW9uX2ludBIsLnByb3RvYnVmX3VuaXR0",
            "ZXN0X3Byb3RvMi5UZXN0RmllbGRPcmRlcmluZ3MYBSABKAU6UgoWcGFja2Vk",
            "X2ludDMyX2V4dGVuc2lvbhIuLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5U",
            "ZXN0UGFja2VkRXh0ZW5zaW9ucxhaIAMoBUICEAE6UgoWcGFja2VkX2ludDY0",
            "X2V4dGVuc2lvbhIuLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0UGFj",
            "a2VkRXh0ZW5zaW9ucxhbIAMoA0ICEAE6UwoXcGFja2VkX3VpbnQzMl9leHRl",
            "bnNpb24SLi5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdFBhY2tlZEV4",
            "dGVuc2lvbnMYXCADKA1CAhABOlMKF3BhY2tlZF91aW50NjRfZXh0ZW5zaW9u",
            "Ei4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RQYWNrZWRFeHRlbnNp",
            "b25zGF0gAygEQgIQATpTChdwYWNrZWRfc2ludDMyX2V4dGVuc2lvbhIuLnBy",
            "b3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0UGFja2VkRXh0ZW5zaW9ucxhe",
            "IAMoEUICEAE6UwoXcGFja2VkX3NpbnQ2NF9leHRlbnNpb24SLi5wcm90b2J1",
            "Zl91bml0dGVzdF9wcm90bzIuVGVzdFBhY2tlZEV4dGVuc2lvbnMYXyADKBJC",
            "AhABOlQKGHBhY2tlZF9maXhlZDMyX2V4dGVuc2lvbhIuLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0UGFja2VkRXh0ZW5zaW9ucxhgIAMoB0ICEAE6",
            "VAoYcGFja2VkX2ZpeGVkNjRfZXh0ZW5zaW9uEi4ucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RQYWNrZWRFeHRlbnNpb25zGGEgAygGQgIQATpVChlw",
            "YWNrZWRfc2ZpeGVkMzJfZXh0ZW5zaW9uEi4ucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RQYWNrZWRFeHRlbnNpb25zGGIgAygPQgIQATpVChlwYWNr",
            "ZWRfc2ZpeGVkNjRfZXh0ZW5zaW9uEi4ucHJvdG9idWZfdW5pdHRlc3RfcHJv",
            "dG8yLlRlc3RQYWNrZWRFeHRlbnNpb25zGGMgAygQQgIQATpSChZwYWNrZWRf",
            "ZmxvYXRfZXh0ZW5zaW9uEi4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRl",
            "c3RQYWNrZWRFeHRlbnNpb25zGGQgAygCQgIQATpTChdwYWNrZWRfZG91Ymxl",
            "X2V4dGVuc2lvbhIuLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0UGFj",
            "a2VkRXh0ZW5zaW9ucxhlIAMoAUICEAE6UQoVcGFja2VkX2Jvb2xfZXh0ZW5z",
            "aW9uEi4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RQYWNrZWRFeHRl",
            "bnNpb25zGGYgAygIQgIQATp4ChVwYWNrZWRfZW51bV9leHRlbnNpb24SLi5w",
            "cm90b2J1Zl91bml0dGVzdF9wcm90bzIuVGVzdFBhY2tlZEV4dGVuc2lvbnMY",
            "ZyADKA4yJS5wcm90b2J1Zl91bml0dGVzdF9wcm90bzIuRm9yZWlnbkVudW1C",
            "AhABOlYKGHVucGFja2VkX2ludDMyX2V4dGVuc2lvbhIwLnByb3RvYnVmX3Vu",
            "aXR0ZXN0X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGFogAygFQgIQ",
            "ADpWChh1bnBhY2tlZF9pbnQ2NF9leHRlbnNpb24SMC5wcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxhbIAMoA0ICEAA6",
            "VwoZdW5wYWNrZWRfdWludDMyX2V4dGVuc2lvbhIwLnByb3RvYnVmX3VuaXR0",
            "ZXN0X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGFwgAygNQgIQADpX",
            "Chl1bnBhY2tlZF91aW50NjRfZXh0ZW5zaW9uEjAucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYXSADKARCAhAAOlcK",
            "GXVucGFja2VkX3NpbnQzMl9leHRlbnNpb24SMC5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxheIAMoEUICEAA6VwoZ",
            "dW5wYWNrZWRfc2ludDY0X2V4dGVuc2lvbhIwLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGF8gAygSQgIQADpYChp1",
            "bnBhY2tlZF9maXhlZDMyX2V4dGVuc2lvbhIwLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGGAgAygHQgIQADpYChp1",
            "bnBhY2tlZF9maXhlZDY0X2V4dGVuc2lvbhIwLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGGEgAygGQgIQADpZCht1",
            "bnBhY2tlZF9zZml4ZWQzMl9leHRlbnNpb24SMC5wcm90b2J1Zl91bml0dGVz",
            "dF9wcm90bzIuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxhiIAMoD0ICEAA6WQob",
            "dW5wYWNrZWRfc2ZpeGVkNjRfZXh0ZW5zaW9uEjAucHJvdG9idWZfdW5pdHRl",
            "c3RfcHJvdG8yLlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYYyADKBBCAhAAOlYK",
            "GHVucGFja2VkX2Zsb2F0X2V4dGVuc2lvbhIwLnByb3RvYnVmX3VuaXR0ZXN0",
            "X3Byb3RvMi5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGGQgAygCQgIQADpXChl1",
            "bnBhY2tlZF9kb3VibGVfZXh0ZW5zaW9uEjAucHJvdG9idWZfdW5pdHRlc3Rf",
            "cHJvdG8yLlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYZSADKAFCAhAAOlUKF3Vu",
            "cGFja2VkX2Jvb2xfZXh0ZW5zaW9uEjAucHJvdG9idWZfdW5pdHRlc3RfcHJv",
            "dG8yLlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYZiADKAhCAhAAOnwKF3VucGFj",
            "a2VkX2VudW1fZXh0ZW5zaW9uEjAucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8y",
            "LlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYZyADKA4yJS5wcm90b2J1Zl91bml0",
            "dGVzdF9wcm90bzIuRm9yZWlnbkVudW1CAhAAOnIKDnRlc3RfYWxsX3R5cGVz",
            "Ei4ucHJvdG9idWZfdW5pdHRlc3RfcHJvdG8yLlRlc3RIdWdlRmllbGROdW1i",
            "ZXJzGOCq//8BIAEoCzImLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0",
            "QWxsVHlwZXM6YQoldGVzdF9leHRlbnNpb25faW5zaWRlX3RhYmxlX2V4dGVu",
            "c2lvbhIyLnByb3RvYnVmX3VuaXR0ZXN0X3Byb3RvMi5UZXN0RXh0ZW5zaW9u",
            "SW5zaWRlVGFibGUYBSABKAVCMkgBgAEBiAEBkAEB+AEBqgIhR29vZ2xlLlBy",
            "b3RvYnVmLlRlc3RQcm90b3MuUHJvdG8y"));
      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.Proto2.UnittestImportReflection.Descriptor, },
          new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.Proto2.ForeignEnum), typeof(global::Google.Protobuf.TestProtos.Proto2.TestEnumWithDupValue), typeof(global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum), typeof(global::Google.Protobuf.TestProtos.Proto2.VeryLargeEnum), }, new pb::Extension[] { UnittestExtensions.OptionalInt32Extension, UnittestExtensions.OptionalInt64Extension, UnittestExtensions.OptionalUint32Extension, UnittestExtensions.OptionalUint64Extension, UnittestExtensions.OptionalSint32Extension, UnittestExtensions.OptionalSint64Extension, UnittestExtensions.OptionalFixed32Extension, UnittestExtensions.OptionalFixed64Extension, UnittestExtensions.OptionalSfixed32Extension, UnittestExtensions.OptionalSfixed64Extension, UnittestExtensions.OptionalFloatExtension, UnittestExtensions.OptionalDoubleExtension, UnittestExtensions.OptionalBoolExtension, UnittestExtensions.OptionalStringExtension, UnittestExtensions.OptionalBytesExtension, UnittestExtensions.OptionalGroupExtension, UnittestExtensions.OptionalNestedMessageExtension, UnittestExtensions.OptionalForeignMessageExtension, UnittestExtensions.OptionalImportMessageExtension, UnittestExtensions.OptionalNestedEnumExtension, UnittestExtensions.OptionalForeignEnumExtension, UnittestExtensions.OptionalImportEnumExtension, UnittestExtensions.OptionalStringPieceExtension, UnittestExtensions.OptionalCordExtension, UnittestExtensions.OptionalPublicImportMessageExtension, UnittestExtensions.OptionalLazyMessageExtension, UnittestExtensions.RepeatedInt32Extension, UnittestExtensions.RepeatedInt64Extension, UnittestExtensions.RepeatedUint32Extension, UnittestExtensions.RepeatedUint64Extension, UnittestExtensions.RepeatedSint32Extension, UnittestExtensions.RepeatedSint64Extension, UnittestExtensions.RepeatedFixed32Extension, UnittestExtensions.RepeatedFixed64Extension, UnittestExtensions.RepeatedSfixed32Extension, UnittestExtensions.RepeatedSfixed64Extension, UnittestExtensions.RepeatedFloatExtension, UnittestExtensions.RepeatedDoubleExtension, UnittestExtensions.RepeatedBoolExtension, UnittestExtensions.RepeatedStringExtension, UnittestExtensions.RepeatedBytesExtension, UnittestExtensions.RepeatedGroupExtension, UnittestExtensions.RepeatedNestedMessageExtension, UnittestExtensions.RepeatedForeignMessageExtension, UnittestExtensions.RepeatedImportMessageExtension, UnittestExtensions.RepeatedNestedEnumExtension, UnittestExtensions.RepeatedForeignEnumExtension, UnittestExtensions.RepeatedImportEnumExtension, UnittestExtensions.RepeatedStringPieceExtension, UnittestExtensions.RepeatedCordExtension, UnittestExtensions.RepeatedLazyMessageExtension, UnittestExtensions.DefaultInt32Extension, UnittestExtensions.DefaultInt64Extension, UnittestExtensions.DefaultUint32Extension, UnittestExtensions.DefaultUint64Extension, UnittestExtensions.DefaultSint32Extension, UnittestExtensions.DefaultSint64Extension, UnittestExtensions.DefaultFixed32Extension, UnittestExtensions.DefaultFixed64Extension, UnittestExtensions.DefaultSfixed32Extension, UnittestExtensions.DefaultSfixed64Extension, UnittestExtensions.DefaultFloatExtension, UnittestExtensions.DefaultDoubleExtension, UnittestExtensions.DefaultBoolExtension, UnittestExtensions.DefaultStringExtension, UnittestExtensions.DefaultBytesExtension, UnittestExtensions.DefaultNestedEnumExtension, UnittestExtensions.DefaultForeignEnumExtension, UnittestExtensions.DefaultImportEnumExtension, UnittestExtensions.DefaultStringPieceExtension, UnittestExtensions.DefaultCordExtension, UnittestExtensions.OneofUint32Extension, UnittestExtensions.OneofNestedMessageExtension, UnittestExtensions.OneofStringExtension, UnittestExtensions.OneofBytesExtension, UnittestExtensions.MyExtensionString, UnittestExtensions.MyExtensionInt, UnittestExtensions.PackedInt32Extension, UnittestExtensions.PackedInt64Extension, UnittestExtensions.PackedUint32Extension, UnittestExtensions.PackedUint64Extension, UnittestExtensions.PackedSint32Extension, UnittestExtensions.PackedSint64Extension, UnittestExtensions.PackedFixed32Extension, UnittestExtensions.PackedFixed64Extension, UnittestExtensions.PackedSfixed32Extension, UnittestExtensions.PackedSfixed64Extension, UnittestExtensions.PackedFloatExtension, UnittestExtensions.PackedDoubleExtension, UnittestExtensions.PackedBoolExtension, UnittestExtensions.PackedEnumExtension, UnittestExtensions.UnpackedInt32Extension, UnittestExtensions.UnpackedInt64Extension, UnittestExtensions.UnpackedUint32Extension, UnittestExtensions.UnpackedUint64Extension, UnittestExtensions.UnpackedSint32Extension, UnittestExtensions.UnpackedSint64Extension, UnittestExtensions.UnpackedFixed32Extension, UnittestExtensions.UnpackedFixed64Extension, UnittestExtensions.UnpackedSfixed32Extension, UnittestExtensions.UnpackedSfixed64Extension, UnittestExtensions.UnpackedFloatExtension, UnittestExtensions.UnpackedDoubleExtension, UnittestExtensions.UnpackedBoolExtension, UnittestExtensions.UnpackedEnumExtension, UnittestExtensions.TestAllTypes, UnittestExtensions.TestExtensionInsideTableExtension }, new pbr::GeneratedClrTypeInfo[] {
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllTypes), global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalGroup", "OptionalNestedMessage", "OptionalForeignMessage", "OptionalImportMessage", "OptionalNestedEnum", "OptionalForeignEnum", "OptionalImportEnum", "OptionalStringPiece", "OptionalCord", "OptionalPublicImportMessage", "OptionalLazyMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedGroup", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedImportMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedImportEnum", "RepeatedStringPiece", "RepeatedCord", "RepeatedLazyMessage", "DefaultInt32", "DefaultInt64", "DefaultUint32", "DefaultUint64", "DefaultSint32", "DefaultSint64", "DefaultFixed32", "DefaultFixed64", "DefaultSfixed32", "DefaultSfixed64", "DefaultFloat", "DefaultDouble", "DefaultBool", "DefaultString", "DefaultBytes", "DefaultNestedEnum", "DefaultForeignEnum", "DefaultImportEnum", "DefaultStringPiece", "DefaultCord", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes" }, new[]{ "OneofField" }, new[]{ typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser, new[]{ "Bb" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup), global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup.Parser, new[]{ "A" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup), global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup.Parser, new[]{ "A" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes), global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes.Parser, new[]{ "Child", "Payload", "RepeatedChild" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDeprecatedFields), global::Google.Protobuf.TestProtos.Proto2.TestDeprecatedFields.Parser, new[]{ "DeprecatedInt32", "DeprecatedInt32InOneof" }, new[]{ "OneofFields" }, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDeprecatedMessage), global::Google.Protobuf.TestProtos.Proto2.TestDeprecatedMessage.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.ForeignMessage), global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser, new[]{ "C", "D" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestReservedFields), global::Google.Protobuf.TestProtos.Proto2.TestReservedFields.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions), global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.OptionalGroup_extension), global::Google.Protobuf.TestProtos.Proto2.OptionalGroup_extension.Parser, new[]{ "A" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.RepeatedGroup_extension), global::Google.Protobuf.TestProtos.Proto2.RepeatedGroup_extension.Parser, new[]{ "A" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestGroup), global::Google.Protobuf.TestProtos.Proto2.TestGroup.Parser, new[]{ "OptionalGroup", "OptionalForeignEnum" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup), global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup.Parser, new[]{ "A" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension), global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension), global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Parser, null, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Extensions.Test, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Extensions.NestedStringExtension, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Extensions.OptionalGroupExtension, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Extensions.OptionalForeignEnumExtension }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Types.OptionalGroup_extension), global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Types.OptionalGroup_extension.Parser, new[]{ "A" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequired), global::Google.Protobuf.TestProtos.Proto2.TestRequired.Parser, new[]{ "A", "Dummy2", "B", "Dummy4", "Dummy5", "Dummy6", "Dummy7", "Dummy8", "Dummy9", "Dummy10", "Dummy11", "Dummy12", "Dummy13", "Dummy14", "Dummy15", "Dummy16", "Dummy17", "Dummy18", "Dummy19", "Dummy20", "Dummy21", "Dummy22", "Dummy23", "Dummy24", "Dummy25", "Dummy26", "Dummy27", "Dummy28", "Dummy29", "Dummy30", "Dummy31", "Dummy32", "C" }, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestRequired.Extensions.Single, global::Google.Protobuf.TestProtos.Proto2.TestRequired.Extensions.Multi }, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredForeign), global::Google.Protobuf.TestProtos.Proto2.TestRequiredForeign.Parser, new[]{ "OptionalMessage", "RepeatedMessage", "Dummy" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredMessage), global::Google.Protobuf.TestProtos.Proto2.TestRequiredMessage.Parser, new[]{ "OptionalMessage", "RepeatedMessage", "RequiredMessage" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestForeignNested), global::Google.Protobuf.TestProtos.Proto2.TestForeignNested.Parser, new[]{ "ForeignNested" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestEmptyMessage), global::Google.Protobuf.TestProtos.Proto2.TestEmptyMessage.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestEmptyMessageWithExtensions), global::Google.Protobuf.TestProtos.Proto2.TestEmptyMessageWithExtensions.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestMultipleExtensionRanges), global::Google.Protobuf.TestProtos.Proto2.TestMultipleExtensionRanges.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestReallyLargeTagNumber), global::Google.Protobuf.TestProtos.Proto2.TestReallyLargeTagNumber.Parser, new[]{ "A", "Bb" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage), global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage.Parser, new[]{ "A", "I" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA), global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Parser, new[]{ "Bb", "SubGroup" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage), global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage.Parser, new[]{ "B" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup), global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup.Parser, new[]{ "SubMessage", "NotInThisScc" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB), global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB.Parser, new[]{ "A", "OptionalInt32" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized), global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Parser, new[]{ "SubMessage" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage), global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Parser, new[]{ "SubGroup" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup), global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup.Parser, new[]{ "I" }, null, null, null, null)})}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber), global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Parser, new[]{ "A", "Foo", "Bar" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo), global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo.Parser, new[]{ "A" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar), global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar.Parser, new[]{ "A" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestEagerMessage), global::Google.Protobuf.TestProtos.Proto2.TestEagerMessage.Parser, new[]{ "SubMessage" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestLazyMessage), global::Google.Protobuf.TestProtos.Proto2.TestLazyMessage.Parser, new[]{ "SubMessage" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits), global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Parser, new[]{ "OptionalNestedMessage" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage.Parser, new[]{ "NestedmessageRepeatedInt32", "NestedmessageRepeatedForeignmessage" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestCamelCaseFieldNames), global::Google.Protobuf.TestProtos.Proto2.TestCamelCaseFieldNames.Parser, new[]{ "PrimitiveField", "StringField", "EnumField", "MessageField", "StringPieceField", "CordField", "RepeatedPrimitiveField", "RepeatedStringField", "RepeatedEnumField", "RepeatedMessageField", "RepeatedStringPieceField", "RepeatedCordField" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings), global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Parser, new[]{ "MyString", "MyInt", "MyFloat", "OptionalNestedMessage" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage.Parser, new[]{ "Oo", "Bb" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1), global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1.Parser, new[]{ "MyString" }, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1.Extensions.TestExtOrderings1 }, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2), global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Parser, new[]{ "MyString" }, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Extensions.TestExtOrderings2 }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3), global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3.Parser, new[]{ "MyString" }, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3.Extensions.TestExtOrderings3 }, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestExtremeDefaultValues), global::Google.Protobuf.TestProtos.Proto2.TestExtremeDefaultValues.Parser, new[]{ "EscapedBytes", "LargeUint32", "LargeUint64", "SmallInt32", "SmallInt64", "ReallySmallInt32", "ReallySmallInt64", "Utf8String", "ZeroFloat", "OneFloat", "SmallFloat", "NegativeOneFloat", "NegativeFloat", "LargeFloat", "SmallNegativeFloat", "InfDouble", "NegInfDouble", "NanDouble", "InfFloat", "NegInfFloat", "NanFloat", "CppTrigraph", "StringWithZero", "BytesWithZero", "StringPieceWithZero", "CordWithZero", "ReplacementString" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.SparseEnumMessage), global::Google.Protobuf.TestProtos.Proto2.SparseEnumMessage.Parser, new[]{ "SparseEnum" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.OneString), global::Google.Protobuf.TestProtos.Proto2.OneString.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.MoreString), global::Google.Protobuf.TestProtos.Proto2.MoreString.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.OneBytes), global::Google.Protobuf.TestProtos.Proto2.OneBytes.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.MoreBytes), global::Google.Protobuf.TestProtos.Proto2.MoreBytes.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.Int32Message), global::Google.Protobuf.TestProtos.Proto2.Int32Message.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.Uint32Message), global::Google.Protobuf.TestProtos.Proto2.Uint32Message.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.Int64Message), global::Google.Protobuf.TestProtos.Proto2.Int64Message.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.Uint64Message), global::Google.Protobuf.TestProtos.Proto2.Uint64Message.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.BoolMessage), global::Google.Protobuf.TestProtos.Proto2.BoolMessage.Parser, new[]{ "Data" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof), global::Google.Protobuf.TestProtos.Proto2.TestOneof.Parser, new[]{ "FooInt", "FooString", "FooMessage", "FooGroup" }, new[]{ "Foo" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup), global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup.Parser, new[]{ "A", "B" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible), global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Parser, new[]{ "FooInt", "FooString", "FooMessage", "FooGroup" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup), global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup.Parser, new[]{ "A", "B" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof2), global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Parser, new[]{ "FooInt", "FooString", "FooCord", "FooStringPiece", "FooBytes", "FooEnum", "FooMessage", "FooGroup", "FooLazyMessage", "BarInt", "BarString", "BarCord", "BarStringPiece", "BarBytes", "BarEnum", "BazInt", "BazString" }, new[]{ "Foo", "Bar" }, new[]{ typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup), global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup.Parser, new[]{ "A", "B" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage.Parser, new[]{ "QuxInt", "CorgeInt" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof), global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Parser, new[]{ "FooInt", "FooString", "FooMessage" }, new[]{ "Foo" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage.Parser, new[]{ "RequiredDouble" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap), global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Parser, new[]{ "Foo" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage), global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage.Parser, new[]{ "RequiredInt32" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestPackedTypes), global::Google.Protobuf.TestProtos.Proto2.TestPackedTypes.Parser, new[]{ "PackedInt32", "PackedInt64", "PackedUint32", "PackedUint64", "PackedSint32", "PackedSint64", "PackedFixed32", "PackedFixed64", "PackedSfixed32", "PackedSfixed64", "PackedFloat", "PackedDouble", "PackedBool", "PackedEnum" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestUnpackedTypes), global::Google.Protobuf.TestProtos.Proto2.TestUnpackedTypes.Parser, new[]{ "UnpackedInt32", "UnpackedInt64", "UnpackedUint32", "UnpackedUint64", "UnpackedSint32", "UnpackedSint64", "UnpackedFixed32", "UnpackedFixed64", "UnpackedSfixed32", "UnpackedSfixed64", "UnpackedFloat", "UnpackedDouble", "UnpackedBool", "UnpackedEnum" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions), global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions), global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions), global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Parser, new[]{ "ScalarExtension", "EnumExtension", "DynamicEnumExtension", "MessageExtension", "DynamicMessageExtension", "RepeatedExtension", "PackedExtension" }, null, new[]{ typeof(global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType), global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType.Parser, new[]{ "DynamicField" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestRepeatedScalarDifferentTagSizes), global::Google.Protobuf.TestProtos.Proto2.TestRepeatedScalarDifferentTagSizes.Parser, new[]{ "RepeatedFixed32", "RepeatedInt32", "RepeatedFixed64", "RepeatedInt64", "RepeatedFloat", "RepeatedUint64" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Parser, new[]{ "RequiredAllTypes", "OptionalAllTypes", "RepeatedAllTypes", "OptionalGroup", "RepeatedGroup" }, null, null, new pb::Extension[] { global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Extensions.OptionalExt, global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Extensions.RepeatedExt }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Parser, new[]{ "Field1", "Field2", "Field3", "Group1", "Group2", "Ext1", "Ext2" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1.Parser, new[]{ "Field1" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2.Parser, new[]{ "Field1" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup.Parser, new[]{ "OptionalGroupAllTypes" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup), global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup.Parser, new[]{ "RepeatedGroupAllTypes" }, null, null, null, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestCommentInjectionMessage), global::Google.Protobuf.TestProtos.Proto2.TestCommentInjectionMessage.Parser, new[]{ "A" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.FooRequest), global::Google.Protobuf.TestProtos.Proto2.FooRequest.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.FooResponse), global::Google.Protobuf.TestProtos.Proto2.FooResponse.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.FooClientMessage), global::Google.Protobuf.TestProtos.Proto2.FooClientMessage.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.FooServerMessage), global::Google.Protobuf.TestProtos.Proto2.FooServerMessage.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.BarRequest), global::Google.Protobuf.TestProtos.Proto2.BarRequest.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.BarResponse), global::Google.Protobuf.TestProtos.Proto2.BarResponse.Parser, null, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestJsonName), global::Google.Protobuf.TestProtos.Proto2.TestJsonName.Parser, new[]{ "FieldName1", "FieldName2", "FieldName3", "FieldName4", "FIELDNAME5", "FieldName6" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers), global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Parser, new[]{ "OptionalInt32", "Fixed32", "RepeatedInt32", "PackedInt32", "OptionalEnum", "OptionalString", "OptionalBytes", "OptionalMessage", "OptionalGroup", "StringStringMap", "OneofUint32", "OneofTestAllTypes", "OneofString", "OneofBytes" }, new[]{ "OneofField" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup), global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup.Parser, new[]{ "GroupA" }, null, null, null, null),
            null, }),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Proto2.TestExtensionInsideTable), global::Google.Protobuf.TestProtos.Proto2.TestExtensionInsideTable.Parser, new[]{ "Field1", "Field2", "Field3", "Field4", "Field6", "Field7", "Field8", "Field9", "Field10" }, null, null, null, null)
          }));
    }
    #endregion

  }
  /// <summary>Holder for extension identifiers generated from the top level of csharp/protos/unittest.proto</summary>
  public static partial class UnittestExtensions {
    /// <summary>
    /// Singular
    /// </summary>
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> OptionalInt32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(1, pb::FieldCodec.ForInt32(8, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> OptionalInt64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(2, pb::FieldCodec.ForInt64(16, 0L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> OptionalUint32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(3, pb::FieldCodec.ForUInt32(24, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> OptionalUint64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(4, pb::FieldCodec.ForUInt64(32, 0UL));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> OptionalSint32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(5, pb::FieldCodec.ForSInt32(40, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> OptionalSint64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(6, pb::FieldCodec.ForSInt64(48, 0L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> OptionalFixed32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(7, pb::FieldCodec.ForFixed32(61, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> OptionalFixed64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(8, pb::FieldCodec.ForFixed64(65, 0UL));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> OptionalSfixed32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(9, pb::FieldCodec.ForSFixed32(77, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> OptionalSfixed64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(10, pb::FieldCodec.ForSFixed64(81, 0L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float> OptionalFloatExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float>(11, pb::FieldCodec.ForFloat(93, 0F));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double> OptionalDoubleExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double>(12, pb::FieldCodec.ForDouble(97, 0D));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool> OptionalBoolExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool>(13, pb::FieldCodec.ForBool(104, false));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> OptionalStringExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(14, pb::FieldCodec.ForString(114, ""));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> OptionalBytesExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(15, pb::FieldCodec.ForBytes(122, pb::ByteString.Empty));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.OptionalGroup_extension> OptionalGroupExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.OptionalGroup_extension>(16, pb::FieldCodec.ForGroup(131, 132, global::Google.Protobuf.TestProtos.Proto2.OptionalGroup_extension.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> OptionalNestedMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>(18, pb::FieldCodec.ForMessage(146, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> OptionalForeignMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage>(19, pb::FieldCodec.ForMessage(154, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportMessage> OptionalImportMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportMessage>(20, pb::FieldCodec.ForMessage(162, global::Google.Protobuf.TestProtos.Proto2.ImportMessage.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> OptionalNestedEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum>(21, pb::FieldCodec.ForEnum(168, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) x, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum.Foo));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> OptionalForeignEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(22, pb::FieldCodec.ForEnum(176, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum> OptionalImportEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum>(23, pb::FieldCodec.ForEnum(184, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x, global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportFoo));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> OptionalStringPieceExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(24, pb::FieldCodec.ForString(194, ""));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> OptionalCordExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(25, pb::FieldCodec.ForString(202, ""));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage> OptionalPublicImportMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage>(26, pb::FieldCodec.ForMessage(210, global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> OptionalLazyMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>(27, pb::FieldCodec.ForMessage(218, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser));
    /// <summary>
    /// Repeated
    /// </summary>
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> RepeatedInt32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(31, pb::FieldCodec.ForInt32(248));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> RepeatedInt64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(32, pb::FieldCodec.ForInt64(256));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> RepeatedUint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(33, pb::FieldCodec.ForUInt32(264));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> RepeatedUint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(34, pb::FieldCodec.ForUInt64(272));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> RepeatedSint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(35, pb::FieldCodec.ForSInt32(280));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> RepeatedSint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(36, pb::FieldCodec.ForSInt64(288));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> RepeatedFixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(37, pb::FieldCodec.ForFixed32(301));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> RepeatedFixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(38, pb::FieldCodec.ForFixed64(305));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> RepeatedSfixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(39, pb::FieldCodec.ForSFixed32(317));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> RepeatedSfixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(40, pb::FieldCodec.ForSFixed64(321));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float> RepeatedFloatExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float>(41, pb::FieldCodec.ForFloat(333));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double> RepeatedDoubleExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double>(42, pb::FieldCodec.ForDouble(337));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool> RepeatedBoolExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool>(43, pb::FieldCodec.ForBool(344));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> RepeatedStringExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(44, pb::FieldCodec.ForString(354));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> RepeatedBytesExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(45, pb::FieldCodec.ForBytes(362));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.RepeatedGroup_extension> RepeatedGroupExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.RepeatedGroup_extension>(46, pb::FieldCodec.ForGroup(371, 372, global::Google.Protobuf.TestProtos.Proto2.RepeatedGroup_extension.Parser));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> RepeatedNestedMessageExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>(48, pb::FieldCodec.ForMessage(386, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> RepeatedForeignMessageExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage>(49, pb::FieldCodec.ForMessage(394, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportMessage> RepeatedImportMessageExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportMessage>(50, pb::FieldCodec.ForMessage(402, global::Google.Protobuf.TestProtos.Proto2.ImportMessage.Parser));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> RepeatedNestedEnumExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum>(51, pb::FieldCodec.ForEnum(408, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) x));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> RepeatedForeignEnumExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(52, pb::FieldCodec.ForEnum(416, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum> RepeatedImportEnumExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum>(53, pb::FieldCodec.ForEnum(424, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> RepeatedStringPieceExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(54, pb::FieldCodec.ForString(434));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> RepeatedCordExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(55, pb::FieldCodec.ForString(442));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> RepeatedLazyMessageExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>(57, pb::FieldCodec.ForMessage(458, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser));
    /// <summary>
    /// Singular with defaults
    /// </summary>
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> DefaultInt32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(61, pb::FieldCodec.ForInt32(488, 41));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> DefaultInt64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(62, pb::FieldCodec.ForInt64(496, 42L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> DefaultUint32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(63, pb::FieldCodec.ForUInt32(504, 43));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> DefaultUint64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(64, pb::FieldCodec.ForUInt64(512, 44UL));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> DefaultSint32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(65, pb::FieldCodec.ForSInt32(520, -45));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> DefaultSint64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(66, pb::FieldCodec.ForSInt64(528, 46L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> DefaultFixed32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(67, pb::FieldCodec.ForFixed32(541, 47));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong> DefaultFixed64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, ulong>(68, pb::FieldCodec.ForFixed64(545, 48UL));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int> DefaultSfixed32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, int>(69, pb::FieldCodec.ForSFixed32(557, 49));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long> DefaultSfixed64Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, long>(70, pb::FieldCodec.ForSFixed64(561, -50L));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float> DefaultFloatExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, float>(71, pb::FieldCodec.ForFloat(573, 51.5F));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double> DefaultDoubleExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, double>(72, pb::FieldCodec.ForDouble(577, 52000D));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool> DefaultBoolExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool>(73, pb::FieldCodec.ForBool(584, true));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(74, pb::FieldCodec.ForString(594, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsbG8="), 0, 5)));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> DefaultBytesExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(75, pb::FieldCodec.ForBytes(602, pb::ByteString.FromBase64("d29ybGQ=")));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> DefaultNestedEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum>(81, pb::FieldCodec.ForEnum(648, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) x, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum.Bar));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> DefaultForeignEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(82, pb::FieldCodec.ForEnum(656, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignBar));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum> DefaultImportEnumExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum>(83, pb::FieldCodec.ForEnum(664, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x, global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportBar));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringPieceExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(84, pb::FieldCodec.ForString(674, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWJj"), 0, 3)));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultCordExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(85, pb::FieldCodec.ForString(682, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIz"), 0, 3)));
    /// <summary>
    /// For oneof test
    /// </summary>
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint> OneofUint32Extension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, uint>(111, pb::FieldCodec.ForUInt32(888, 0));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> OneofNestedMessageExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>(112, pb::FieldCodec.ForMessage(898, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> OneofStringExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(113, pb::FieldCodec.ForString(906, ""));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> OneofBytesExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(114, pb::FieldCodec.ForBytes(914, pb::ByteString.Empty));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, string> MyExtensionString =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, string>(50, pb::FieldCodec.ForString(402, ""));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, int> MyExtensionInt =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, int>(5, pb::FieldCodec.ForInt32(40, 0));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int> PackedInt32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int>(90, pb::FieldCodec.ForInt32(722));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long> PackedInt64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long>(91, pb::FieldCodec.ForInt64(730));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, uint> PackedUint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, uint>(92, pb::FieldCodec.ForUInt32(738));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, ulong> PackedUint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, ulong>(93, pb::FieldCodec.ForUInt64(746));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int> PackedSint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int>(94, pb::FieldCodec.ForSInt32(754));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long> PackedSint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long>(95, pb::FieldCodec.ForSInt64(762));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, uint> PackedFixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, uint>(96, pb::FieldCodec.ForFixed32(770));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, ulong> PackedFixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, ulong>(97, pb::FieldCodec.ForFixed64(778));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int> PackedSfixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, int>(98, pb::FieldCodec.ForSFixed32(786));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long> PackedSfixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, long>(99, pb::FieldCodec.ForSFixed64(794));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, float> PackedFloatExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, float>(100, pb::FieldCodec.ForFloat(802));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, double> PackedDoubleExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, double>(101, pb::FieldCodec.ForDouble(810));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, bool> PackedBoolExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, bool>(102, pb::FieldCodec.ForBool(818));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> PackedEnumExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestPackedExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(103, pb::FieldCodec.ForEnum(826, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int> UnpackedInt32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int>(90, pb::FieldCodec.ForInt32(720));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long> UnpackedInt64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long>(91, pb::FieldCodec.ForInt64(728));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, uint> UnpackedUint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, uint>(92, pb::FieldCodec.ForUInt32(736));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, ulong> UnpackedUint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, ulong>(93, pb::FieldCodec.ForUInt64(744));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int> UnpackedSint32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int>(94, pb::FieldCodec.ForSInt32(752));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long> UnpackedSint64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long>(95, pb::FieldCodec.ForSInt64(760));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, uint> UnpackedFixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, uint>(96, pb::FieldCodec.ForFixed32(773));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, ulong> UnpackedFixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, ulong>(97, pb::FieldCodec.ForFixed64(777));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int> UnpackedSfixed32Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, int>(98, pb::FieldCodec.ForSFixed32(789));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long> UnpackedSfixed64Extension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, long>(99, pb::FieldCodec.ForSFixed64(793));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, float> UnpackedFloatExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, float>(100, pb::FieldCodec.ForFloat(805));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, double> UnpackedDoubleExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, double>(101, pb::FieldCodec.ForDouble(809));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, bool> UnpackedBoolExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, bool>(102, pb::FieldCodec.ForBool(816));
    public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> UnpackedEnumExtension =
      new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestUnpackedExtensions, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(103, pb::FieldCodec.ForEnum(824, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> TestAllTypes =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>(536860000, pb::FieldCodec.ForMessage(4294880002, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser));
    public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestExtensionInsideTable, int> TestExtensionInsideTableExtension =
      new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestExtensionInsideTable, int>(5, pb::FieldCodec.ForInt32(40, 0));
  }

  #region Enums
  public enum ForeignEnum {
    [pbr::OriginalName("FOREIGN_FOO")] ForeignFoo = 4,
    [pbr::OriginalName("FOREIGN_BAR")] ForeignBar = 5,
    [pbr::OriginalName("FOREIGN_BAZ")] ForeignBaz = 6,
  }

  /// <summary>
  /// Test an enum that has multiple values with the same number.
  /// </summary>
  public enum TestEnumWithDupValue {
    [pbr::OriginalName("FOO1")] Foo1 = 1,
    [pbr::OriginalName("BAR1")] Bar1 = 2,
    [pbr::OriginalName("BAZ")] Baz = 3,
    [pbr::OriginalName("FOO2", PreferredAlias = false)] Foo2 = 1,
    [pbr::OriginalName("BAR2", PreferredAlias = false)] Bar2 = 2,
  }

  /// <summary>
  /// Test an enum with large, unordered values.
  /// </summary>
  public enum TestSparseEnum {
    [pbr::OriginalName("SPARSE_A")] SparseA = 123,
    [pbr::OriginalName("SPARSE_B")] SparseB = 62374,
    [pbr::OriginalName("SPARSE_C")] SparseC = 12589234,
    [pbr::OriginalName("SPARSE_D")] SparseD = -15,
    [pbr::OriginalName("SPARSE_E")] SparseE = -53452,
    [pbr::OriginalName("SPARSE_F")] SparseF = 0,
    [pbr::OriginalName("SPARSE_G")] SparseG = 2,
  }

  public enum VeryLargeEnum {
    [pbr::OriginalName("ENUM_LABEL_DEFAULT")] EnumLabelDefault = 0,
    [pbr::OriginalName("ENUM_LABEL_1")] EnumLabel1 = 1,
    [pbr::OriginalName("ENUM_LABEL_2")] EnumLabel2 = 2,
    [pbr::OriginalName("ENUM_LABEL_3")] EnumLabel3 = 3,
    [pbr::OriginalName("ENUM_LABEL_4")] EnumLabel4 = 4,
    [pbr::OriginalName("ENUM_LABEL_5")] EnumLabel5 = 5,
    [pbr::OriginalName("ENUM_LABEL_6")] EnumLabel6 = 6,
    [pbr::OriginalName("ENUM_LABEL_7")] EnumLabel7 = 7,
    [pbr::OriginalName("ENUM_LABEL_8")] EnumLabel8 = 8,
    [pbr::OriginalName("ENUM_LABEL_9")] EnumLabel9 = 9,
    [pbr::OriginalName("ENUM_LABEL_10")] EnumLabel10 = 10,
    [pbr::OriginalName("ENUM_LABEL_11")] EnumLabel11 = 11,
    [pbr::OriginalName("ENUM_LABEL_12")] EnumLabel12 = 12,
    [pbr::OriginalName("ENUM_LABEL_13")] EnumLabel13 = 13,
    [pbr::OriginalName("ENUM_LABEL_14")] EnumLabel14 = 14,
    [pbr::OriginalName("ENUM_LABEL_15")] EnumLabel15 = 15,
    [pbr::OriginalName("ENUM_LABEL_16")] EnumLabel16 = 16,
    [pbr::OriginalName("ENUM_LABEL_17")] EnumLabel17 = 17,
    [pbr::OriginalName("ENUM_LABEL_18")] EnumLabel18 = 18,
    [pbr::OriginalName("ENUM_LABEL_19")] EnumLabel19 = 19,
    [pbr::OriginalName("ENUM_LABEL_20")] EnumLabel20 = 20,
    [pbr::OriginalName("ENUM_LABEL_21")] EnumLabel21 = 21,
    [pbr::OriginalName("ENUM_LABEL_22")] EnumLabel22 = 22,
    [pbr::OriginalName("ENUM_LABEL_23")] EnumLabel23 = 23,
    [pbr::OriginalName("ENUM_LABEL_24")] EnumLabel24 = 24,
    [pbr::OriginalName("ENUM_LABEL_25")] EnumLabel25 = 25,
    [pbr::OriginalName("ENUM_LABEL_26")] EnumLabel26 = 26,
    [pbr::OriginalName("ENUM_LABEL_27")] EnumLabel27 = 27,
    [pbr::OriginalName("ENUM_LABEL_28")] EnumLabel28 = 28,
    [pbr::OriginalName("ENUM_LABEL_29")] EnumLabel29 = 29,
    [pbr::OriginalName("ENUM_LABEL_30")] EnumLabel30 = 30,
    [pbr::OriginalName("ENUM_LABEL_31")] EnumLabel31 = 31,
    [pbr::OriginalName("ENUM_LABEL_32")] EnumLabel32 = 32,
    [pbr::OriginalName("ENUM_LABEL_33")] EnumLabel33 = 33,
    [pbr::OriginalName("ENUM_LABEL_34")] EnumLabel34 = 34,
    [pbr::OriginalName("ENUM_LABEL_35")] EnumLabel35 = 35,
    [pbr::OriginalName("ENUM_LABEL_36")] EnumLabel36 = 36,
    [pbr::OriginalName("ENUM_LABEL_37")] EnumLabel37 = 37,
    [pbr::OriginalName("ENUM_LABEL_38")] EnumLabel38 = 38,
    [pbr::OriginalName("ENUM_LABEL_39")] EnumLabel39 = 39,
    [pbr::OriginalName("ENUM_LABEL_40")] EnumLabel40 = 40,
    [pbr::OriginalName("ENUM_LABEL_41")] EnumLabel41 = 41,
    [pbr::OriginalName("ENUM_LABEL_42")] EnumLabel42 = 42,
    [pbr::OriginalName("ENUM_LABEL_43")] EnumLabel43 = 43,
    [pbr::OriginalName("ENUM_LABEL_44")] EnumLabel44 = 44,
    [pbr::OriginalName("ENUM_LABEL_45")] EnumLabel45 = 45,
    [pbr::OriginalName("ENUM_LABEL_46")] EnumLabel46 = 46,
    [pbr::OriginalName("ENUM_LABEL_47")] EnumLabel47 = 47,
    [pbr::OriginalName("ENUM_LABEL_48")] EnumLabel48 = 48,
    [pbr::OriginalName("ENUM_LABEL_49")] EnumLabel49 = 49,
    [pbr::OriginalName("ENUM_LABEL_50")] EnumLabel50 = 50,
    [pbr::OriginalName("ENUM_LABEL_51")] EnumLabel51 = 51,
    [pbr::OriginalName("ENUM_LABEL_52")] EnumLabel52 = 52,
    [pbr::OriginalName("ENUM_LABEL_53")] EnumLabel53 = 53,
    [pbr::OriginalName("ENUM_LABEL_54")] EnumLabel54 = 54,
    [pbr::OriginalName("ENUM_LABEL_55")] EnumLabel55 = 55,
    [pbr::OriginalName("ENUM_LABEL_56")] EnumLabel56 = 56,
    [pbr::OriginalName("ENUM_LABEL_57")] EnumLabel57 = 57,
    [pbr::OriginalName("ENUM_LABEL_58")] EnumLabel58 = 58,
    [pbr::OriginalName("ENUM_LABEL_59")] EnumLabel59 = 59,
    [pbr::OriginalName("ENUM_LABEL_60")] EnumLabel60 = 60,
    [pbr::OriginalName("ENUM_LABEL_61")] EnumLabel61 = 61,
    [pbr::OriginalName("ENUM_LABEL_62")] EnumLabel62 = 62,
    [pbr::OriginalName("ENUM_LABEL_63")] EnumLabel63 = 63,
    [pbr::OriginalName("ENUM_LABEL_64")] EnumLabel64 = 64,
    [pbr::OriginalName("ENUM_LABEL_65")] EnumLabel65 = 65,
    [pbr::OriginalName("ENUM_LABEL_66")] EnumLabel66 = 66,
    [pbr::OriginalName("ENUM_LABEL_67")] EnumLabel67 = 67,
    [pbr::OriginalName("ENUM_LABEL_68")] EnumLabel68 = 68,
    [pbr::OriginalName("ENUM_LABEL_69")] EnumLabel69 = 69,
    [pbr::OriginalName("ENUM_LABEL_70")] EnumLabel70 = 70,
    [pbr::OriginalName("ENUM_LABEL_71")] EnumLabel71 = 71,
    [pbr::OriginalName("ENUM_LABEL_72")] EnumLabel72 = 72,
    [pbr::OriginalName("ENUM_LABEL_73")] EnumLabel73 = 73,
    [pbr::OriginalName("ENUM_LABEL_74")] EnumLabel74 = 74,
    [pbr::OriginalName("ENUM_LABEL_75")] EnumLabel75 = 75,
    [pbr::OriginalName("ENUM_LABEL_76")] EnumLabel76 = 76,
    [pbr::OriginalName("ENUM_LABEL_77")] EnumLabel77 = 77,
    [pbr::OriginalName("ENUM_LABEL_78")] EnumLabel78 = 78,
    [pbr::OriginalName("ENUM_LABEL_79")] EnumLabel79 = 79,
    [pbr::OriginalName("ENUM_LABEL_80")] EnumLabel80 = 80,
    [pbr::OriginalName("ENUM_LABEL_81")] EnumLabel81 = 81,
    [pbr::OriginalName("ENUM_LABEL_82")] EnumLabel82 = 82,
    [pbr::OriginalName("ENUM_LABEL_83")] EnumLabel83 = 83,
    [pbr::OriginalName("ENUM_LABEL_84")] EnumLabel84 = 84,
    [pbr::OriginalName("ENUM_LABEL_85")] EnumLabel85 = 85,
    [pbr::OriginalName("ENUM_LABEL_86")] EnumLabel86 = 86,
    [pbr::OriginalName("ENUM_LABEL_87")] EnumLabel87 = 87,
    [pbr::OriginalName("ENUM_LABEL_88")] EnumLabel88 = 88,
    [pbr::OriginalName("ENUM_LABEL_89")] EnumLabel89 = 89,
    [pbr::OriginalName("ENUM_LABEL_90")] EnumLabel90 = 90,
    [pbr::OriginalName("ENUM_LABEL_91")] EnumLabel91 = 91,
    [pbr::OriginalName("ENUM_LABEL_92")] EnumLabel92 = 92,
    [pbr::OriginalName("ENUM_LABEL_93")] EnumLabel93 = 93,
    [pbr::OriginalName("ENUM_LABEL_94")] EnumLabel94 = 94,
    [pbr::OriginalName("ENUM_LABEL_95")] EnumLabel95 = 95,
    [pbr::OriginalName("ENUM_LABEL_96")] EnumLabel96 = 96,
    [pbr::OriginalName("ENUM_LABEL_97")] EnumLabel97 = 97,
    [pbr::OriginalName("ENUM_LABEL_98")] EnumLabel98 = 98,
    [pbr::OriginalName("ENUM_LABEL_99")] EnumLabel99 = 99,
    [pbr::OriginalName("ENUM_LABEL_100")] EnumLabel100 = 100,
  }

  #endregion

  #region Messages
  /// <summary>
  /// This proto includes every type of field in both singular and repeated
  /// forms.
  /// </summary>
  public sealed partial class TestAllTypes : pb::IMessage<TestAllTypes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestAllTypes> _parser = new pb::MessageParser<TestAllTypes>(() => new TestAllTypes());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    private int _hasBits1;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestAllTypes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[0]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllTypes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllTypes(TestAllTypes other) : this() {
      _hasBits0 = other._hasBits0;
      _hasBits1 = other._hasBits1;
      optionalInt32_ = other.optionalInt32_;
      optionalInt64_ = other.optionalInt64_;
      optionalUint32_ = other.optionalUint32_;
      optionalUint64_ = other.optionalUint64_;
      optionalSint32_ = other.optionalSint32_;
      optionalSint64_ = other.optionalSint64_;
      optionalFixed32_ = other.optionalFixed32_;
      optionalFixed64_ = other.optionalFixed64_;
      optionalSfixed32_ = other.optionalSfixed32_;
      optionalSfixed64_ = other.optionalSfixed64_;
      optionalFloat_ = other.optionalFloat_;
      optionalDouble_ = other.optionalDouble_;
      optionalBool_ = other.optionalBool_;
      optionalString_ = other.optionalString_;
      optionalBytes_ = other.optionalBytes_;
      optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null;
      optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
      optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null;
      optionalImportMessage_ = other.optionalImportMessage_ != null ? other.optionalImportMessage_.Clone() : null;
      optionalNestedEnum_ = other.optionalNestedEnum_;
      optionalForeignEnum_ = other.optionalForeignEnum_;
      optionalImportEnum_ = other.optionalImportEnum_;
      optionalStringPiece_ = other.optionalStringPiece_;
      optionalCord_ = other.optionalCord_;
      optionalPublicImportMessage_ = other.optionalPublicImportMessage_ != null ? other.optionalPublicImportMessage_.Clone() : null;
      optionalLazyMessage_ = other.optionalLazyMessage_ != null ? other.optionalLazyMessage_.Clone() : null;
      repeatedInt32_ = other.repeatedInt32_.Clone();
      repeatedInt64_ = other.repeatedInt64_.Clone();
      repeatedUint32_ = other.repeatedUint32_.Clone();
      repeatedUint64_ = other.repeatedUint64_.Clone();
      repeatedSint32_ = other.repeatedSint32_.Clone();
      repeatedSint64_ = other.repeatedSint64_.Clone();
      repeatedFixed32_ = other.repeatedFixed32_.Clone();
      repeatedFixed64_ = other.repeatedFixed64_.Clone();
      repeatedSfixed32_ = other.repeatedSfixed32_.Clone();
      repeatedSfixed64_ = other.repeatedSfixed64_.Clone();
      repeatedFloat_ = other.repeatedFloat_.Clone();
      repeatedDouble_ = other.repeatedDouble_.Clone();
      repeatedBool_ = other.repeatedBool_.Clone();
      repeatedString_ = other.repeatedString_.Clone();
      repeatedBytes_ = other.repeatedBytes_.Clone();
      repeatedGroup_ = other.repeatedGroup_.Clone();
      repeatedNestedMessage_ = other.repeatedNestedMessage_.Clone();
      repeatedForeignMessage_ = other.repeatedForeignMessage_.Clone();
      repeatedImportMessage_ = other.repeatedImportMessage_.Clone();
      repeatedNestedEnum_ = other.repeatedNestedEnum_.Clone();
      repeatedForeignEnum_ = other.repeatedForeignEnum_.Clone();
      repeatedImportEnum_ = other.repeatedImportEnum_.Clone();
      repeatedStringPiece_ = other.repeatedStringPiece_.Clone();
      repeatedCord_ = other.repeatedCord_.Clone();
      repeatedLazyMessage_ = other.repeatedLazyMessage_.Clone();
      defaultInt32_ = other.defaultInt32_;
      defaultInt64_ = other.defaultInt64_;
      defaultUint32_ = other.defaultUint32_;
      defaultUint64_ = other.defaultUint64_;
      defaultSint32_ = other.defaultSint32_;
      defaultSint64_ = other.defaultSint64_;
      defaultFixed32_ = other.defaultFixed32_;
      defaultFixed64_ = other.defaultFixed64_;
      defaultSfixed32_ = other.defaultSfixed32_;
      defaultSfixed64_ = other.defaultSfixed64_;
      defaultFloat_ = other.defaultFloat_;
      defaultDouble_ = other.defaultDouble_;
      defaultBool_ = other.defaultBool_;
      defaultString_ = other.defaultString_;
      defaultBytes_ = other.defaultBytes_;
      defaultNestedEnum_ = other.defaultNestedEnum_;
      defaultForeignEnum_ = other.defaultForeignEnum_;
      defaultImportEnum_ = other.defaultImportEnum_;
      defaultStringPiece_ = other.defaultStringPiece_;
      defaultCord_ = other.defaultCord_;
      switch (other.OneofFieldCase) {
        case OneofFieldOneofCase.OneofUint32:
          OneofUint32 = other.OneofUint32;
          break;
        case OneofFieldOneofCase.OneofNestedMessage:
          OneofNestedMessage = other.OneofNestedMessage.Clone();
          break;
        case OneofFieldOneofCase.OneofString:
          OneofString = other.OneofString;
          break;
        case OneofFieldOneofCase.OneofBytes:
          OneofBytes = other.OneofBytes;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllTypes Clone() {
      return new TestAllTypes(this);
    }

    /// <summary>Field number for the "optional_int32" field.</summary>
    public const int OptionalInt32FieldNumber = 1;
    private readonly static int OptionalInt32DefaultValue = 0;

    private int optionalInt32_;
    /// <summary>
    /// Singular
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int OptionalInt32 {
      get { if ((_hasBits0 & 1) != 0) { return optionalInt32_; } else { return OptionalInt32DefaultValue; } }
      set {
        _hasBits0 |= 1;
        optionalInt32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalInt32 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "optional_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalInt32() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "optional_int64" field.</summary>
    public const int OptionalInt64FieldNumber = 2;
    private readonly static long OptionalInt64DefaultValue = 0L;

    private long optionalInt64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long OptionalInt64 {
      get { if ((_hasBits0 & 2) != 0) { return optionalInt64_; } else { return OptionalInt64DefaultValue; } }
      set {
        _hasBits0 |= 2;
        optionalInt64_ = value;
      }
    }
    /// <summary>Gets whether the "optional_int64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalInt64 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "optional_int64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalInt64() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "optional_uint32" field.</summary>
    public const int OptionalUint32FieldNumber = 3;
    private readonly static uint OptionalUint32DefaultValue = 0;

    private uint optionalUint32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint OptionalUint32 {
      get { if ((_hasBits0 & 4) != 0) { return optionalUint32_; } else { return OptionalUint32DefaultValue; } }
      set {
        _hasBits0 |= 4;
        optionalUint32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_uint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalUint32 {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "optional_uint32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalUint32() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "optional_uint64" field.</summary>
    public const int OptionalUint64FieldNumber = 4;
    private readonly static ulong OptionalUint64DefaultValue = 0UL;

    private ulong optionalUint64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong OptionalUint64 {
      get { if ((_hasBits0 & 8) != 0) { return optionalUint64_; } else { return OptionalUint64DefaultValue; } }
      set {
        _hasBits0 |= 8;
        optionalUint64_ = value;
      }
    }
    /// <summary>Gets whether the "optional_uint64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalUint64 {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "optional_uint64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalUint64() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "optional_sint32" field.</summary>
    public const int OptionalSint32FieldNumber = 5;
    private readonly static int OptionalSint32DefaultValue = 0;

    private int optionalSint32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int OptionalSint32 {
      get { if ((_hasBits0 & 16) != 0) { return optionalSint32_; } else { return OptionalSint32DefaultValue; } }
      set {
        _hasBits0 |= 16;
        optionalSint32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_sint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalSint32 {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "optional_sint32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalSint32() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "optional_sint64" field.</summary>
    public const int OptionalSint64FieldNumber = 6;
    private readonly static long OptionalSint64DefaultValue = 0L;

    private long optionalSint64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long OptionalSint64 {
      get { if ((_hasBits0 & 32) != 0) { return optionalSint64_; } else { return OptionalSint64DefaultValue; } }
      set {
        _hasBits0 |= 32;
        optionalSint64_ = value;
      }
    }
    /// <summary>Gets whether the "optional_sint64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalSint64 {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "optional_sint64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalSint64() {
      _hasBits0 &= ~32;
    }

    /// <summary>Field number for the "optional_fixed32" field.</summary>
    public const int OptionalFixed32FieldNumber = 7;
    private readonly static uint OptionalFixed32DefaultValue = 0;

    private uint optionalFixed32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint OptionalFixed32 {
      get { if ((_hasBits0 & 64) != 0) { return optionalFixed32_; } else { return OptionalFixed32DefaultValue; } }
      set {
        _hasBits0 |= 64;
        optionalFixed32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_fixed32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalFixed32 {
      get { return (_hasBits0 & 64) != 0; }
    }
    /// <summary>Clears the value of the "optional_fixed32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalFixed32() {
      _hasBits0 &= ~64;
    }

    /// <summary>Field number for the "optional_fixed64" field.</summary>
    public const int OptionalFixed64FieldNumber = 8;
    private readonly static ulong OptionalFixed64DefaultValue = 0UL;

    private ulong optionalFixed64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong OptionalFixed64 {
      get { if ((_hasBits0 & 128) != 0) { return optionalFixed64_; } else { return OptionalFixed64DefaultValue; } }
      set {
        _hasBits0 |= 128;
        optionalFixed64_ = value;
      }
    }
    /// <summary>Gets whether the "optional_fixed64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalFixed64 {
      get { return (_hasBits0 & 128) != 0; }
    }
    /// <summary>Clears the value of the "optional_fixed64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalFixed64() {
      _hasBits0 &= ~128;
    }

    /// <summary>Field number for the "optional_sfixed32" field.</summary>
    public const int OptionalSfixed32FieldNumber = 9;
    private readonly static int OptionalSfixed32DefaultValue = 0;

    private int optionalSfixed32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int OptionalSfixed32 {
      get { if ((_hasBits0 & 256) != 0) { return optionalSfixed32_; } else { return OptionalSfixed32DefaultValue; } }
      set {
        _hasBits0 |= 256;
        optionalSfixed32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_sfixed32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalSfixed32 {
      get { return (_hasBits0 & 256) != 0; }
    }
    /// <summary>Clears the value of the "optional_sfixed32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalSfixed32() {
      _hasBits0 &= ~256;
    }

    /// <summary>Field number for the "optional_sfixed64" field.</summary>
    public const int OptionalSfixed64FieldNumber = 10;
    private readonly static long OptionalSfixed64DefaultValue = 0L;

    private long optionalSfixed64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long OptionalSfixed64 {
      get { if ((_hasBits0 & 512) != 0) { return optionalSfixed64_; } else { return OptionalSfixed64DefaultValue; } }
      set {
        _hasBits0 |= 512;
        optionalSfixed64_ = value;
      }
    }
    /// <summary>Gets whether the "optional_sfixed64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalSfixed64 {
      get { return (_hasBits0 & 512) != 0; }
    }
    /// <summary>Clears the value of the "optional_sfixed64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalSfixed64() {
      _hasBits0 &= ~512;
    }

    /// <summary>Field number for the "optional_float" field.</summary>
    public const int OptionalFloatFieldNumber = 11;
    private readonly static float OptionalFloatDefaultValue = 0F;

    private float optionalFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float OptionalFloat {
      get { if ((_hasBits0 & 1024) != 0) { return optionalFloat_; } else { return OptionalFloatDefaultValue; } }
      set {
        _hasBits0 |= 1024;
        optionalFloat_ = value;
      }
    }
    /// <summary>Gets whether the "optional_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalFloat {
      get { return (_hasBits0 & 1024) != 0; }
    }
    /// <summary>Clears the value of the "optional_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalFloat() {
      _hasBits0 &= ~1024;
    }

    /// <summary>Field number for the "optional_double" field.</summary>
    public const int OptionalDoubleFieldNumber = 12;
    private readonly static double OptionalDoubleDefaultValue = 0D;

    private double optionalDouble_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public double OptionalDouble {
      get { if ((_hasBits0 & 2048) != 0) { return optionalDouble_; } else { return OptionalDoubleDefaultValue; } }
      set {
        _hasBits0 |= 2048;
        optionalDouble_ = value;
      }
    }
    /// <summary>Gets whether the "optional_double" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalDouble {
      get { return (_hasBits0 & 2048) != 0; }
    }
    /// <summary>Clears the value of the "optional_double" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalDouble() {
      _hasBits0 &= ~2048;
    }

    /// <summary>Field number for the "optional_bool" field.</summary>
    public const int OptionalBoolFieldNumber = 13;
    private readonly static bool OptionalBoolDefaultValue = false;

    private bool optionalBool_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool OptionalBool {
      get { if ((_hasBits0 & 4096) != 0) { return optionalBool_; } else { return OptionalBoolDefaultValue; } }
      set {
        _hasBits0 |= 4096;
        optionalBool_ = value;
      }
    }
    /// <summary>Gets whether the "optional_bool" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalBool {
      get { return (_hasBits0 & 4096) != 0; }
    }
    /// <summary>Clears the value of the "optional_bool" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalBool() {
      _hasBits0 &= ~4096;
    }

    /// <summary>Field number for the "optional_string" field.</summary>
    public const int OptionalStringFieldNumber = 14;
    private readonly static string OptionalStringDefaultValue = "";

    private string optionalString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OptionalString {
      get { return optionalString_ ?? OptionalStringDefaultValue; }
      set {
        optionalString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalString {
      get { return optionalString_ != null; }
    }
    /// <summary>Clears the value of the "optional_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalString() {
      optionalString_ = null;
    }

    /// <summary>Field number for the "optional_bytes" field.</summary>
    public const int OptionalBytesFieldNumber = 15;
    private readonly static pb::ByteString OptionalBytesDefaultValue = pb::ByteString.Empty;

    private pb::ByteString optionalBytes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString OptionalBytes {
      get { return optionalBytes_ ?? OptionalBytesDefaultValue; }
      set {
        optionalBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalBytes {
      get { return optionalBytes_ != null; }
    }
    /// <summary>Clears the value of the "optional_bytes" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalBytes() {
      optionalBytes_ = null;
    }

    /// <summary>Field number for the "optionalgroup" field.</summary>
    public const int OptionalGroupFieldNumber = 16;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup optionalGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup OptionalGroup {
      get { return optionalGroup_; }
      set {
        optionalGroup_ = value;
      }
    }
    /// <summary>Gets whether the optionalgroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalGroup {
      get { return optionalGroup_ != null; }
    }
    /// <summary>Clears the value of the optionalgroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalGroup() {
      optionalGroup_ = null;
    }

    /// <summary>Field number for the "optional_nested_message" field.</summary>
    public const int OptionalNestedMessageFieldNumber = 18;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage optionalNestedMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage OptionalNestedMessage {
      get { return optionalNestedMessage_; }
      set {
        optionalNestedMessage_ = value;
      }
    }

    /// <summary>Field number for the "optional_foreign_message" field.</summary>
    public const int OptionalForeignMessageFieldNumber = 19;
    private global::Google.Protobuf.TestProtos.Proto2.ForeignMessage optionalForeignMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignMessage OptionalForeignMessage {
      get { return optionalForeignMessage_; }
      set {
        optionalForeignMessage_ = value;
      }
    }

    /// <summary>Field number for the "optional_import_message" field.</summary>
    public const int OptionalImportMessageFieldNumber = 20;
    private global::Google.Protobuf.TestProtos.Proto2.ImportMessage optionalImportMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ImportMessage OptionalImportMessage {
      get { return optionalImportMessage_; }
      set {
        optionalImportMessage_ = value;
      }
    }

    /// <summary>Field number for the "optional_nested_enum" field.</summary>
    public const int OptionalNestedEnumFieldNumber = 21;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum OptionalNestedEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum.Foo;

    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum optionalNestedEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum OptionalNestedEnum {
      get { if ((_hasBits0 & 8192) != 0) { return optionalNestedEnum_; } else { return OptionalNestedEnumDefaultValue; } }
      set {
        _hasBits0 |= 8192;
        optionalNestedEnum_ = value;
      }
    }
    /// <summary>Gets whether the "optional_nested_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalNestedEnum {
      get { return (_hasBits0 & 8192) != 0; }
    }
    /// <summary>Clears the value of the "optional_nested_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalNestedEnum() {
      _hasBits0 &= ~8192;
    }

    /// <summary>Field number for the "optional_foreign_enum" field.</summary>
    public const int OptionalForeignEnumFieldNumber = 22;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalForeignEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum optionalForeignEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalForeignEnum {
      get { if ((_hasBits0 & 16384) != 0) { return optionalForeignEnum_; } else { return OptionalForeignEnumDefaultValue; } }
      set {
        _hasBits0 |= 16384;
        optionalForeignEnum_ = value;
      }
    }
    /// <summary>Gets whether the "optional_foreign_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalForeignEnum {
      get { return (_hasBits0 & 16384) != 0; }
    }
    /// <summary>Clears the value of the "optional_foreign_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalForeignEnum() {
      _hasBits0 &= ~16384;
    }

    /// <summary>Field number for the "optional_import_enum" field.</summary>
    public const int OptionalImportEnumFieldNumber = 23;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ImportEnum OptionalImportEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ImportEnum optionalImportEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ImportEnum OptionalImportEnum {
      get { if ((_hasBits0 & 32768) != 0) { return optionalImportEnum_; } else { return OptionalImportEnumDefaultValue; } }
      set {
        _hasBits0 |= 32768;
        optionalImportEnum_ = value;
      }
    }
    /// <summary>Gets whether the "optional_import_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalImportEnum {
      get { return (_hasBits0 & 32768) != 0; }
    }
    /// <summary>Clears the value of the "optional_import_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalImportEnum() {
      _hasBits0 &= ~32768;
    }

    /// <summary>Field number for the "optional_string_piece" field.</summary>
    public const int OptionalStringPieceFieldNumber = 24;
    private readonly static string OptionalStringPieceDefaultValue = "";

    private string optionalStringPiece_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OptionalStringPiece {
      get { return optionalStringPiece_ ?? OptionalStringPieceDefaultValue; }
      set {
        optionalStringPiece_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_string_piece" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalStringPiece {
      get { return optionalStringPiece_ != null; }
    }
    /// <summary>Clears the value of the "optional_string_piece" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalStringPiece() {
      optionalStringPiece_ = null;
    }

    /// <summary>Field number for the "optional_cord" field.</summary>
    public const int OptionalCordFieldNumber = 25;
    private readonly static string OptionalCordDefaultValue = "";

    private string optionalCord_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OptionalCord {
      get { return optionalCord_ ?? OptionalCordDefaultValue; }
      set {
        optionalCord_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_cord" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalCord {
      get { return optionalCord_ != null; }
    }
    /// <summary>Clears the value of the "optional_cord" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalCord() {
      optionalCord_ = null;
    }

    /// <summary>Field number for the "optional_public_import_message" field.</summary>
    public const int OptionalPublicImportMessageFieldNumber = 26;
    private global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage optionalPublicImportMessage_;
    /// <summary>
    /// Defined in unittest_import_public.proto
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage OptionalPublicImportMessage {
      get { return optionalPublicImportMessage_; }
      set {
        optionalPublicImportMessage_ = value;
      }
    }

    /// <summary>Field number for the "optional_lazy_message" field.</summary>
    public const int OptionalLazyMessageFieldNumber = 27;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage optionalLazyMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage OptionalLazyMessage {
      get { return optionalLazyMessage_; }
      set {
        optionalLazyMessage_ = value;
      }
    }

    /// <summary>Field number for the "repeated_int32" field.</summary>
    public const int RepeatedInt32FieldNumber = 31;
    private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
        = pb::FieldCodec.ForInt32(248);
    private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
    /// <summary>
    /// Repeated
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedInt32 {
      get { return repeatedInt32_; }
    }

    /// <summary>Field number for the "repeated_int64" field.</summary>
    public const int RepeatedInt64FieldNumber = 32;
    private static readonly pb::FieldCodec<long> _repeated_repeatedInt64_codec
        = pb::FieldCodec.ForInt64(256);
    private readonly pbc::RepeatedField<long> repeatedInt64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> RepeatedInt64 {
      get { return repeatedInt64_; }
    }

    /// <summary>Field number for the "repeated_uint32" field.</summary>
    public const int RepeatedUint32FieldNumber = 33;
    private static readonly pb::FieldCodec<uint> _repeated_repeatedUint32_codec
        = pb::FieldCodec.ForUInt32(264);
    private readonly pbc::RepeatedField<uint> repeatedUint32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> RepeatedUint32 {
      get { return repeatedUint32_; }
    }

    /// <summary>Field number for the "repeated_uint64" field.</summary>
    public const int RepeatedUint64FieldNumber = 34;
    private static readonly pb::FieldCodec<ulong> _repeated_repeatedUint64_codec
        = pb::FieldCodec.ForUInt64(272);
    private readonly pbc::RepeatedField<ulong> repeatedUint64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> RepeatedUint64 {
      get { return repeatedUint64_; }
    }

    /// <summary>Field number for the "repeated_sint32" field.</summary>
    public const int RepeatedSint32FieldNumber = 35;
    private static readonly pb::FieldCodec<int> _repeated_repeatedSint32_codec
        = pb::FieldCodec.ForSInt32(280);
    private readonly pbc::RepeatedField<int> repeatedSint32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedSint32 {
      get { return repeatedSint32_; }
    }

    /// <summary>Field number for the "repeated_sint64" field.</summary>
    public const int RepeatedSint64FieldNumber = 36;
    private static readonly pb::FieldCodec<long> _repeated_repeatedSint64_codec
        = pb::FieldCodec.ForSInt64(288);
    private readonly pbc::RepeatedField<long> repeatedSint64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> RepeatedSint64 {
      get { return repeatedSint64_; }
    }

    /// <summary>Field number for the "repeated_fixed32" field.</summary>
    public const int RepeatedFixed32FieldNumber = 37;
    private static readonly pb::FieldCodec<uint> _repeated_repeatedFixed32_codec
        = pb::FieldCodec.ForFixed32(301);
    private readonly pbc::RepeatedField<uint> repeatedFixed32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> RepeatedFixed32 {
      get { return repeatedFixed32_; }
    }

    /// <summary>Field number for the "repeated_fixed64" field.</summary>
    public const int RepeatedFixed64FieldNumber = 38;
    private static readonly pb::FieldCodec<ulong> _repeated_repeatedFixed64_codec
        = pb::FieldCodec.ForFixed64(305);
    private readonly pbc::RepeatedField<ulong> repeatedFixed64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> RepeatedFixed64 {
      get { return repeatedFixed64_; }
    }

    /// <summary>Field number for the "repeated_sfixed32" field.</summary>
    public const int RepeatedSfixed32FieldNumber = 39;
    private static readonly pb::FieldCodec<int> _repeated_repeatedSfixed32_codec
        = pb::FieldCodec.ForSFixed32(317);
    private readonly pbc::RepeatedField<int> repeatedSfixed32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedSfixed32 {
      get { return repeatedSfixed32_; }
    }

    /// <summary>Field number for the "repeated_sfixed64" field.</summary>
    public const int RepeatedSfixed64FieldNumber = 40;
    private static readonly pb::FieldCodec<long> _repeated_repeatedSfixed64_codec
        = pb::FieldCodec.ForSFixed64(321);
    private readonly pbc::RepeatedField<long> repeatedSfixed64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> RepeatedSfixed64 {
      get { return repeatedSfixed64_; }
    }

    /// <summary>Field number for the "repeated_float" field.</summary>
    public const int RepeatedFloatFieldNumber = 41;
    private static readonly pb::FieldCodec<float> _repeated_repeatedFloat_codec
        = pb::FieldCodec.ForFloat(333);
    private readonly pbc::RepeatedField<float> repeatedFloat_ = new pbc::RepeatedField<float>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<float> RepeatedFloat {
      get { return repeatedFloat_; }
    }

    /// <summary>Field number for the "repeated_double" field.</summary>
    public const int RepeatedDoubleFieldNumber = 42;
    private static readonly pb::FieldCodec<double> _repeated_repeatedDouble_codec
        = pb::FieldCodec.ForDouble(337);
    private readonly pbc::RepeatedField<double> repeatedDouble_ = new pbc::RepeatedField<double>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<double> RepeatedDouble {
      get { return repeatedDouble_; }
    }

    /// <summary>Field number for the "repeated_bool" field.</summary>
    public const int RepeatedBoolFieldNumber = 43;
    private static readonly pb::FieldCodec<bool> _repeated_repeatedBool_codec
        = pb::FieldCodec.ForBool(344);
    private readonly pbc::RepeatedField<bool> repeatedBool_ = new pbc::RepeatedField<bool>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<bool> RepeatedBool {
      get { return repeatedBool_; }
    }

    /// <summary>Field number for the "repeated_string" field.</summary>
    public const int RepeatedStringFieldNumber = 44;
    private static readonly pb::FieldCodec<string> _repeated_repeatedString_codec
        = pb::FieldCodec.ForString(354);
    private readonly pbc::RepeatedField<string> repeatedString_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedString {
      get { return repeatedString_; }
    }

    /// <summary>Field number for the "repeated_bytes" field.</summary>
    public const int RepeatedBytesFieldNumber = 45;
    private static readonly pb::FieldCodec<pb::ByteString> _repeated_repeatedBytes_codec
        = pb::FieldCodec.ForBytes(362);
    private readonly pbc::RepeatedField<pb::ByteString> repeatedBytes_ = new pbc::RepeatedField<pb::ByteString>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<pb::ByteString> RepeatedBytes {
      get { return repeatedBytes_; }
    }

    /// <summary>Field number for the "repeatedgroup" field.</summary>
    public const int RepeatedGroupFieldNumber = 46;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup> _repeated_repeatedGroup_codec
        = pb::FieldCodec.ForGroup(371, 372, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup> repeatedGroup_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.RepeatedGroup> RepeatedGroup {
      get { return repeatedGroup_; }
    }

    /// <summary>Field number for the "repeated_nested_message" field.</summary>
    public const int RepeatedNestedMessageFieldNumber = 48;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> _repeated_repeatedNestedMessage_codec
        = pb::FieldCodec.ForMessage(386, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> repeatedNestedMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> RepeatedNestedMessage {
      get { return repeatedNestedMessage_; }
    }

    /// <summary>Field number for the "repeated_foreign_message" field.</summary>
    public const int RepeatedForeignMessageFieldNumber = 49;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> _repeated_repeatedForeignMessage_codec
        = pb::FieldCodec.ForMessage(394, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> repeatedForeignMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> RepeatedForeignMessage {
      get { return repeatedForeignMessage_; }
    }

    /// <summary>Field number for the "repeated_import_message" field.</summary>
    public const int RepeatedImportMessageFieldNumber = 50;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ImportMessage> _repeated_repeatedImportMessage_codec
        = pb::FieldCodec.ForMessage(402, global::Google.Protobuf.TestProtos.Proto2.ImportMessage.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportMessage> repeatedImportMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportMessage> RepeatedImportMessage {
      get { return repeatedImportMessage_; }
    }

    /// <summary>Field number for the "repeated_nested_enum" field.</summary>
    public const int RepeatedNestedEnumFieldNumber = 51;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> _repeated_repeatedNestedEnum_codec
        = pb::FieldCodec.ForEnum(408, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> repeatedNestedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> RepeatedNestedEnum {
      get { return repeatedNestedEnum_; }
    }

    /// <summary>Field number for the "repeated_foreign_enum" field.</summary>
    public const int RepeatedForeignEnumFieldNumber = 52;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> _repeated_repeatedForeignEnum_codec
        = pb::FieldCodec.ForEnum(416, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> repeatedForeignEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> RepeatedForeignEnum {
      get { return repeatedForeignEnum_; }
    }

    /// <summary>Field number for the "repeated_import_enum" field.</summary>
    public const int RepeatedImportEnumFieldNumber = 53;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ImportEnum> _repeated_repeatedImportEnum_codec
        = pb::FieldCodec.ForEnum(424, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportEnum> repeatedImportEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ImportEnum> RepeatedImportEnum {
      get { return repeatedImportEnum_; }
    }

    /// <summary>Field number for the "repeated_string_piece" field.</summary>
    public const int RepeatedStringPieceFieldNumber = 54;
    private static readonly pb::FieldCodec<string> _repeated_repeatedStringPiece_codec
        = pb::FieldCodec.ForString(434);
    private readonly pbc::RepeatedField<string> repeatedStringPiece_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedStringPiece {
      get { return repeatedStringPiece_; }
    }

    /// <summary>Field number for the "repeated_cord" field.</summary>
    public const int RepeatedCordFieldNumber = 55;
    private static readonly pb::FieldCodec<string> _repeated_repeatedCord_codec
        = pb::FieldCodec.ForString(442);
    private readonly pbc::RepeatedField<string> repeatedCord_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedCord {
      get { return repeatedCord_; }
    }

    /// <summary>Field number for the "repeated_lazy_message" field.</summary>
    public const int RepeatedLazyMessageFieldNumber = 57;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> _repeated_repeatedLazyMessage_codec
        = pb::FieldCodec.ForMessage(458, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> repeatedLazyMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage> RepeatedLazyMessage {
      get { return repeatedLazyMessage_; }
    }

    /// <summary>Field number for the "default_int32" field.</summary>
    public const int DefaultInt32FieldNumber = 61;
    private readonly static int DefaultInt32DefaultValue = 41;

    private int defaultInt32_;
    /// <summary>
    /// Singular with defaults
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int DefaultInt32 {
      get { if ((_hasBits0 & 65536) != 0) { return defaultInt32_; } else { return DefaultInt32DefaultValue; } }
      set {
        _hasBits0 |= 65536;
        defaultInt32_ = value;
      }
    }
    /// <summary>Gets whether the "default_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultInt32 {
      get { return (_hasBits0 & 65536) != 0; }
    }
    /// <summary>Clears the value of the "default_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultInt32() {
      _hasBits0 &= ~65536;
    }

    /// <summary>Field number for the "default_int64" field.</summary>
    public const int DefaultInt64FieldNumber = 62;
    private readonly static long DefaultInt64DefaultValue = 42L;

    private long defaultInt64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long DefaultInt64 {
      get { if ((_hasBits0 & 131072) != 0) { return defaultInt64_; } else { return DefaultInt64DefaultValue; } }
      set {
        _hasBits0 |= 131072;
        defaultInt64_ = value;
      }
    }
    /// <summary>Gets whether the "default_int64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultInt64 {
      get { return (_hasBits0 & 131072) != 0; }
    }
    /// <summary>Clears the value of the "default_int64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultInt64() {
      _hasBits0 &= ~131072;
    }

    /// <summary>Field number for the "default_uint32" field.</summary>
    public const int DefaultUint32FieldNumber = 63;
    private readonly static uint DefaultUint32DefaultValue = 43;

    private uint defaultUint32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint DefaultUint32 {
      get { if ((_hasBits0 & 262144) != 0) { return defaultUint32_; } else { return DefaultUint32DefaultValue; } }
      set {
        _hasBits0 |= 262144;
        defaultUint32_ = value;
      }
    }
    /// <summary>Gets whether the "default_uint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultUint32 {
      get { return (_hasBits0 & 262144) != 0; }
    }
    /// <summary>Clears the value of the "default_uint32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultUint32() {
      _hasBits0 &= ~262144;
    }

    /// <summary>Field number for the "default_uint64" field.</summary>
    public const int DefaultUint64FieldNumber = 64;
    private readonly static ulong DefaultUint64DefaultValue = 44UL;

    private ulong defaultUint64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong DefaultUint64 {
      get { if ((_hasBits0 & 524288) != 0) { return defaultUint64_; } else { return DefaultUint64DefaultValue; } }
      set {
        _hasBits0 |= 524288;
        defaultUint64_ = value;
      }
    }
    /// <summary>Gets whether the "default_uint64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultUint64 {
      get { return (_hasBits0 & 524288) != 0; }
    }
    /// <summary>Clears the value of the "default_uint64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultUint64() {
      _hasBits0 &= ~524288;
    }

    /// <summary>Field number for the "default_sint32" field.</summary>
    public const int DefaultSint32FieldNumber = 65;
    private readonly static int DefaultSint32DefaultValue = -45;

    private int defaultSint32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int DefaultSint32 {
      get { if ((_hasBits0 & 1048576) != 0) { return defaultSint32_; } else { return DefaultSint32DefaultValue; } }
      set {
        _hasBits0 |= 1048576;
        defaultSint32_ = value;
      }
    }
    /// <summary>Gets whether the "default_sint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultSint32 {
      get { return (_hasBits0 & 1048576) != 0; }
    }
    /// <summary>Clears the value of the "default_sint32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultSint32() {
      _hasBits0 &= ~1048576;
    }

    /// <summary>Field number for the "default_sint64" field.</summary>
    public const int DefaultSint64FieldNumber = 66;
    private readonly static long DefaultSint64DefaultValue = 46L;

    private long defaultSint64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long DefaultSint64 {
      get { if ((_hasBits0 & 2097152) != 0) { return defaultSint64_; } else { return DefaultSint64DefaultValue; } }
      set {
        _hasBits0 |= 2097152;
        defaultSint64_ = value;
      }
    }
    /// <summary>Gets whether the "default_sint64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultSint64 {
      get { return (_hasBits0 & 2097152) != 0; }
    }
    /// <summary>Clears the value of the "default_sint64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultSint64() {
      _hasBits0 &= ~2097152;
    }

    /// <summary>Field number for the "default_fixed32" field.</summary>
    public const int DefaultFixed32FieldNumber = 67;
    private readonly static uint DefaultFixed32DefaultValue = 47;

    private uint defaultFixed32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint DefaultFixed32 {
      get { if ((_hasBits0 & 4194304) != 0) { return defaultFixed32_; } else { return DefaultFixed32DefaultValue; } }
      set {
        _hasBits0 |= 4194304;
        defaultFixed32_ = value;
      }
    }
    /// <summary>Gets whether the "default_fixed32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultFixed32 {
      get { return (_hasBits0 & 4194304) != 0; }
    }
    /// <summary>Clears the value of the "default_fixed32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultFixed32() {
      _hasBits0 &= ~4194304;
    }

    /// <summary>Field number for the "default_fixed64" field.</summary>
    public const int DefaultFixed64FieldNumber = 68;
    private readonly static ulong DefaultFixed64DefaultValue = 48UL;

    private ulong defaultFixed64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong DefaultFixed64 {
      get { if ((_hasBits0 & 8388608) != 0) { return defaultFixed64_; } else { return DefaultFixed64DefaultValue; } }
      set {
        _hasBits0 |= 8388608;
        defaultFixed64_ = value;
      }
    }
    /// <summary>Gets whether the "default_fixed64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultFixed64 {
      get { return (_hasBits0 & 8388608) != 0; }
    }
    /// <summary>Clears the value of the "default_fixed64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultFixed64() {
      _hasBits0 &= ~8388608;
    }

    /// <summary>Field number for the "default_sfixed32" field.</summary>
    public const int DefaultSfixed32FieldNumber = 69;
    private readonly static int DefaultSfixed32DefaultValue = 49;

    private int defaultSfixed32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int DefaultSfixed32 {
      get { if ((_hasBits0 & 16777216) != 0) { return defaultSfixed32_; } else { return DefaultSfixed32DefaultValue; } }
      set {
        _hasBits0 |= 16777216;
        defaultSfixed32_ = value;
      }
    }
    /// <summary>Gets whether the "default_sfixed32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultSfixed32 {
      get { return (_hasBits0 & 16777216) != 0; }
    }
    /// <summary>Clears the value of the "default_sfixed32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultSfixed32() {
      _hasBits0 &= ~16777216;
    }

    /// <summary>Field number for the "default_sfixed64" field.</summary>
    public const int DefaultSfixed64FieldNumber = 70;
    private readonly static long DefaultSfixed64DefaultValue = -50L;

    private long defaultSfixed64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long DefaultSfixed64 {
      get { if ((_hasBits0 & 33554432) != 0) { return defaultSfixed64_; } else { return DefaultSfixed64DefaultValue; } }
      set {
        _hasBits0 |= 33554432;
        defaultSfixed64_ = value;
      }
    }
    /// <summary>Gets whether the "default_sfixed64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultSfixed64 {
      get { return (_hasBits0 & 33554432) != 0; }
    }
    /// <summary>Clears the value of the "default_sfixed64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultSfixed64() {
      _hasBits0 &= ~33554432;
    }

    /// <summary>Field number for the "default_float" field.</summary>
    public const int DefaultFloatFieldNumber = 71;
    private readonly static float DefaultFloatDefaultValue = 51.5F;

    private float defaultFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float DefaultFloat {
      get { if ((_hasBits0 & 67108864) != 0) { return defaultFloat_; } else { return DefaultFloatDefaultValue; } }
      set {
        _hasBits0 |= 67108864;
        defaultFloat_ = value;
      }
    }
    /// <summary>Gets whether the "default_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultFloat {
      get { return (_hasBits0 & 67108864) != 0; }
    }
    /// <summary>Clears the value of the "default_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultFloat() {
      _hasBits0 &= ~67108864;
    }

    /// <summary>Field number for the "default_double" field.</summary>
    public const int DefaultDoubleFieldNumber = 72;
    private readonly static double DefaultDoubleDefaultValue = 52000D;

    private double defaultDouble_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public double DefaultDouble {
      get { if ((_hasBits0 & 134217728) != 0) { return defaultDouble_; } else { return DefaultDoubleDefaultValue; } }
      set {
        _hasBits0 |= 134217728;
        defaultDouble_ = value;
      }
    }
    /// <summary>Gets whether the "default_double" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultDouble {
      get { return (_hasBits0 & 134217728) != 0; }
    }
    /// <summary>Clears the value of the "default_double" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultDouble() {
      _hasBits0 &= ~134217728;
    }

    /// <summary>Field number for the "default_bool" field.</summary>
    public const int DefaultBoolFieldNumber = 73;
    private readonly static bool DefaultBoolDefaultValue = true;

    private bool defaultBool_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool DefaultBool {
      get { if ((_hasBits0 & 268435456) != 0) { return defaultBool_; } else { return DefaultBoolDefaultValue; } }
      set {
        _hasBits0 |= 268435456;
        defaultBool_ = value;
      }
    }
    /// <summary>Gets whether the "default_bool" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultBool {
      get { return (_hasBits0 & 268435456) != 0; }
    }
    /// <summary>Clears the value of the "default_bool" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultBool() {
      _hasBits0 &= ~268435456;
    }

    /// <summary>Field number for the "default_string" field.</summary>
    public const int DefaultStringFieldNumber = 74;
    private readonly static string DefaultStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsbG8="), 0, 5);

    private string defaultString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string DefaultString {
      get { return defaultString_ ?? DefaultStringDefaultValue; }
      set {
        defaultString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "default_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultString {
      get { return defaultString_ != null; }
    }
    /// <summary>Clears the value of the "default_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultString() {
      defaultString_ = null;
    }

    /// <summary>Field number for the "default_bytes" field.</summary>
    public const int DefaultBytesFieldNumber = 75;
    private readonly static pb::ByteString DefaultBytesDefaultValue = pb::ByteString.FromBase64("d29ybGQ=");

    private pb::ByteString defaultBytes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString DefaultBytes {
      get { return defaultBytes_ ?? DefaultBytesDefaultValue; }
      set {
        defaultBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "default_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultBytes {
      get { return defaultBytes_ != null; }
    }
    /// <summary>Clears the value of the "default_bytes" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultBytes() {
      defaultBytes_ = null;
    }

    /// <summary>Field number for the "default_nested_enum" field.</summary>
    public const int DefaultNestedEnumFieldNumber = 81;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum DefaultNestedEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum.Bar;

    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum defaultNestedEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum DefaultNestedEnum {
      get { if ((_hasBits0 & 536870912) != 0) { return defaultNestedEnum_; } else { return DefaultNestedEnumDefaultValue; } }
      set {
        _hasBits0 |= 536870912;
        defaultNestedEnum_ = value;
      }
    }
    /// <summary>Gets whether the "default_nested_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultNestedEnum {
      get { return (_hasBits0 & 536870912) != 0; }
    }
    /// <summary>Clears the value of the "default_nested_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultNestedEnum() {
      _hasBits0 &= ~536870912;
    }

    /// <summary>Field number for the "default_foreign_enum" field.</summary>
    public const int DefaultForeignEnumFieldNumber = 82;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum DefaultForeignEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignBar;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum defaultForeignEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum DefaultForeignEnum {
      get { if ((_hasBits0 & 1073741824) != 0) { return defaultForeignEnum_; } else { return DefaultForeignEnumDefaultValue; } }
      set {
        _hasBits0 |= 1073741824;
        defaultForeignEnum_ = value;
      }
    }
    /// <summary>Gets whether the "default_foreign_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultForeignEnum {
      get { return (_hasBits0 & 1073741824) != 0; }
    }
    /// <summary>Clears the value of the "default_foreign_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultForeignEnum() {
      _hasBits0 &= ~1073741824;
    }

    /// <summary>Field number for the "default_import_enum" field.</summary>
    public const int DefaultImportEnumFieldNumber = 83;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ImportEnum DefaultImportEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportBar;

    private global::Google.Protobuf.TestProtos.Proto2.ImportEnum defaultImportEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ImportEnum DefaultImportEnum {
      get { if ((_hasBits0 & -2147483648) != 0) { return defaultImportEnum_; } else { return DefaultImportEnumDefaultValue; } }
      set {
        _hasBits0 |= -2147483648;
        defaultImportEnum_ = value;
      }
    }
    /// <summary>Gets whether the "default_import_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultImportEnum {
      get { return (_hasBits0 & -2147483648) != 0; }
    }
    /// <summary>Clears the value of the "default_import_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultImportEnum() {
      _hasBits0 &= ~-2147483648;
    }

    /// <summary>Field number for the "default_string_piece" field.</summary>
    public const int DefaultStringPieceFieldNumber = 84;
    private readonly static string DefaultStringPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWJj"), 0, 3);

    private string defaultStringPiece_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string DefaultStringPiece {
      get { return defaultStringPiece_ ?? DefaultStringPieceDefaultValue; }
      set {
        defaultStringPiece_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "default_string_piece" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultStringPiece {
      get { return defaultStringPiece_ != null; }
    }
    /// <summary>Clears the value of the "default_string_piece" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultStringPiece() {
      defaultStringPiece_ = null;
    }

    /// <summary>Field number for the "default_cord" field.</summary>
    public const int DefaultCordFieldNumber = 85;
    private readonly static string DefaultCordDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIz"), 0, 3);

    private string defaultCord_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string DefaultCord {
      get { return defaultCord_ ?? DefaultCordDefaultValue; }
      set {
        defaultCord_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "default_cord" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDefaultCord {
      get { return defaultCord_ != null; }
    }
    /// <summary>Clears the value of the "default_cord" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDefaultCord() {
      defaultCord_ = null;
    }

    /// <summary>Field number for the "oneof_uint32" field.</summary>
    public const int OneofUint32FieldNumber = 111;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint OneofUint32 {
      get { return HasOneofUint32 ? (uint) oneofField_ : 0; }
      set {
        oneofField_ = value;
        oneofFieldCase_ = OneofFieldOneofCase.OneofUint32;
      }
    }
    /// <summary>Gets whether the "oneof_uint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofUint32 {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_uint32" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofUint32() {
      if (HasOneofUint32) {
        ClearOneofField();
      }
    }

    /// <summary>Field number for the "oneof_nested_message" field.</summary>
    public const int OneofNestedMessageFieldNumber = 112;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage OneofNestedMessage {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage) oneofField_ : null; }
      set {
        oneofField_ = value;
        oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage;
      }
    }

    /// <summary>Field number for the "oneof_string" field.</summary>
    public const int OneofStringFieldNumber = 113;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OneofString {
      get { return HasOneofString ? (string) oneofField_ : ""; }
      set {
        oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        oneofFieldCase_ = OneofFieldOneofCase.OneofString;
      }
    }
    /// <summary>Gets whether the "oneof_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofString {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofString() {
      if (HasOneofString) {
        ClearOneofField();
      }
    }

    /// <summary>Field number for the "oneof_bytes" field.</summary>
    public const int OneofBytesFieldNumber = 114;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString OneofBytes {
      get { return HasOneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; }
      set {
        oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        oneofFieldCase_ = OneofFieldOneofCase.OneofBytes;
      }
    }
    /// <summary>Gets whether the "oneof_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofBytes {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_bytes" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofBytes() {
      if (HasOneofBytes) {
        ClearOneofField();
      }
    }

    private object oneofField_;
    /// <summary>Enum of possible cases for the "oneof_field" oneof.</summary>
    public enum OneofFieldOneofCase {
      None = 0,
      OneofUint32 = 111,
      OneofNestedMessage = 112,
      OneofString = 113,
      OneofBytes = 114,
    }
    private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneofFieldOneofCase OneofFieldCase {
      get { return oneofFieldCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofField() {
      oneofFieldCase_ = OneofFieldOneofCase.None;
      oneofField_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestAllTypes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestAllTypes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (OptionalInt32 != other.OptionalInt32) return false;
      if (OptionalInt64 != other.OptionalInt64) return false;
      if (OptionalUint32 != other.OptionalUint32) return false;
      if (OptionalUint64 != other.OptionalUint64) return false;
      if (OptionalSint32 != other.OptionalSint32) return false;
      if (OptionalSint64 != other.OptionalSint64) return false;
      if (OptionalFixed32 != other.OptionalFixed32) return false;
      if (OptionalFixed64 != other.OptionalFixed64) return false;
      if (OptionalSfixed32 != other.OptionalSfixed32) return false;
      if (OptionalSfixed64 != other.OptionalSfixed64) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(OptionalFloat, other.OptionalFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(OptionalDouble, other.OptionalDouble)) return false;
      if (OptionalBool != other.OptionalBool) return false;
      if (OptionalString != other.OptionalString) return false;
      if (OptionalBytes != other.OptionalBytes) return false;
      if (!object.Equals(OptionalGroup, other.OptionalGroup)) return false;
      if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false;
      if (!object.Equals(OptionalForeignMessage, other.OptionalForeignMessage)) return false;
      if (!object.Equals(OptionalImportMessage, other.OptionalImportMessage)) return false;
      if (OptionalNestedEnum != other.OptionalNestedEnum) return false;
      if (OptionalForeignEnum != other.OptionalForeignEnum) return false;
      if (OptionalImportEnum != other.OptionalImportEnum) return false;
      if (OptionalStringPiece != other.OptionalStringPiece) return false;
      if (OptionalCord != other.OptionalCord) return false;
      if (!object.Equals(OptionalPublicImportMessage, other.OptionalPublicImportMessage)) return false;
      if (!object.Equals(OptionalLazyMessage, other.OptionalLazyMessage)) return false;
      if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
      if(!repeatedInt64_.Equals(other.repeatedInt64_)) return false;
      if(!repeatedUint32_.Equals(other.repeatedUint32_)) return false;
      if(!repeatedUint64_.Equals(other.repeatedUint64_)) return false;
      if(!repeatedSint32_.Equals(other.repeatedSint32_)) return false;
      if(!repeatedSint64_.Equals(other.repeatedSint64_)) return false;
      if(!repeatedFixed32_.Equals(other.repeatedFixed32_)) return false;
      if(!repeatedFixed64_.Equals(other.repeatedFixed64_)) return false;
      if(!repeatedSfixed32_.Equals(other.repeatedSfixed32_)) return false;
      if(!repeatedSfixed64_.Equals(other.repeatedSfixed64_)) return false;
      if(!repeatedFloat_.Equals(other.repeatedFloat_)) return false;
      if(!repeatedDouble_.Equals(other.repeatedDouble_)) return false;
      if(!repeatedBool_.Equals(other.repeatedBool_)) return false;
      if(!repeatedString_.Equals(other.repeatedString_)) return false;
      if(!repeatedBytes_.Equals(other.repeatedBytes_)) return false;
      if(!repeatedGroup_.Equals(other.repeatedGroup_)) return false;
      if(!repeatedNestedMessage_.Equals(other.repeatedNestedMessage_)) return false;
      if(!repeatedForeignMessage_.Equals(other.repeatedForeignMessage_)) return false;
      if(!repeatedImportMessage_.Equals(other.repeatedImportMessage_)) return false;
      if(!repeatedNestedEnum_.Equals(other.repeatedNestedEnum_)) return false;
      if(!repeatedForeignEnum_.Equals(other.repeatedForeignEnum_)) return false;
      if(!repeatedImportEnum_.Equals(other.repeatedImportEnum_)) return false;
      if(!repeatedStringPiece_.Equals(other.repeatedStringPiece_)) return false;
      if(!repeatedCord_.Equals(other.repeatedCord_)) return false;
      if(!repeatedLazyMessage_.Equals(other.repeatedLazyMessage_)) return false;
      if (DefaultInt32 != other.DefaultInt32) return false;
      if (DefaultInt64 != other.DefaultInt64) return false;
      if (DefaultUint32 != other.DefaultUint32) return false;
      if (DefaultUint64 != other.DefaultUint64) return false;
      if (DefaultSint32 != other.DefaultSint32) return false;
      if (DefaultSint64 != other.DefaultSint64) return false;
      if (DefaultFixed32 != other.DefaultFixed32) return false;
      if (DefaultFixed64 != other.DefaultFixed64) return false;
      if (DefaultSfixed32 != other.DefaultSfixed32) return false;
      if (DefaultSfixed64 != other.DefaultSfixed64) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(DefaultFloat, other.DefaultFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DefaultDouble, other.DefaultDouble)) return false;
      if (DefaultBool != other.DefaultBool) return false;
      if (DefaultString != other.DefaultString) return false;
      if (DefaultBytes != other.DefaultBytes) return false;
      if (DefaultNestedEnum != other.DefaultNestedEnum) return false;
      if (DefaultForeignEnum != other.DefaultForeignEnum) return false;
      if (DefaultImportEnum != other.DefaultImportEnum) return false;
      if (DefaultStringPiece != other.DefaultStringPiece) return false;
      if (DefaultCord != other.DefaultCord) return false;
      if (OneofUint32 != other.OneofUint32) return false;
      if (!object.Equals(OneofNestedMessage, other.OneofNestedMessage)) return false;
      if (OneofString != other.OneofString) return false;
      if (OneofBytes != other.OneofBytes) return false;
      if (OneofFieldCase != other.OneofFieldCase) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode();
      if (HasOptionalInt64) hash ^= OptionalInt64.GetHashCode();
      if (HasOptionalUint32) hash ^= OptionalUint32.GetHashCode();
      if (HasOptionalUint64) hash ^= OptionalUint64.GetHashCode();
      if (HasOptionalSint32) hash ^= OptionalSint32.GetHashCode();
      if (HasOptionalSint64) hash ^= OptionalSint64.GetHashCode();
      if (HasOptionalFixed32) hash ^= OptionalFixed32.GetHashCode();
      if (HasOptionalFixed64) hash ^= OptionalFixed64.GetHashCode();
      if (HasOptionalSfixed32) hash ^= OptionalSfixed32.GetHashCode();
      if (HasOptionalSfixed64) hash ^= OptionalSfixed64.GetHashCode();
      if (HasOptionalFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(OptionalFloat);
      if (HasOptionalDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(OptionalDouble);
      if (HasOptionalBool) hash ^= OptionalBool.GetHashCode();
      if (HasOptionalString) hash ^= OptionalString.GetHashCode();
      if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode();
      if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode();
      if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
      if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode();
      if (optionalImportMessage_ != null) hash ^= OptionalImportMessage.GetHashCode();
      if (HasOptionalNestedEnum) hash ^= OptionalNestedEnum.GetHashCode();
      if (HasOptionalForeignEnum) hash ^= OptionalForeignEnum.GetHashCode();
      if (HasOptionalImportEnum) hash ^= OptionalImportEnum.GetHashCode();
      if (HasOptionalStringPiece) hash ^= OptionalStringPiece.GetHashCode();
      if (HasOptionalCord) hash ^= OptionalCord.GetHashCode();
      if (optionalPublicImportMessage_ != null) hash ^= OptionalPublicImportMessage.GetHashCode();
      if (optionalLazyMessage_ != null) hash ^= OptionalLazyMessage.GetHashCode();
      hash ^= repeatedInt32_.GetHashCode();
      hash ^= repeatedInt64_.GetHashCode();
      hash ^= repeatedUint32_.GetHashCode();
      hash ^= repeatedUint64_.GetHashCode();
      hash ^= repeatedSint32_.GetHashCode();
      hash ^= repeatedSint64_.GetHashCode();
      hash ^= repeatedFixed32_.GetHashCode();
      hash ^= repeatedFixed64_.GetHashCode();
      hash ^= repeatedSfixed32_.GetHashCode();
      hash ^= repeatedSfixed64_.GetHashCode();
      hash ^= repeatedFloat_.GetHashCode();
      hash ^= repeatedDouble_.GetHashCode();
      hash ^= repeatedBool_.GetHashCode();
      hash ^= repeatedString_.GetHashCode();
      hash ^= repeatedBytes_.GetHashCode();
      hash ^= repeatedGroup_.GetHashCode();
      hash ^= repeatedNestedMessage_.GetHashCode();
      hash ^= repeatedForeignMessage_.GetHashCode();
      hash ^= repeatedImportMessage_.GetHashCode();
      hash ^= repeatedNestedEnum_.GetHashCode();
      hash ^= repeatedForeignEnum_.GetHashCode();
      hash ^= repeatedImportEnum_.GetHashCode();
      hash ^= repeatedStringPiece_.GetHashCode();
      hash ^= repeatedCord_.GetHashCode();
      hash ^= repeatedLazyMessage_.GetHashCode();
      if (HasDefaultInt32) hash ^= DefaultInt32.GetHashCode();
      if (HasDefaultInt64) hash ^= DefaultInt64.GetHashCode();
      if (HasDefaultUint32) hash ^= DefaultUint32.GetHashCode();
      if (HasDefaultUint64) hash ^= DefaultUint64.GetHashCode();
      if (HasDefaultSint32) hash ^= DefaultSint32.GetHashCode();
      if (HasDefaultSint64) hash ^= DefaultSint64.GetHashCode();
      if (HasDefaultFixed32) hash ^= DefaultFixed32.GetHashCode();
      if (HasDefaultFixed64) hash ^= DefaultFixed64.GetHashCode();
      if (HasDefaultSfixed32) hash ^= DefaultSfixed32.GetHashCode();
      if (HasDefaultSfixed64) hash ^= DefaultSfixed64.GetHashCode();
      if (HasDefaultFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(DefaultFloat);
      if (HasDefaultDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DefaultDouble);
      if (HasDefaultBool) hash ^= DefaultBool.GetHashCode();
      if (HasDefaultString) hash ^= DefaultString.GetHashCode();
      if (HasDefaultBytes) hash ^= DefaultBytes.GetHashCode();
      if (HasDefaultNestedEnum) hash ^= DefaultNestedEnum.GetHashCode();
      if (HasDefaultForeignEnum) hash ^= DefaultForeignEnum.GetHashCode();
      if (HasDefaultImportEnum) hash ^= DefaultImportEnum.GetHashCode();
      if (HasDefaultStringPiece) hash ^= DefaultStringPiece.GetHashCode();
      if (HasDefaultCord) hash ^= DefaultCord.GetHashCode();
      if (HasOneofUint32) hash ^= OneofUint32.GetHashCode();
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode();
      if (HasOneofString) hash ^= OneofString.GetHashCode();
      if (HasOneofBytes) hash ^= OneofBytes.GetHashCode();
      hash ^= (int) oneofFieldCase_;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasOptionalInt32) {
        output.WriteRawTag(8);
        output.WriteInt32(OptionalInt32);
      }
      if (HasOptionalInt64) {
        output.WriteRawTag(16);
        output.WriteInt64(OptionalInt64);
      }
      if (HasOptionalUint32) {
        output.WriteRawTag(24);
        output.WriteUInt32(OptionalUint32);
      }
      if (HasOptionalUint64) {
        output.WriteRawTag(32);
        output.WriteUInt64(OptionalUint64);
      }
      if (HasOptionalSint32) {
        output.WriteRawTag(40);
        output.WriteSInt32(OptionalSint32);
      }
      if (HasOptionalSint64) {
        output.WriteRawTag(48);
        output.WriteSInt64(OptionalSint64);
      }
      if (HasOptionalFixed32) {
        output.WriteRawTag(61);
        output.WriteFixed32(OptionalFixed32);
      }
      if (HasOptionalFixed64) {
        output.WriteRawTag(65);
        output.WriteFixed64(OptionalFixed64);
      }
      if (HasOptionalSfixed32) {
        output.WriteRawTag(77);
        output.WriteSFixed32(OptionalSfixed32);
      }
      if (HasOptionalSfixed64) {
        output.WriteRawTag(81);
        output.WriteSFixed64(OptionalSfixed64);
      }
      if (HasOptionalFloat) {
        output.WriteRawTag(93);
        output.WriteFloat(OptionalFloat);
      }
      if (HasOptionalDouble) {
        output.WriteRawTag(97);
        output.WriteDouble(OptionalDouble);
      }
      if (HasOptionalBool) {
        output.WriteRawTag(104);
        output.WriteBool(OptionalBool);
      }
      if (HasOptionalString) {
        output.WriteRawTag(114);
        output.WriteString(OptionalString);
      }
      if (HasOptionalBytes) {
        output.WriteRawTag(122);
        output.WriteBytes(OptionalBytes);
      }
      if (HasOptionalGroup) {
        output.WriteRawTag(131, 1);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(132, 1);
      }
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(146, 1);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (optionalForeignMessage_ != null) {
        output.WriteRawTag(154, 1);
        output.WriteMessage(OptionalForeignMessage);
      }
      if (optionalImportMessage_ != null) {
        output.WriteRawTag(162, 1);
        output.WriteMessage(OptionalImportMessage);
      }
      if (HasOptionalNestedEnum) {
        output.WriteRawTag(168, 1);
        output.WriteEnum((int) OptionalNestedEnum);
      }
      if (HasOptionalForeignEnum) {
        output.WriteRawTag(176, 1);
        output.WriteEnum((int) OptionalForeignEnum);
      }
      if (HasOptionalImportEnum) {
        output.WriteRawTag(184, 1);
        output.WriteEnum((int) OptionalImportEnum);
      }
      if (HasOptionalStringPiece) {
        output.WriteRawTag(194, 1);
        output.WriteString(OptionalStringPiece);
      }
      if (HasOptionalCord) {
        output.WriteRawTag(202, 1);
        output.WriteString(OptionalCord);
      }
      if (optionalPublicImportMessage_ != null) {
        output.WriteRawTag(210, 1);
        output.WriteMessage(OptionalPublicImportMessage);
      }
      if (optionalLazyMessage_ != null) {
        output.WriteRawTag(218, 1);
        output.WriteMessage(OptionalLazyMessage);
      }
      repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
      repeatedInt64_.WriteTo(output, _repeated_repeatedInt64_codec);
      repeatedUint32_.WriteTo(output, _repeated_repeatedUint32_codec);
      repeatedUint64_.WriteTo(output, _repeated_repeatedUint64_codec);
      repeatedSint32_.WriteTo(output, _repeated_repeatedSint32_codec);
      repeatedSint64_.WriteTo(output, _repeated_repeatedSint64_codec);
      repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
      repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
      repeatedSfixed32_.WriteTo(output, _repeated_repeatedSfixed32_codec);
      repeatedSfixed64_.WriteTo(output, _repeated_repeatedSfixed64_codec);
      repeatedFloat_.WriteTo(output, _repeated_repeatedFloat_codec);
      repeatedDouble_.WriteTo(output, _repeated_repeatedDouble_codec);
      repeatedBool_.WriteTo(output, _repeated_repeatedBool_codec);
      repeatedString_.WriteTo(output, _repeated_repeatedString_codec);
      repeatedBytes_.WriteTo(output, _repeated_repeatedBytes_codec);
      repeatedGroup_.WriteTo(output, _repeated_repeatedGroup_codec);
      repeatedNestedMessage_.WriteTo(output, _repeated_repeatedNestedMessage_codec);
      repeatedForeignMessage_.WriteTo(output, _repeated_repeatedForeignMessage_codec);
      repeatedImportMessage_.WriteTo(output, _repeated_repeatedImportMessage_codec);
      repeatedNestedEnum_.WriteTo(output, _repeated_repeatedNestedEnum_codec);
      repeatedForeignEnum_.WriteTo(output, _repeated_repeatedForeignEnum_codec);
      repeatedImportEnum_.WriteTo(output, _repeated_repeatedImportEnum_codec);
      repeatedStringPiece_.WriteTo(output, _repeated_repeatedStringPiece_codec);
      repeatedCord_.WriteTo(output, _repeated_repeatedCord_codec);
      repeatedLazyMessage_.WriteTo(output, _repeated_repeatedLazyMessage_codec);
      if (HasDefaultInt32) {
        output.WriteRawTag(232, 3);
        output.WriteInt32(DefaultInt32);
      }
      if (HasDefaultInt64) {
        output.WriteRawTag(240, 3);
        output.WriteInt64(DefaultInt64);
      }
      if (HasDefaultUint32) {
        output.WriteRawTag(248, 3);
        output.WriteUInt32(DefaultUint32);
      }
      if (HasDefaultUint64) {
        output.WriteRawTag(128, 4);
        output.WriteUInt64(DefaultUint64);
      }
      if (HasDefaultSint32) {
        output.WriteRawTag(136, 4);
        output.WriteSInt32(DefaultSint32);
      }
      if (HasDefaultSint64) {
        output.WriteRawTag(144, 4);
        output.WriteSInt64(DefaultSint64);
      }
      if (HasDefaultFixed32) {
        output.WriteRawTag(157, 4);
        output.WriteFixed32(DefaultFixed32);
      }
      if (HasDefaultFixed64) {
        output.WriteRawTag(161, 4);
        output.WriteFixed64(DefaultFixed64);
      }
      if (HasDefaultSfixed32) {
        output.WriteRawTag(173, 4);
        output.WriteSFixed32(DefaultSfixed32);
      }
      if (HasDefaultSfixed64) {
        output.WriteRawTag(177, 4);
        output.WriteSFixed64(DefaultSfixed64);
      }
      if (HasDefaultFloat) {
        output.WriteRawTag(189, 4);
        output.WriteFloat(DefaultFloat);
      }
      if (HasDefaultDouble) {
        output.WriteRawTag(193, 4);
        output.WriteDouble(DefaultDouble);
      }
      if (HasDefaultBool) {
        output.WriteRawTag(200, 4);
        output.WriteBool(DefaultBool);
      }
      if (HasDefaultString) {
        output.WriteRawTag(210, 4);
        output.WriteString(DefaultString);
      }
      if (HasDefaultBytes) {
        output.WriteRawTag(218, 4);
        output.WriteBytes(DefaultBytes);
      }
      if (HasDefaultNestedEnum) {
        output.WriteRawTag(136, 5);
        output.WriteEnum((int) DefaultNestedEnum);
      }
      if (HasDefaultForeignEnum) {
        output.WriteRawTag(144, 5);
        output.WriteEnum((int) DefaultForeignEnum);
      }
      if (HasDefaultImportEnum) {
        output.WriteRawTag(152, 5);
        output.WriteEnum((int) DefaultImportEnum);
      }
      if (HasDefaultStringPiece) {
        output.WriteRawTag(162, 5);
        output.WriteString(DefaultStringPiece);
      }
      if (HasDefaultCord) {
        output.WriteRawTag(170, 5);
        output.WriteString(DefaultCord);
      }
      if (HasOneofUint32) {
        output.WriteRawTag(248, 6);
        output.WriteUInt32(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
        output.WriteRawTag(130, 7);
        output.WriteMessage(OneofNestedMessage);
      }
      if (HasOneofString) {
        output.WriteRawTag(138, 7);
        output.WriteString(OneofString);
      }
      if (HasOneofBytes) {
        output.WriteRawTag(146, 7);
        output.WriteBytes(OneofBytes);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasOptionalInt32) {
        output.WriteRawTag(8);
        output.WriteInt32(OptionalInt32);
      }
      if (HasOptionalInt64) {
        output.WriteRawTag(16);
        output.WriteInt64(OptionalInt64);
      }
      if (HasOptionalUint32) {
        output.WriteRawTag(24);
        output.WriteUInt32(OptionalUint32);
      }
      if (HasOptionalUint64) {
        output.WriteRawTag(32);
        output.WriteUInt64(OptionalUint64);
      }
      if (HasOptionalSint32) {
        output.WriteRawTag(40);
        output.WriteSInt32(OptionalSint32);
      }
      if (HasOptionalSint64) {
        output.WriteRawTag(48);
        output.WriteSInt64(OptionalSint64);
      }
      if (HasOptionalFixed32) {
        output.WriteRawTag(61);
        output.WriteFixed32(OptionalFixed32);
      }
      if (HasOptionalFixed64) {
        output.WriteRawTag(65);
        output.WriteFixed64(OptionalFixed64);
      }
      if (HasOptionalSfixed32) {
        output.WriteRawTag(77);
        output.WriteSFixed32(OptionalSfixed32);
      }
      if (HasOptionalSfixed64) {
        output.WriteRawTag(81);
        output.WriteSFixed64(OptionalSfixed64);
      }
      if (HasOptionalFloat) {
        output.WriteRawTag(93);
        output.WriteFloat(OptionalFloat);
      }
      if (HasOptionalDouble) {
        output.WriteRawTag(97);
        output.WriteDouble(OptionalDouble);
      }
      if (HasOptionalBool) {
        output.WriteRawTag(104);
        output.WriteBool(OptionalBool);
      }
      if (HasOptionalString) {
        output.WriteRawTag(114);
        output.WriteString(OptionalString);
      }
      if (HasOptionalBytes) {
        output.WriteRawTag(122);
        output.WriteBytes(OptionalBytes);
      }
      if (HasOptionalGroup) {
        output.WriteRawTag(131, 1);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(132, 1);
      }
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(146, 1);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (optionalForeignMessage_ != null) {
        output.WriteRawTag(154, 1);
        output.WriteMessage(OptionalForeignMessage);
      }
      if (optionalImportMessage_ != null) {
        output.WriteRawTag(162, 1);
        output.WriteMessage(OptionalImportMessage);
      }
      if (HasOptionalNestedEnum) {
        output.WriteRawTag(168, 1);
        output.WriteEnum((int) OptionalNestedEnum);
      }
      if (HasOptionalForeignEnum) {
        output.WriteRawTag(176, 1);
        output.WriteEnum((int) OptionalForeignEnum);
      }
      if (HasOptionalImportEnum) {
        output.WriteRawTag(184, 1);
        output.WriteEnum((int) OptionalImportEnum);
      }
      if (HasOptionalStringPiece) {
        output.WriteRawTag(194, 1);
        output.WriteString(OptionalStringPiece);
      }
      if (HasOptionalCord) {
        output.WriteRawTag(202, 1);
        output.WriteString(OptionalCord);
      }
      if (optionalPublicImportMessage_ != null) {
        output.WriteRawTag(210, 1);
        output.WriteMessage(OptionalPublicImportMessage);
      }
      if (optionalLazyMessage_ != null) {
        output.WriteRawTag(218, 1);
        output.WriteMessage(OptionalLazyMessage);
      }
      repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec);
      repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec);
      repeatedUint32_.WriteTo(ref output, _repeated_repeatedUint32_codec);
      repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec);
      repeatedSint32_.WriteTo(ref output, _repeated_repeatedSint32_codec);
      repeatedSint64_.WriteTo(ref output, _repeated_repeatedSint64_codec);
      repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec);
      repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec);
      repeatedSfixed32_.WriteTo(ref output, _repeated_repeatedSfixed32_codec);
      repeatedSfixed64_.WriteTo(ref output, _repeated_repeatedSfixed64_codec);
      repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec);
      repeatedDouble_.WriteTo(ref output, _repeated_repeatedDouble_codec);
      repeatedBool_.WriteTo(ref output, _repeated_repeatedBool_codec);
      repeatedString_.WriteTo(ref output, _repeated_repeatedString_codec);
      repeatedBytes_.WriteTo(ref output, _repeated_repeatedBytes_codec);
      repeatedGroup_.WriteTo(ref output, _repeated_repeatedGroup_codec);
      repeatedNestedMessage_.WriteTo(ref output, _repeated_repeatedNestedMessage_codec);
      repeatedForeignMessage_.WriteTo(ref output, _repeated_repeatedForeignMessage_codec);
      repeatedImportMessage_.WriteTo(ref output, _repeated_repeatedImportMessage_codec);
      repeatedNestedEnum_.WriteTo(ref output, _repeated_repeatedNestedEnum_codec);
      repeatedForeignEnum_.WriteTo(ref output, _repeated_repeatedForeignEnum_codec);
      repeatedImportEnum_.WriteTo(ref output, _repeated_repeatedImportEnum_codec);
      repeatedStringPiece_.WriteTo(ref output, _repeated_repeatedStringPiece_codec);
      repeatedCord_.WriteTo(ref output, _repeated_repeatedCord_codec);
      repeatedLazyMessage_.WriteTo(ref output, _repeated_repeatedLazyMessage_codec);
      if (HasDefaultInt32) {
        output.WriteRawTag(232, 3);
        output.WriteInt32(DefaultInt32);
      }
      if (HasDefaultInt64) {
        output.WriteRawTag(240, 3);
        output.WriteInt64(DefaultInt64);
      }
      if (HasDefaultUint32) {
        output.WriteRawTag(248, 3);
        output.WriteUInt32(DefaultUint32);
      }
      if (HasDefaultUint64) {
        output.WriteRawTag(128, 4);
        output.WriteUInt64(DefaultUint64);
      }
      if (HasDefaultSint32) {
        output.WriteRawTag(136, 4);
        output.WriteSInt32(DefaultSint32);
      }
      if (HasDefaultSint64) {
        output.WriteRawTag(144, 4);
        output.WriteSInt64(DefaultSint64);
      }
      if (HasDefaultFixed32) {
        output.WriteRawTag(157, 4);
        output.WriteFixed32(DefaultFixed32);
      }
      if (HasDefaultFixed64) {
        output.WriteRawTag(161, 4);
        output.WriteFixed64(DefaultFixed64);
      }
      if (HasDefaultSfixed32) {
        output.WriteRawTag(173, 4);
        output.WriteSFixed32(DefaultSfixed32);
      }
      if (HasDefaultSfixed64) {
        output.WriteRawTag(177, 4);
        output.WriteSFixed64(DefaultSfixed64);
      }
      if (HasDefaultFloat) {
        output.WriteRawTag(189, 4);
        output.WriteFloat(DefaultFloat);
      }
      if (HasDefaultDouble) {
        output.WriteRawTag(193, 4);
        output.WriteDouble(DefaultDouble);
      }
      if (HasDefaultBool) {
        output.WriteRawTag(200, 4);
        output.WriteBool(DefaultBool);
      }
      if (HasDefaultString) {
        output.WriteRawTag(210, 4);
        output.WriteString(DefaultString);
      }
      if (HasDefaultBytes) {
        output.WriteRawTag(218, 4);
        output.WriteBytes(DefaultBytes);
      }
      if (HasDefaultNestedEnum) {
        output.WriteRawTag(136, 5);
        output.WriteEnum((int) DefaultNestedEnum);
      }
      if (HasDefaultForeignEnum) {
        output.WriteRawTag(144, 5);
        output.WriteEnum((int) DefaultForeignEnum);
      }
      if (HasDefaultImportEnum) {
        output.WriteRawTag(152, 5);
        output.WriteEnum((int) DefaultImportEnum);
      }
      if (HasDefaultStringPiece) {
        output.WriteRawTag(162, 5);
        output.WriteString(DefaultStringPiece);
      }
      if (HasDefaultCord) {
        output.WriteRawTag(170, 5);
        output.WriteString(DefaultCord);
      }
      if (HasOneofUint32) {
        output.WriteRawTag(248, 6);
        output.WriteUInt32(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
        output.WriteRawTag(130, 7);
        output.WriteMessage(OneofNestedMessage);
      }
      if (HasOneofString) {
        output.WriteRawTag(138, 7);
        output.WriteString(OneofString);
      }
      if (HasOneofBytes) {
        output.WriteRawTag(146, 7);
        output.WriteBytes(OneofBytes);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasOptionalInt32) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(OptionalInt32);
      }
      if (HasOptionalInt64) {
        size += 1 + pb::CodedOutputStream.ComputeInt64Size(OptionalInt64);
      }
      if (HasOptionalUint32) {
        size += 1 + pb::CodedOutputStream.ComputeUInt32Size(OptionalUint32);
      }
      if (HasOptionalUint64) {
        size += 1 + pb::CodedOutputStream.ComputeUInt64Size(OptionalUint64);
      }
      if (HasOptionalSint32) {
        size += 1 + pb::CodedOutputStream.ComputeSInt32Size(OptionalSint32);
      }
      if (HasOptionalSint64) {
        size += 1 + pb::CodedOutputStream.ComputeSInt64Size(OptionalSint64);
      }
      if (HasOptionalFixed32) {
        size += 1 + 4;
      }
      if (HasOptionalFixed64) {
        size += 1 + 8;
      }
      if (HasOptionalSfixed32) {
        size += 1 + 4;
      }
      if (HasOptionalSfixed64) {
        size += 1 + 8;
      }
      if (HasOptionalFloat) {
        size += 1 + 4;
      }
      if (HasOptionalDouble) {
        size += 1 + 8;
      }
      if (HasOptionalBool) {
        size += 1 + 1;
      }
      if (HasOptionalString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(OptionalString);
      }
      if (HasOptionalBytes) {
        size += 1 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes);
      }
      if (HasOptionalGroup) {
        size += 4 + pb::CodedOutputStream.ComputeGroupSize(OptionalGroup);
      }
      if (optionalNestedMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
      }
      if (optionalForeignMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalForeignMessage);
      }
      if (optionalImportMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalImportMessage);
      }
      if (HasOptionalNestedEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalNestedEnum);
      }
      if (HasOptionalForeignEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalForeignEnum);
      }
      if (HasOptionalImportEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalImportEnum);
      }
      if (HasOptionalStringPiece) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalStringPiece);
      }
      if (HasOptionalCord) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalCord);
      }
      if (optionalPublicImportMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalPublicImportMessage);
      }
      if (optionalLazyMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalLazyMessage);
      }
      size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
      size += repeatedInt64_.CalculateSize(_repeated_repeatedInt64_codec);
      size += repeatedUint32_.CalculateSize(_repeated_repeatedUint32_codec);
      size += repeatedUint64_.CalculateSize(_repeated_repeatedUint64_codec);
      size += repeatedSint32_.CalculateSize(_repeated_repeatedSint32_codec);
      size += repeatedSint64_.CalculateSize(_repeated_repeatedSint64_codec);
      size += repeatedFixed32_.CalculateSize(_repeated_repeatedFixed32_codec);
      size += repeatedFixed64_.CalculateSize(_repeated_repeatedFixed64_codec);
      size += repeatedSfixed32_.CalculateSize(_repeated_repeatedSfixed32_codec);
      size += repeatedSfixed64_.CalculateSize(_repeated_repeatedSfixed64_codec);
      size += repeatedFloat_.CalculateSize(_repeated_repeatedFloat_codec);
      size += repeatedDouble_.CalculateSize(_repeated_repeatedDouble_codec);
      size += repeatedBool_.CalculateSize(_repeated_repeatedBool_codec);
      size += repeatedString_.CalculateSize(_repeated_repeatedString_codec);
      size += repeatedBytes_.CalculateSize(_repeated_repeatedBytes_codec);
      size += repeatedGroup_.CalculateSize(_repeated_repeatedGroup_codec);
      size += repeatedNestedMessage_.CalculateSize(_repeated_repeatedNestedMessage_codec);
      size += repeatedForeignMessage_.CalculateSize(_repeated_repeatedForeignMessage_codec);
      size += repeatedImportMessage_.CalculateSize(_repeated_repeatedImportMessage_codec);
      size += repeatedNestedEnum_.CalculateSize(_repeated_repeatedNestedEnum_codec);
      size += repeatedForeignEnum_.CalculateSize(_repeated_repeatedForeignEnum_codec);
      size += repeatedImportEnum_.CalculateSize(_repeated_repeatedImportEnum_codec);
      size += repeatedStringPiece_.CalculateSize(_repeated_repeatedStringPiece_codec);
      size += repeatedCord_.CalculateSize(_repeated_repeatedCord_codec);
      size += repeatedLazyMessage_.CalculateSize(_repeated_repeatedLazyMessage_codec);
      if (HasDefaultInt32) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(DefaultInt32);
      }
      if (HasDefaultInt64) {
        size += 2 + pb::CodedOutputStream.ComputeInt64Size(DefaultInt64);
      }
      if (HasDefaultUint32) {
        size += 2 + pb::CodedOutputStream.ComputeUInt32Size(DefaultUint32);
      }
      if (HasDefaultUint64) {
        size += 2 + pb::CodedOutputStream.ComputeUInt64Size(DefaultUint64);
      }
      if (HasDefaultSint32) {
        size += 2 + pb::CodedOutputStream.ComputeSInt32Size(DefaultSint32);
      }
      if (HasDefaultSint64) {
        size += 2 + pb::CodedOutputStream.ComputeSInt64Size(DefaultSint64);
      }
      if (HasDefaultFixed32) {
        size += 2 + 4;
      }
      if (HasDefaultFixed64) {
        size += 2 + 8;
      }
      if (HasDefaultSfixed32) {
        size += 2 + 4;
      }
      if (HasDefaultSfixed64) {
        size += 2 + 8;
      }
      if (HasDefaultFloat) {
        size += 2 + 4;
      }
      if (HasDefaultDouble) {
        size += 2 + 8;
      }
      if (HasDefaultBool) {
        size += 2 + 1;
      }
      if (HasDefaultString) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(DefaultString);
      }
      if (HasDefaultBytes) {
        size += 2 + pb::CodedOutputStream.ComputeBytesSize(DefaultBytes);
      }
      if (HasDefaultNestedEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) DefaultNestedEnum);
      }
      if (HasDefaultForeignEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) DefaultForeignEnum);
      }
      if (HasDefaultImportEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) DefaultImportEnum);
      }
      if (HasDefaultStringPiece) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(DefaultStringPiece);
      }
      if (HasDefaultCord) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(DefaultCord);
      }
      if (HasOneofUint32) {
        size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage);
      }
      if (HasOneofString) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(OneofString);
      }
      if (HasOneofBytes) {
        size += 2 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestAllTypes other) {
      if (other == null) {
        return;
      }
      if (other.HasOptionalInt32) {
        OptionalInt32 = other.OptionalInt32;
      }
      if (other.HasOptionalInt64) {
        OptionalInt64 = other.OptionalInt64;
      }
      if (other.HasOptionalUint32) {
        OptionalUint32 = other.OptionalUint32;
      }
      if (other.HasOptionalUint64) {
        OptionalUint64 = other.OptionalUint64;
      }
      if (other.HasOptionalSint32) {
        OptionalSint32 = other.OptionalSint32;
      }
      if (other.HasOptionalSint64) {
        OptionalSint64 = other.OptionalSint64;
      }
      if (other.HasOptionalFixed32) {
        OptionalFixed32 = other.OptionalFixed32;
      }
      if (other.HasOptionalFixed64) {
        OptionalFixed64 = other.OptionalFixed64;
      }
      if (other.HasOptionalSfixed32) {
        OptionalSfixed32 = other.OptionalSfixed32;
      }
      if (other.HasOptionalSfixed64) {
        OptionalSfixed64 = other.OptionalSfixed64;
      }
      if (other.HasOptionalFloat) {
        OptionalFloat = other.OptionalFloat;
      }
      if (other.HasOptionalDouble) {
        OptionalDouble = other.OptionalDouble;
      }
      if (other.HasOptionalBool) {
        OptionalBool = other.OptionalBool;
      }
      if (other.HasOptionalString) {
        OptionalString = other.OptionalString;
      }
      if (other.HasOptionalBytes) {
        OptionalBytes = other.OptionalBytes;
      }
      if (other.HasOptionalGroup) {
        if (!HasOptionalGroup) {
          OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup();
        }
        OptionalGroup.MergeFrom(other.OptionalGroup);
      }
      if (other.optionalNestedMessage_ != null) {
        if (optionalNestedMessage_ == null) {
          OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
        }
        OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
      }
      if (other.optionalForeignMessage_ != null) {
        if (optionalForeignMessage_ == null) {
          OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
        }
        OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage);
      }
      if (other.optionalImportMessage_ != null) {
        if (optionalImportMessage_ == null) {
          OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage();
        }
        OptionalImportMessage.MergeFrom(other.OptionalImportMessage);
      }
      if (other.HasOptionalNestedEnum) {
        OptionalNestedEnum = other.OptionalNestedEnum;
      }
      if (other.HasOptionalForeignEnum) {
        OptionalForeignEnum = other.OptionalForeignEnum;
      }
      if (other.HasOptionalImportEnum) {
        OptionalImportEnum = other.OptionalImportEnum;
      }
      if (other.HasOptionalStringPiece) {
        OptionalStringPiece = other.OptionalStringPiece;
      }
      if (other.HasOptionalCord) {
        OptionalCord = other.OptionalCord;
      }
      if (other.optionalPublicImportMessage_ != null) {
        if (optionalPublicImportMessage_ == null) {
          OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage();
        }
        OptionalPublicImportMessage.MergeFrom(other.OptionalPublicImportMessage);
      }
      if (other.optionalLazyMessage_ != null) {
        if (optionalLazyMessage_ == null) {
          OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
        }
        OptionalLazyMessage.MergeFrom(other.OptionalLazyMessage);
      }
      repeatedInt32_.Add(other.repeatedInt32_);
      repeatedInt64_.Add(other.repeatedInt64_);
      repeatedUint32_.Add(other.repeatedUint32_);
      repeatedUint64_.Add(other.repeatedUint64_);
      repeatedSint32_.Add(other.repeatedSint32_);
      repeatedSint64_.Add(other.repeatedSint64_);
      repeatedFixed32_.Add(other.repeatedFixed32_);
      repeatedFixed64_.Add(other.repeatedFixed64_);
      repeatedSfixed32_.Add(other.repeatedSfixed32_);
      repeatedSfixed64_.Add(other.repeatedSfixed64_);
      repeatedFloat_.Add(other.repeatedFloat_);
      repeatedDouble_.Add(other.repeatedDouble_);
      repeatedBool_.Add(other.repeatedBool_);
      repeatedString_.Add(other.repeatedString_);
      repeatedBytes_.Add(other.repeatedBytes_);
      repeatedGroup_.Add(other.repeatedGroup_);
      repeatedNestedMessage_.Add(other.repeatedNestedMessage_);
      repeatedForeignMessage_.Add(other.repeatedForeignMessage_);
      repeatedImportMessage_.Add(other.repeatedImportMessage_);
      repeatedNestedEnum_.Add(other.repeatedNestedEnum_);
      repeatedForeignEnum_.Add(other.repeatedForeignEnum_);
      repeatedImportEnum_.Add(other.repeatedImportEnum_);
      repeatedStringPiece_.Add(other.repeatedStringPiece_);
      repeatedCord_.Add(other.repeatedCord_);
      repeatedLazyMessage_.Add(other.repeatedLazyMessage_);
      if (other.HasDefaultInt32) {
        DefaultInt32 = other.DefaultInt32;
      }
      if (other.HasDefaultInt64) {
        DefaultInt64 = other.DefaultInt64;
      }
      if (other.HasDefaultUint32) {
        DefaultUint32 = other.DefaultUint32;
      }
      if (other.HasDefaultUint64) {
        DefaultUint64 = other.DefaultUint64;
      }
      if (other.HasDefaultSint32) {
        DefaultSint32 = other.DefaultSint32;
      }
      if (other.HasDefaultSint64) {
        DefaultSint64 = other.DefaultSint64;
      }
      if (other.HasDefaultFixed32) {
        DefaultFixed32 = other.DefaultFixed32;
      }
      if (other.HasDefaultFixed64) {
        DefaultFixed64 = other.DefaultFixed64;
      }
      if (other.HasDefaultSfixed32) {
        DefaultSfixed32 = other.DefaultSfixed32;
      }
      if (other.HasDefaultSfixed64) {
        DefaultSfixed64 = other.DefaultSfixed64;
      }
      if (other.HasDefaultFloat) {
        DefaultFloat = other.DefaultFloat;
      }
      if (other.HasDefaultDouble) {
        DefaultDouble = other.DefaultDouble;
      }
      if (other.HasDefaultBool) {
        DefaultBool = other.DefaultBool;
      }
      if (other.HasDefaultString) {
        DefaultString = other.DefaultString;
      }
      if (other.HasDefaultBytes) {
        DefaultBytes = other.DefaultBytes;
      }
      if (other.HasDefaultNestedEnum) {
        DefaultNestedEnum = other.DefaultNestedEnum;
      }
      if (other.HasDefaultForeignEnum) {
        DefaultForeignEnum = other.DefaultForeignEnum;
      }
      if (other.HasDefaultImportEnum) {
        DefaultImportEnum = other.DefaultImportEnum;
      }
      if (other.HasDefaultStringPiece) {
        DefaultStringPiece = other.DefaultStringPiece;
      }
      if (other.HasDefaultCord) {
        DefaultCord = other.DefaultCord;
      }
      switch (other.OneofFieldCase) {
        case OneofFieldOneofCase.OneofUint32:
          OneofUint32 = other.OneofUint32;
          break;
        case OneofFieldOneofCase.OneofNestedMessage:
          if (OneofNestedMessage == null) {
            OneofNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
          }
          OneofNestedMessage.MergeFrom(other.OneofNestedMessage);
          break;
        case OneofFieldOneofCase.OneofString:
          OneofString = other.OneofString;
          break;
        case OneofFieldOneofCase.OneofBytes:
          OneofBytes = other.OneofBytes;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
          case 16: {
            OptionalInt64 = input.ReadInt64();
            break;
          }
          case 24: {
            OptionalUint32 = input.ReadUInt32();
            break;
          }
          case 32: {
            OptionalUint64 = input.ReadUInt64();
            break;
          }
          case 40: {
            OptionalSint32 = input.ReadSInt32();
            break;
          }
          case 48: {
            OptionalSint64 = input.ReadSInt64();
            break;
          }
          case 61: {
            OptionalFixed32 = input.ReadFixed32();
            break;
          }
          case 65: {
            OptionalFixed64 = input.ReadFixed64();
            break;
          }
          case 77: {
            OptionalSfixed32 = input.ReadSFixed32();
            break;
          }
          case 81: {
            OptionalSfixed64 = input.ReadSFixed64();
            break;
          }
          case 93: {
            OptionalFloat = input.ReadFloat();
            break;
          }
          case 97: {
            OptionalDouble = input.ReadDouble();
            break;
          }
          case 104: {
            OptionalBool = input.ReadBool();
            break;
          }
          case 114: {
            OptionalString = input.ReadString();
            break;
          }
          case 122: {
            OptionalBytes = input.ReadBytes();
            break;
          }
          case 131: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 146: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
          case 154: {
            if (optionalForeignMessage_ == null) {
              OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(OptionalForeignMessage);
            break;
          }
          case 162: {
            if (optionalImportMessage_ == null) {
              OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage();
            }
            input.ReadMessage(OptionalImportMessage);
            break;
          }
          case 168: {
            OptionalNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum();
            break;
          }
          case 176: {
            OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 184: {
            OptionalImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum();
            break;
          }
          case 194: {
            OptionalStringPiece = input.ReadString();
            break;
          }
          case 202: {
            OptionalCord = input.ReadString();
            break;
          }
          case 210: {
            if (optionalPublicImportMessage_ == null) {
              OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage();
            }
            input.ReadMessage(OptionalPublicImportMessage);
            break;
          }
          case 218: {
            if (optionalLazyMessage_ == null) {
              OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(OptionalLazyMessage);
            break;
          }
          case 250:
          case 248: {
            repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
            break;
          }
          case 258:
          case 256: {
            repeatedInt64_.AddEntriesFrom(input, _repeated_repeatedInt64_codec);
            break;
          }
          case 266:
          case 264: {
            repeatedUint32_.AddEntriesFrom(input, _repeated_repeatedUint32_codec);
            break;
          }
          case 274:
          case 272: {
            repeatedUint64_.AddEntriesFrom(input, _repeated_repeatedUint64_codec);
            break;
          }
          case 282:
          case 280: {
            repeatedSint32_.AddEntriesFrom(input, _repeated_repeatedSint32_codec);
            break;
          }
          case 290:
          case 288: {
            repeatedSint64_.AddEntriesFrom(input, _repeated_repeatedSint64_codec);
            break;
          }
          case 298:
          case 301: {
            repeatedFixed32_.AddEntriesFrom(input, _repeated_repeatedFixed32_codec);
            break;
          }
          case 306:
          case 305: {
            repeatedFixed64_.AddEntriesFrom(input, _repeated_repeatedFixed64_codec);
            break;
          }
          case 314:
          case 317: {
            repeatedSfixed32_.AddEntriesFrom(input, _repeated_repeatedSfixed32_codec);
            break;
          }
          case 322:
          case 321: {
            repeatedSfixed64_.AddEntriesFrom(input, _repeated_repeatedSfixed64_codec);
            break;
          }
          case 330:
          case 333: {
            repeatedFloat_.AddEntriesFrom(input, _repeated_repeatedFloat_codec);
            break;
          }
          case 338:
          case 337: {
            repeatedDouble_.AddEntriesFrom(input, _repeated_repeatedDouble_codec);
            break;
          }
          case 346:
          case 344: {
            repeatedBool_.AddEntriesFrom(input, _repeated_repeatedBool_codec);
            break;
          }
          case 354: {
            repeatedString_.AddEntriesFrom(input, _repeated_repeatedString_codec);
            break;
          }
          case 362: {
            repeatedBytes_.AddEntriesFrom(input, _repeated_repeatedBytes_codec);
            break;
          }
          case 371: {
            repeatedGroup_.AddEntriesFrom(input, _repeated_repeatedGroup_codec);
            break;
          }
          case 386: {
            repeatedNestedMessage_.AddEntriesFrom(input, _repeated_repeatedNestedMessage_codec);
            break;
          }
          case 394: {
            repeatedForeignMessage_.AddEntriesFrom(input, _repeated_repeatedForeignMessage_codec);
            break;
          }
          case 402: {
            repeatedImportMessage_.AddEntriesFrom(input, _repeated_repeatedImportMessage_codec);
            break;
          }
          case 410:
          case 408: {
            repeatedNestedEnum_.AddEntriesFrom(input, _repeated_repeatedNestedEnum_codec);
            break;
          }
          case 418:
          case 416: {
            repeatedForeignEnum_.AddEntriesFrom(input, _repeated_repeatedForeignEnum_codec);
            break;
          }
          case 426:
          case 424: {
            repeatedImportEnum_.AddEntriesFrom(input, _repeated_repeatedImportEnum_codec);
            break;
          }
          case 434: {
            repeatedStringPiece_.AddEntriesFrom(input, _repeated_repeatedStringPiece_codec);
            break;
          }
          case 442: {
            repeatedCord_.AddEntriesFrom(input, _repeated_repeatedCord_codec);
            break;
          }
          case 458: {
            repeatedLazyMessage_.AddEntriesFrom(input, _repeated_repeatedLazyMessage_codec);
            break;
          }
          case 488: {
            DefaultInt32 = input.ReadInt32();
            break;
          }
          case 496: {
            DefaultInt64 = input.ReadInt64();
            break;
          }
          case 504: {
            DefaultUint32 = input.ReadUInt32();
            break;
          }
          case 512: {
            DefaultUint64 = input.ReadUInt64();
            break;
          }
          case 520: {
            DefaultSint32 = input.ReadSInt32();
            break;
          }
          case 528: {
            DefaultSint64 = input.ReadSInt64();
            break;
          }
          case 541: {
            DefaultFixed32 = input.ReadFixed32();
            break;
          }
          case 545: {
            DefaultFixed64 = input.ReadFixed64();
            break;
          }
          case 557: {
            DefaultSfixed32 = input.ReadSFixed32();
            break;
          }
          case 561: {
            DefaultSfixed64 = input.ReadSFixed64();
            break;
          }
          case 573: {
            DefaultFloat = input.ReadFloat();
            break;
          }
          case 577: {
            DefaultDouble = input.ReadDouble();
            break;
          }
          case 584: {
            DefaultBool = input.ReadBool();
            break;
          }
          case 594: {
            DefaultString = input.ReadString();
            break;
          }
          case 602: {
            DefaultBytes = input.ReadBytes();
            break;
          }
          case 648: {
            DefaultNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum();
            break;
          }
          case 656: {
            DefaultForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 664: {
            DefaultImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum();
            break;
          }
          case 674: {
            DefaultStringPiece = input.ReadString();
            break;
          }
          case 682: {
            DefaultCord = input.ReadString();
            break;
          }
          case 888: {
            OneofUint32 = input.ReadUInt32();
            break;
          }
          case 898: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
              subBuilder.MergeFrom(OneofNestedMessage);
            }
            input.ReadMessage(subBuilder);
            OneofNestedMessage = subBuilder;
            break;
          }
          case 906: {
            OneofString = input.ReadString();
            break;
          }
          case 914: {
            OneofBytes = input.ReadBytes();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
          case 16: {
            OptionalInt64 = input.ReadInt64();
            break;
          }
          case 24: {
            OptionalUint32 = input.ReadUInt32();
            break;
          }
          case 32: {
            OptionalUint64 = input.ReadUInt64();
            break;
          }
          case 40: {
            OptionalSint32 = input.ReadSInt32();
            break;
          }
          case 48: {
            OptionalSint64 = input.ReadSInt64();
            break;
          }
          case 61: {
            OptionalFixed32 = input.ReadFixed32();
            break;
          }
          case 65: {
            OptionalFixed64 = input.ReadFixed64();
            break;
          }
          case 77: {
            OptionalSfixed32 = input.ReadSFixed32();
            break;
          }
          case 81: {
            OptionalSfixed64 = input.ReadSFixed64();
            break;
          }
          case 93: {
            OptionalFloat = input.ReadFloat();
            break;
          }
          case 97: {
            OptionalDouble = input.ReadDouble();
            break;
          }
          case 104: {
            OptionalBool = input.ReadBool();
            break;
          }
          case 114: {
            OptionalString = input.ReadString();
            break;
          }
          case 122: {
            OptionalBytes = input.ReadBytes();
            break;
          }
          case 131: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 146: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
          case 154: {
            if (optionalForeignMessage_ == null) {
              OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(OptionalForeignMessage);
            break;
          }
          case 162: {
            if (optionalImportMessage_ == null) {
              OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage();
            }
            input.ReadMessage(OptionalImportMessage);
            break;
          }
          case 168: {
            OptionalNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum();
            break;
          }
          case 176: {
            OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 184: {
            OptionalImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum();
            break;
          }
          case 194: {
            OptionalStringPiece = input.ReadString();
            break;
          }
          case 202: {
            OptionalCord = input.ReadString();
            break;
          }
          case 210: {
            if (optionalPublicImportMessage_ == null) {
              OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage();
            }
            input.ReadMessage(OptionalPublicImportMessage);
            break;
          }
          case 218: {
            if (optionalLazyMessage_ == null) {
              OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(OptionalLazyMessage);
            break;
          }
          case 250:
          case 248: {
            repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec);
            break;
          }
          case 258:
          case 256: {
            repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec);
            break;
          }
          case 266:
          case 264: {
            repeatedUint32_.AddEntriesFrom(ref input, _repeated_repeatedUint32_codec);
            break;
          }
          case 274:
          case 272: {
            repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec);
            break;
          }
          case 282:
          case 280: {
            repeatedSint32_.AddEntriesFrom(ref input, _repeated_repeatedSint32_codec);
            break;
          }
          case 290:
          case 288: {
            repeatedSint64_.AddEntriesFrom(ref input, _repeated_repeatedSint64_codec);
            break;
          }
          case 298:
          case 301: {
            repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec);
            break;
          }
          case 306:
          case 305: {
            repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec);
            break;
          }
          case 314:
          case 317: {
            repeatedSfixed32_.AddEntriesFrom(ref input, _repeated_repeatedSfixed32_codec);
            break;
          }
          case 322:
          case 321: {
            repeatedSfixed64_.AddEntriesFrom(ref input, _repeated_repeatedSfixed64_codec);
            break;
          }
          case 330:
          case 333: {
            repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec);
            break;
          }
          case 338:
          case 337: {
            repeatedDouble_.AddEntriesFrom(ref input, _repeated_repeatedDouble_codec);
            break;
          }
          case 346:
          case 344: {
            repeatedBool_.AddEntriesFrom(ref input, _repeated_repeatedBool_codec);
            break;
          }
          case 354: {
            repeatedString_.AddEntriesFrom(ref input, _repeated_repeatedString_codec);
            break;
          }
          case 362: {
            repeatedBytes_.AddEntriesFrom(ref input, _repeated_repeatedBytes_codec);
            break;
          }
          case 371: {
            repeatedGroup_.AddEntriesFrom(ref input, _repeated_repeatedGroup_codec);
            break;
          }
          case 386: {
            repeatedNestedMessage_.AddEntriesFrom(ref input, _repeated_repeatedNestedMessage_codec);
            break;
          }
          case 394: {
            repeatedForeignMessage_.AddEntriesFrom(ref input, _repeated_repeatedForeignMessage_codec);
            break;
          }
          case 402: {
            repeatedImportMessage_.AddEntriesFrom(ref input, _repeated_repeatedImportMessage_codec);
            break;
          }
          case 410:
          case 408: {
            repeatedNestedEnum_.AddEntriesFrom(ref input, _repeated_repeatedNestedEnum_codec);
            break;
          }
          case 418:
          case 416: {
            repeatedForeignEnum_.AddEntriesFrom(ref input, _repeated_repeatedForeignEnum_codec);
            break;
          }
          case 426:
          case 424: {
            repeatedImportEnum_.AddEntriesFrom(ref input, _repeated_repeatedImportEnum_codec);
            break;
          }
          case 434: {
            repeatedStringPiece_.AddEntriesFrom(ref input, _repeated_repeatedStringPiece_codec);
            break;
          }
          case 442: {
            repeatedCord_.AddEntriesFrom(ref input, _repeated_repeatedCord_codec);
            break;
          }
          case 458: {
            repeatedLazyMessage_.AddEntriesFrom(ref input, _repeated_repeatedLazyMessage_codec);
            break;
          }
          case 488: {
            DefaultInt32 = input.ReadInt32();
            break;
          }
          case 496: {
            DefaultInt64 = input.ReadInt64();
            break;
          }
          case 504: {
            DefaultUint32 = input.ReadUInt32();
            break;
          }
          case 512: {
            DefaultUint64 = input.ReadUInt64();
            break;
          }
          case 520: {
            DefaultSint32 = input.ReadSInt32();
            break;
          }
          case 528: {
            DefaultSint64 = input.ReadSInt64();
            break;
          }
          case 541: {
            DefaultFixed32 = input.ReadFixed32();
            break;
          }
          case 545: {
            DefaultFixed64 = input.ReadFixed64();
            break;
          }
          case 557: {
            DefaultSfixed32 = input.ReadSFixed32();
            break;
          }
          case 561: {
            DefaultSfixed64 = input.ReadSFixed64();
            break;
          }
          case 573: {
            DefaultFloat = input.ReadFloat();
            break;
          }
          case 577: {
            DefaultDouble = input.ReadDouble();
            break;
          }
          case 584: {
            DefaultBool = input.ReadBool();
            break;
          }
          case 594: {
            DefaultString = input.ReadString();
            break;
          }
          case 602: {
            DefaultBytes = input.ReadBytes();
            break;
          }
          case 648: {
            DefaultNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum();
            break;
          }
          case 656: {
            DefaultForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 664: {
            DefaultImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum();
            break;
          }
          case 674: {
            DefaultStringPiece = input.ReadString();
            break;
          }
          case 682: {
            DefaultCord = input.ReadString();
            break;
          }
          case 888: {
            OneofUint32 = input.ReadUInt32();
            break;
          }
          case 898: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
              subBuilder.MergeFrom(OneofNestedMessage);
            }
            input.ReadMessage(subBuilder);
            OneofNestedMessage = subBuilder;
            break;
          }
          case 906: {
            OneofString = input.ReadString();
            break;
          }
          case 914: {
            OneofBytes = input.ReadBytes();
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestAllTypes message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public enum NestedEnum {
        [pbr::OriginalName("FOO")] Foo = 1,
        [pbr::OriginalName("BAR")] Bar = 2,
        [pbr::OriginalName("BAZ")] Baz = 3,
        /// <summary>
        /// Intentionally negative.
        /// </summary>
        [pbr::OriginalName("NEG")] Neg = -1,
      }

      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          _hasBits0 = other._hasBits0;
          bb_ = other.bb_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "bb" field.</summary>
        public const int BbFieldNumber = 1;
        private readonly static int BbDefaultValue = 0;

        private int bb_;
        /// <summary>
        /// The field name "b" fails to compile in proto1 because it conflicts with
        /// a local variable named "b" in one of the generated methods.  Doh.
        /// This file needs to compile in proto1 to test backwards-compatibility.
        /// </summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int Bb {
          get { if ((_hasBits0 & 1) != 0) { return bb_; } else { return BbDefaultValue; } }
          set {
            _hasBits0 |= 1;
            bb_ = value;
          }
        }
        /// <summary>Gets whether the "bb" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasBb {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "bb" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearBb() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (Bb != other.Bb) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasBb) hash ^= Bb.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasBb) {
            output.WriteRawTag(8);
            output.WriteInt32(Bb);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasBb) {
            output.WriteRawTag(8);
            output.WriteInt32(Bb);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasBb) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(Bb);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasBb) {
            Bb = other.Bb;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                Bb = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                Bb = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class OptionalGroup : pb::IMessage<OptionalGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<OptionalGroup> _parser = new pb::MessageParser<OptionalGroup>(() => new OptionalGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<OptionalGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup(OptionalGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup Clone() {
          return new OptionalGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 17;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as OptionalGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(OptionalGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(OptionalGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class RepeatedGroup : pb::IMessage<RepeatedGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<RepeatedGroup> _parser = new pb::MessageParser<RepeatedGroup>(() => new RepeatedGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<RepeatedGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Descriptor.NestedTypes[2]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup(RepeatedGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup Clone() {
          return new RepeatedGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 47;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as RepeatedGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(RepeatedGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(248, 2);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(248, 2);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(RepeatedGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 372:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 376: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 372:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 376: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  /// <summary>
  /// This proto includes a recursively nested message.
  /// </summary>
  public sealed partial class NestedTestAllTypes : pb::IMessage<NestedTestAllTypes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<NestedTestAllTypes> _parser = new pb::MessageParser<NestedTestAllTypes>(() => new NestedTestAllTypes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<NestedTestAllTypes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[1]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public NestedTestAllTypes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public NestedTestAllTypes(NestedTestAllTypes other) : this() {
      child_ = other.child_ != null ? other.child_.Clone() : null;
      payload_ = other.payload_ != null ? other.payload_.Clone() : null;
      repeatedChild_ = other.repeatedChild_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public NestedTestAllTypes Clone() {
      return new NestedTestAllTypes(this);
    }

    /// <summary>Field number for the "child" field.</summary>
    public const int ChildFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes child_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes Child {
      get { return child_; }
      set {
        child_ = value;
      }
    }

    /// <summary>Field number for the "payload" field.</summary>
    public const int PayloadFieldNumber = 2;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes payload_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes Payload {
      get { return payload_; }
      set {
        payload_ = value;
      }
    }

    /// <summary>Field number for the "repeated_child" field.</summary>
    public const int RepeatedChildFieldNumber = 3;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes> _repeated_repeatedChild_codec
        = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes> repeatedChild_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes> RepeatedChild {
      get { return repeatedChild_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as NestedTestAllTypes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(NestedTestAllTypes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(Child, other.Child)) return false;
      if (!object.Equals(Payload, other.Payload)) return false;
      if(!repeatedChild_.Equals(other.repeatedChild_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (child_ != null) hash ^= Child.GetHashCode();
      if (payload_ != null) hash ^= Payload.GetHashCode();
      hash ^= repeatedChild_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (child_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(Child);
      }
      if (payload_ != null) {
        output.WriteRawTag(18);
        output.WriteMessage(Payload);
      }
      repeatedChild_.WriteTo(output, _repeated_repeatedChild_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (child_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(Child);
      }
      if (payload_ != null) {
        output.WriteRawTag(18);
        output.WriteMessage(Payload);
      }
      repeatedChild_.WriteTo(ref output, _repeated_repeatedChild_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (child_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(Child);
      }
      if (payload_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(Payload);
      }
      size += repeatedChild_.CalculateSize(_repeated_repeatedChild_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(NestedTestAllTypes other) {
      if (other == null) {
        return;
      }
      if (other.child_ != null) {
        if (child_ == null) {
          Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes();
        }
        Child.MergeFrom(other.Child);
      }
      if (other.payload_ != null) {
        if (payload_ == null) {
          Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        Payload.MergeFrom(other.Payload);
      }
      repeatedChild_.Add(other.repeatedChild_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (child_ == null) {
              Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes();
            }
            input.ReadMessage(Child);
            break;
          }
          case 18: {
            if (payload_ == null) {
              Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(Payload);
            break;
          }
          case 26: {
            repeatedChild_.AddEntriesFrom(input, _repeated_repeatedChild_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (child_ == null) {
              Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes();
            }
            input.ReadMessage(Child);
            break;
          }
          case 18: {
            if (payload_ == null) {
              Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(Payload);
            break;
          }
          case 26: {
            repeatedChild_.AddEntriesFrom(ref input, _repeated_repeatedChild_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestDeprecatedFields : pb::IMessage<TestDeprecatedFields>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestDeprecatedFields> _parser = new pb::MessageParser<TestDeprecatedFields>(() => new TestDeprecatedFields());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestDeprecatedFields> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[2]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedFields() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedFields(TestDeprecatedFields other) : this() {
      _hasBits0 = other._hasBits0;
      deprecatedInt32_ = other.deprecatedInt32_;
      switch (other.OneofFieldsCase) {
        case OneofFieldsOneofCase.DeprecatedInt32InOneof:
          DeprecatedInt32InOneof = other.DeprecatedInt32InOneof;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedFields Clone() {
      return new TestDeprecatedFields(this);
    }

    /// <summary>Field number for the "deprecated_int32" field.</summary>
    public const int DeprecatedInt32FieldNumber = 1;
    private readonly static int DeprecatedInt32DefaultValue = 0;

    private int deprecatedInt32_;
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int DeprecatedInt32 {
      get { if ((_hasBits0 & 1) != 0) { return deprecatedInt32_; } else { return DeprecatedInt32DefaultValue; } }
      set {
        _hasBits0 |= 1;
        deprecatedInt32_ = value;
      }
    }
    /// <summary>Gets whether the "deprecated_int32" field is set</summary>
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDeprecatedInt32 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "deprecated_int32" field</summary>
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDeprecatedInt32() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "deprecated_int32_in_oneof" field.</summary>
    public const int DeprecatedInt32InOneofFieldNumber = 2;
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int DeprecatedInt32InOneof {
      get { return HasDeprecatedInt32InOneof ? (int) oneofFields_ : 0; }
      set {
        oneofFields_ = value;
        oneofFieldsCase_ = OneofFieldsOneofCase.DeprecatedInt32InOneof;
      }
    }
    /// <summary>Gets whether the "deprecated_int32_in_oneof" field is set</summary>
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDeprecatedInt32InOneof {
      get { return oneofFieldsCase_ == OneofFieldsOneofCase.DeprecatedInt32InOneof; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "deprecated_int32_in_oneof" </summary>
    [global::System.ObsoleteAttribute]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDeprecatedInt32InOneof() {
      if (HasDeprecatedInt32InOneof) {
        ClearOneofFields();
      }
    }

    private object oneofFields_;
    /// <summary>Enum of possible cases for the "oneof_fields" oneof.</summary>
    public enum OneofFieldsOneofCase {
      None = 0,
      DeprecatedInt32InOneof = 2,
    }
    private OneofFieldsOneofCase oneofFieldsCase_ = OneofFieldsOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneofFieldsOneofCase OneofFieldsCase {
      get { return oneofFieldsCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofFields() {
      oneofFieldsCase_ = OneofFieldsOneofCase.None;
      oneofFields_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestDeprecatedFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestDeprecatedFields other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (DeprecatedInt32 != other.DeprecatedInt32) return false;
      if (DeprecatedInt32InOneof != other.DeprecatedInt32InOneof) return false;
      if (OneofFieldsCase != other.OneofFieldsCase) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasDeprecatedInt32) hash ^= DeprecatedInt32.GetHashCode();
      if (HasDeprecatedInt32InOneof) hash ^= DeprecatedInt32InOneof.GetHashCode();
      hash ^= (int) oneofFieldsCase_;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasDeprecatedInt32) {
        output.WriteRawTag(8);
        output.WriteInt32(DeprecatedInt32);
      }
      if (HasDeprecatedInt32InOneof) {
        output.WriteRawTag(16);
        output.WriteInt32(DeprecatedInt32InOneof);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasDeprecatedInt32) {
        output.WriteRawTag(8);
        output.WriteInt32(DeprecatedInt32);
      }
      if (HasDeprecatedInt32InOneof) {
        output.WriteRawTag(16);
        output.WriteInt32(DeprecatedInt32InOneof);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasDeprecatedInt32) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(DeprecatedInt32);
      }
      if (HasDeprecatedInt32InOneof) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(DeprecatedInt32InOneof);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestDeprecatedFields other) {
      if (other == null) {
        return;
      }
      if (other.HasDeprecatedInt32) {
        DeprecatedInt32 = other.DeprecatedInt32;
      }
      switch (other.OneofFieldsCase) {
        case OneofFieldsOneofCase.DeprecatedInt32InOneof:
          DeprecatedInt32InOneof = other.DeprecatedInt32InOneof;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            DeprecatedInt32 = input.ReadInt32();
            break;
          }
          case 16: {
            DeprecatedInt32InOneof = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            DeprecatedInt32 = input.ReadInt32();
            break;
          }
          case 16: {
            DeprecatedInt32InOneof = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  [global::System.ObsoleteAttribute]
  public sealed partial class TestDeprecatedMessage : pb::IMessage<TestDeprecatedMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestDeprecatedMessage> _parser = new pb::MessageParser<TestDeprecatedMessage>(() => new TestDeprecatedMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestDeprecatedMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[3]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedMessage(TestDeprecatedMessage other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDeprecatedMessage Clone() {
      return new TestDeprecatedMessage(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestDeprecatedMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestDeprecatedMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestDeprecatedMessage other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Define these after TestAllTypes to make sure the compiler can handle
  /// that.
  /// </summary>
  public sealed partial class ForeignMessage : pb::IMessage<ForeignMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<ForeignMessage> _parser = new pb::MessageParser<ForeignMessage>(() => new ForeignMessage());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<ForeignMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[4]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ForeignMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ForeignMessage(ForeignMessage other) : this() {
      _hasBits0 = other._hasBits0;
      c_ = other.c_;
      d_ = other.d_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ForeignMessage Clone() {
      return new ForeignMessage(this);
    }

    /// <summary>Field number for the "c" field.</summary>
    public const int CFieldNumber = 1;
    private readonly static int CDefaultValue = 0;

    private int c_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int C {
      get { if ((_hasBits0 & 1) != 0) { return c_; } else { return CDefaultValue; } }
      set {
        _hasBits0 |= 1;
        c_ = value;
      }
    }
    /// <summary>Gets whether the "c" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasC {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "c" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearC() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "d" field.</summary>
    public const int DFieldNumber = 2;
    private readonly static int DDefaultValue = 0;

    private int d_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int D {
      get { if ((_hasBits0 & 2) != 0) { return d_; } else { return DDefaultValue; } }
      set {
        _hasBits0 |= 2;
        d_ = value;
      }
    }
    /// <summary>Gets whether the "d" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasD {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "d" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearD() {
      _hasBits0 &= ~2;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as ForeignMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(ForeignMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (C != other.C) return false;
      if (D != other.D) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasC) hash ^= C.GetHashCode();
      if (HasD) hash ^= D.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasC) {
        output.WriteRawTag(8);
        output.WriteInt32(C);
      }
      if (HasD) {
        output.WriteRawTag(16);
        output.WriteInt32(D);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasC) {
        output.WriteRawTag(8);
        output.WriteInt32(C);
      }
      if (HasD) {
        output.WriteRawTag(16);
        output.WriteInt32(D);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasC) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(C);
      }
      if (HasD) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(D);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(ForeignMessage other) {
      if (other == null) {
        return;
      }
      if (other.HasC) {
        C = other.C;
      }
      if (other.HasD) {
        D = other.D;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            C = input.ReadInt32();
            break;
          }
          case 16: {
            D = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            C = input.ReadInt32();
            break;
          }
          case 16: {
            D = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestReservedFields : pb::IMessage<TestReservedFields>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestReservedFields> _parser = new pb::MessageParser<TestReservedFields>(() => new TestReservedFields());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestReservedFields> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[5]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReservedFields() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReservedFields(TestReservedFields other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReservedFields Clone() {
      return new TestReservedFields(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestReservedFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestReservedFields other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestReservedFields other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class TestAllExtensions : pb::IExtendableMessage<TestAllExtensions>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestAllExtensions> _parser = new pb::MessageParser<TestAllExtensions>(() => new TestAllExtensions());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestAllExtensions> _extensions;
    private pb::ExtensionSet<TestAllExtensions> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestAllExtensions> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[6]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllExtensions() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllExtensions(TestAllExtensions other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestAllExtensions Clone() {
      return new TestAllExtensions(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestAllExtensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestAllExtensions other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestAllExtensions other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestAllExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestAllExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestAllExtensions, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestAllExtensions, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestAllExtensions, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestAllExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestAllExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  public sealed partial class OptionalGroup_extension : pb::IMessage<OptionalGroup_extension>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<OptionalGroup_extension> _parser = new pb::MessageParser<OptionalGroup_extension>(() => new OptionalGroup_extension());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<OptionalGroup_extension> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[7]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OptionalGroup_extension() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OptionalGroup_extension(OptionalGroup_extension other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OptionalGroup_extension Clone() {
      return new OptionalGroup_extension(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 17;
    private readonly static int ADefaultValue = 0;

    private int a_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int A {
      get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
      set {
        _hasBits0 |= 1;
        a_ = value;
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as OptionalGroup_extension);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(OptionalGroup_extension other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(136, 1);
        output.WriteInt32(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(136, 1);
        output.WriteInt32(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(OptionalGroup_extension other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          case 132:
            return;
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 136: {
            A = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          case 132:
            return;
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 136: {
            A = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class RepeatedGroup_extension : pb::IMessage<RepeatedGroup_extension>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<RepeatedGroup_extension> _parser = new pb::MessageParser<RepeatedGroup_extension>(() => new RepeatedGroup_extension());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<RepeatedGroup_extension> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[8]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public RepeatedGroup_extension() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public RepeatedGroup_extension(RepeatedGroup_extension other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public RepeatedGroup_extension Clone() {
      return new RepeatedGroup_extension(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 47;
    private readonly static int ADefaultValue = 0;

    private int a_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int A {
      get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
      set {
        _hasBits0 |= 1;
        a_ = value;
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as RepeatedGroup_extension);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(RepeatedGroup_extension other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(248, 2);
        output.WriteInt32(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(248, 2);
        output.WriteInt32(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(RepeatedGroup_extension other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          case 372:
            return;
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 376: {
            A = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          case 372:
            return;
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 376: {
            A = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestGroup : pb::IMessage<TestGroup>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestGroup> _parser = new pb::MessageParser<TestGroup>(() => new TestGroup());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestGroup> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[9]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroup() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroup(TestGroup other) : this() {
      _hasBits0 = other._hasBits0;
      optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null;
      optionalForeignEnum_ = other.optionalForeignEnum_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroup Clone() {
      return new TestGroup(this);
    }

    /// <summary>Field number for the "optionalgroup" field.</summary>
    public const int OptionalGroupFieldNumber = 16;
    private global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup optionalGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup OptionalGroup {
      get { return optionalGroup_; }
      set {
        optionalGroup_ = value;
      }
    }
    /// <summary>Gets whether the optionalgroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalGroup {
      get { return optionalGroup_ != null; }
    }
    /// <summary>Clears the value of the optionalgroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalGroup() {
      optionalGroup_ = null;
    }

    /// <summary>Field number for the "optional_foreign_enum" field.</summary>
    public const int OptionalForeignEnumFieldNumber = 22;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalForeignEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum optionalForeignEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalForeignEnum {
      get { if ((_hasBits0 & 1) != 0) { return optionalForeignEnum_; } else { return OptionalForeignEnumDefaultValue; } }
      set {
        _hasBits0 |= 1;
        optionalForeignEnum_ = value;
      }
    }
    /// <summary>Gets whether the "optional_foreign_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalForeignEnum {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "optional_foreign_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalForeignEnum() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestGroup);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestGroup other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(OptionalGroup, other.OptionalGroup)) return false;
      if (OptionalForeignEnum != other.OptionalForeignEnum) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode();
      if (HasOptionalForeignEnum) hash ^= OptionalForeignEnum.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasOptionalGroup) {
        output.WriteRawTag(131, 1);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(132, 1);
      }
      if (HasOptionalForeignEnum) {
        output.WriteRawTag(176, 1);
        output.WriteEnum((int) OptionalForeignEnum);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasOptionalGroup) {
        output.WriteRawTag(131, 1);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(132, 1);
      }
      if (HasOptionalForeignEnum) {
        output.WriteRawTag(176, 1);
        output.WriteEnum((int) OptionalForeignEnum);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasOptionalGroup) {
        size += 4 + pb::CodedOutputStream.ComputeGroupSize(OptionalGroup);
      }
      if (HasOptionalForeignEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalForeignEnum);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestGroup other) {
      if (other == null) {
        return;
      }
      if (other.HasOptionalGroup) {
        if (!HasOptionalGroup) {
          OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup();
        }
        OptionalGroup.MergeFrom(other.OptionalGroup);
      }
      if (other.HasOptionalForeignEnum) {
        OptionalForeignEnum = other.OptionalForeignEnum;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 131: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 176: {
            OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 131: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 176: {
            OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestGroup message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class OptionalGroup : pb::IMessage<OptionalGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<OptionalGroup> _parser = new pb::MessageParser<OptionalGroup>(() => new OptionalGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<OptionalGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestGroup.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup(OptionalGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup Clone() {
          return new OptionalGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 17;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as OptionalGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(OptionalGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(OptionalGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestGroupExtension : pb::IExtendableMessage<TestGroupExtension>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestGroupExtension> _parser = new pb::MessageParser<TestGroupExtension>(() => new TestGroupExtension());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestGroupExtension> _extensions;
    private pb::ExtensionSet<TestGroupExtension> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestGroupExtension> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[10]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroupExtension() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroupExtension(TestGroupExtension other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestGroupExtension Clone() {
      return new TestGroupExtension(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestGroupExtension);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestGroupExtension other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestGroupExtension other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestGroupExtension, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestGroupExtension, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestGroupExtension, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestGroupExtension, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestGroupExtension, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestGroupExtension, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestGroupExtension, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  public sealed partial class TestNestedExtension : pb::IMessage<TestNestedExtension>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestNestedExtension> _parser = new pb::MessageParser<TestNestedExtension>(() => new TestNestedExtension());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestNestedExtension> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[11]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedExtension() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedExtension(TestNestedExtension other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedExtension Clone() {
      return new TestNestedExtension(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestNestedExtension);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestNestedExtension other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestNestedExtension other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestNestedExtension message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class OptionalGroup_extension : pb::IMessage<OptionalGroup_extension>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<OptionalGroup_extension> _parser = new pb::MessageParser<OptionalGroup_extension>(() => new OptionalGroup_extension());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<OptionalGroup_extension> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup_extension() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup_extension(OptionalGroup_extension other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup_extension Clone() {
          return new OptionalGroup_extension(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 17;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as OptionalGroup_extension);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(OptionalGroup_extension other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(136, 1);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 2 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(OptionalGroup_extension other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 132:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 136: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestNestedExtension message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Extensions {
      /// <summary>
      /// Check for bug where string extensions declared in tested scope did not
      /// compile.
      /// </summary>
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> Test =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(1002, pb::FieldCodec.ForString(8018, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("dGVzdA=="), 0, 4)));
      /// <summary>
      /// Used to test if generated extension name is correct when there are
      /// underscores.
      /// </summary>
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> NestedStringExtension =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(1003, pb::FieldCodec.ForString(8026, ""));
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Types.OptionalGroup_extension> OptionalGroupExtension =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Types.OptionalGroup_extension>(16, pb::FieldCodec.ForGroup(131, 132, global::Google.Protobuf.TestProtos.Proto2.TestNestedExtension.Types.OptionalGroup_extension.Parser));
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> OptionalForeignEnumExtension =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestGroupExtension, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>(22, pb::FieldCodec.ForEnum(176, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x, global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo));
    }
    #endregion

  }

  /// <summary>
  /// We have separate messages for testing required fields because it's
  /// annoying to have to fill in required fields in TestProto in order to
  /// do anything with it.  Note that we don't need to test every type of
  /// required filed because the code output is basically identical to
  /// optional fields for all types.
  /// </summary>
  public sealed partial class TestRequired : pb::IMessage<TestRequired>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRequired> _parser = new pb::MessageParser<TestRequired>(() => new TestRequired());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    private int _hasBits1;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRequired> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[12]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequired() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequired(TestRequired other) : this() {
      _hasBits0 = other._hasBits0;
      _hasBits1 = other._hasBits1;
      a_ = other.a_;
      dummy2_ = other.dummy2_;
      b_ = other.b_;
      dummy4_ = other.dummy4_;
      dummy5_ = other.dummy5_;
      dummy6_ = other.dummy6_;
      dummy7_ = other.dummy7_;
      dummy8_ = other.dummy8_;
      dummy9_ = other.dummy9_;
      dummy10_ = other.dummy10_;
      dummy11_ = other.dummy11_;
      dummy12_ = other.dummy12_;
      dummy13_ = other.dummy13_;
      dummy14_ = other.dummy14_;
      dummy15_ = other.dummy15_;
      dummy16_ = other.dummy16_;
      dummy17_ = other.dummy17_;
      dummy18_ = other.dummy18_;
      dummy19_ = other.dummy19_;
      dummy20_ = other.dummy20_;
      dummy21_ = other.dummy21_;
      dummy22_ = other.dummy22_;
      dummy23_ = other.dummy23_;
      dummy24_ = other.dummy24_;
      dummy25_ = other.dummy25_;
      dummy26_ = other.dummy26_;
      dummy27_ = other.dummy27_;
      dummy28_ = other.dummy28_;
      dummy29_ = other.dummy29_;
      dummy30_ = other.dummy30_;
      dummy31_ = other.dummy31_;
      dummy32_ = other.dummy32_;
      c_ = other.c_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequired Clone() {
      return new TestRequired(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private readonly static int ADefaultValue = 0;

    private int a_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int A {
      get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
      set {
        _hasBits0 |= 1;
        a_ = value;
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "dummy2" field.</summary>
    public const int Dummy2FieldNumber = 2;
    private readonly static int Dummy2DefaultValue = 0;

    private int dummy2_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy2 {
      get { if ((_hasBits0 & 2) != 0) { return dummy2_; } else { return Dummy2DefaultValue; } }
      set {
        _hasBits0 |= 2;
        dummy2_ = value;
      }
    }
    /// <summary>Gets whether the "dummy2" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy2 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "dummy2" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy2() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "b" field.</summary>
    public const int BFieldNumber = 3;
    private readonly static int BDefaultValue = 0;

    private int b_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int B {
      get { if ((_hasBits0 & 4) != 0) { return b_; } else { return BDefaultValue; } }
      set {
        _hasBits0 |= 4;
        b_ = value;
      }
    }
    /// <summary>Gets whether the "b" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasB {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "b" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearB() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "dummy4" field.</summary>
    public const int Dummy4FieldNumber = 4;
    private readonly static int Dummy4DefaultValue = 0;

    private int dummy4_;
    /// <summary>
    /// Pad the field count to 32 so that we can test that IsInitialized()
    /// properly checks multiple elements of has_bits_.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy4 {
      get { if ((_hasBits0 & 8) != 0) { return dummy4_; } else { return Dummy4DefaultValue; } }
      set {
        _hasBits0 |= 8;
        dummy4_ = value;
      }
    }
    /// <summary>Gets whether the "dummy4" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy4 {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "dummy4" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy4() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "dummy5" field.</summary>
    public const int Dummy5FieldNumber = 5;
    private readonly static int Dummy5DefaultValue = 0;

    private int dummy5_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy5 {
      get { if ((_hasBits0 & 16) != 0) { return dummy5_; } else { return Dummy5DefaultValue; } }
      set {
        _hasBits0 |= 16;
        dummy5_ = value;
      }
    }
    /// <summary>Gets whether the "dummy5" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy5 {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "dummy5" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy5() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "dummy6" field.</summary>
    public const int Dummy6FieldNumber = 6;
    private readonly static int Dummy6DefaultValue = 0;

    private int dummy6_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy6 {
      get { if ((_hasBits0 & 32) != 0) { return dummy6_; } else { return Dummy6DefaultValue; } }
      set {
        _hasBits0 |= 32;
        dummy6_ = value;
      }
    }
    /// <summary>Gets whether the "dummy6" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy6 {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "dummy6" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy6() {
      _hasBits0 &= ~32;
    }

    /// <summary>Field number for the "dummy7" field.</summary>
    public const int Dummy7FieldNumber = 7;
    private readonly static int Dummy7DefaultValue = 0;

    private int dummy7_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy7 {
      get { if ((_hasBits0 & 64) != 0) { return dummy7_; } else { return Dummy7DefaultValue; } }
      set {
        _hasBits0 |= 64;
        dummy7_ = value;
      }
    }
    /// <summary>Gets whether the "dummy7" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy7 {
      get { return (_hasBits0 & 64) != 0; }
    }
    /// <summary>Clears the value of the "dummy7" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy7() {
      _hasBits0 &= ~64;
    }

    /// <summary>Field number for the "dummy8" field.</summary>
    public const int Dummy8FieldNumber = 8;
    private readonly static int Dummy8DefaultValue = 0;

    private int dummy8_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy8 {
      get { if ((_hasBits0 & 128) != 0) { return dummy8_; } else { return Dummy8DefaultValue; } }
      set {
        _hasBits0 |= 128;
        dummy8_ = value;
      }
    }
    /// <summary>Gets whether the "dummy8" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy8 {
      get { return (_hasBits0 & 128) != 0; }
    }
    /// <summary>Clears the value of the "dummy8" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy8() {
      _hasBits0 &= ~128;
    }

    /// <summary>Field number for the "dummy9" field.</summary>
    public const int Dummy9FieldNumber = 9;
    private readonly static int Dummy9DefaultValue = 0;

    private int dummy9_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy9 {
      get { if ((_hasBits0 & 256) != 0) { return dummy9_; } else { return Dummy9DefaultValue; } }
      set {
        _hasBits0 |= 256;
        dummy9_ = value;
      }
    }
    /// <summary>Gets whether the "dummy9" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy9 {
      get { return (_hasBits0 & 256) != 0; }
    }
    /// <summary>Clears the value of the "dummy9" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy9() {
      _hasBits0 &= ~256;
    }

    /// <summary>Field number for the "dummy10" field.</summary>
    public const int Dummy10FieldNumber = 10;
    private readonly static int Dummy10DefaultValue = 0;

    private int dummy10_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy10 {
      get { if ((_hasBits0 & 512) != 0) { return dummy10_; } else { return Dummy10DefaultValue; } }
      set {
        _hasBits0 |= 512;
        dummy10_ = value;
      }
    }
    /// <summary>Gets whether the "dummy10" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy10 {
      get { return (_hasBits0 & 512) != 0; }
    }
    /// <summary>Clears the value of the "dummy10" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy10() {
      _hasBits0 &= ~512;
    }

    /// <summary>Field number for the "dummy11" field.</summary>
    public const int Dummy11FieldNumber = 11;
    private readonly static int Dummy11DefaultValue = 0;

    private int dummy11_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy11 {
      get { if ((_hasBits0 & 1024) != 0) { return dummy11_; } else { return Dummy11DefaultValue; } }
      set {
        _hasBits0 |= 1024;
        dummy11_ = value;
      }
    }
    /// <summary>Gets whether the "dummy11" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy11 {
      get { return (_hasBits0 & 1024) != 0; }
    }
    /// <summary>Clears the value of the "dummy11" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy11() {
      _hasBits0 &= ~1024;
    }

    /// <summary>Field number for the "dummy12" field.</summary>
    public const int Dummy12FieldNumber = 12;
    private readonly static int Dummy12DefaultValue = 0;

    private int dummy12_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy12 {
      get { if ((_hasBits0 & 2048) != 0) { return dummy12_; } else { return Dummy12DefaultValue; } }
      set {
        _hasBits0 |= 2048;
        dummy12_ = value;
      }
    }
    /// <summary>Gets whether the "dummy12" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy12 {
      get { return (_hasBits0 & 2048) != 0; }
    }
    /// <summary>Clears the value of the "dummy12" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy12() {
      _hasBits0 &= ~2048;
    }

    /// <summary>Field number for the "dummy13" field.</summary>
    public const int Dummy13FieldNumber = 13;
    private readonly static int Dummy13DefaultValue = 0;

    private int dummy13_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy13 {
      get { if ((_hasBits0 & 4096) != 0) { return dummy13_; } else { return Dummy13DefaultValue; } }
      set {
        _hasBits0 |= 4096;
        dummy13_ = value;
      }
    }
    /// <summary>Gets whether the "dummy13" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy13 {
      get { return (_hasBits0 & 4096) != 0; }
    }
    /// <summary>Clears the value of the "dummy13" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy13() {
      _hasBits0 &= ~4096;
    }

    /// <summary>Field number for the "dummy14" field.</summary>
    public const int Dummy14FieldNumber = 14;
    private readonly static int Dummy14DefaultValue = 0;

    private int dummy14_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy14 {
      get { if ((_hasBits0 & 8192) != 0) { return dummy14_; } else { return Dummy14DefaultValue; } }
      set {
        _hasBits0 |= 8192;
        dummy14_ = value;
      }
    }
    /// <summary>Gets whether the "dummy14" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy14 {
      get { return (_hasBits0 & 8192) != 0; }
    }
    /// <summary>Clears the value of the "dummy14" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy14() {
      _hasBits0 &= ~8192;
    }

    /// <summary>Field number for the "dummy15" field.</summary>
    public const int Dummy15FieldNumber = 15;
    private readonly static int Dummy15DefaultValue = 0;

    private int dummy15_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy15 {
      get { if ((_hasBits0 & 16384) != 0) { return dummy15_; } else { return Dummy15DefaultValue; } }
      set {
        _hasBits0 |= 16384;
        dummy15_ = value;
      }
    }
    /// <summary>Gets whether the "dummy15" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy15 {
      get { return (_hasBits0 & 16384) != 0; }
    }
    /// <summary>Clears the value of the "dummy15" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy15() {
      _hasBits0 &= ~16384;
    }

    /// <summary>Field number for the "dummy16" field.</summary>
    public const int Dummy16FieldNumber = 16;
    private readonly static int Dummy16DefaultValue = 0;

    private int dummy16_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy16 {
      get { if ((_hasBits0 & 32768) != 0) { return dummy16_; } else { return Dummy16DefaultValue; } }
      set {
        _hasBits0 |= 32768;
        dummy16_ = value;
      }
    }
    /// <summary>Gets whether the "dummy16" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy16 {
      get { return (_hasBits0 & 32768) != 0; }
    }
    /// <summary>Clears the value of the "dummy16" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy16() {
      _hasBits0 &= ~32768;
    }

    /// <summary>Field number for the "dummy17" field.</summary>
    public const int Dummy17FieldNumber = 17;
    private readonly static int Dummy17DefaultValue = 0;

    private int dummy17_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy17 {
      get { if ((_hasBits0 & 65536) != 0) { return dummy17_; } else { return Dummy17DefaultValue; } }
      set {
        _hasBits0 |= 65536;
        dummy17_ = value;
      }
    }
    /// <summary>Gets whether the "dummy17" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy17 {
      get { return (_hasBits0 & 65536) != 0; }
    }
    /// <summary>Clears the value of the "dummy17" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy17() {
      _hasBits0 &= ~65536;
    }

    /// <summary>Field number for the "dummy18" field.</summary>
    public const int Dummy18FieldNumber = 18;
    private readonly static int Dummy18DefaultValue = 0;

    private int dummy18_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy18 {
      get { if ((_hasBits0 & 131072) != 0) { return dummy18_; } else { return Dummy18DefaultValue; } }
      set {
        _hasBits0 |= 131072;
        dummy18_ = value;
      }
    }
    /// <summary>Gets whether the "dummy18" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy18 {
      get { return (_hasBits0 & 131072) != 0; }
    }
    /// <summary>Clears the value of the "dummy18" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy18() {
      _hasBits0 &= ~131072;
    }

    /// <summary>Field number for the "dummy19" field.</summary>
    public const int Dummy19FieldNumber = 19;
    private readonly static int Dummy19DefaultValue = 0;

    private int dummy19_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy19 {
      get { if ((_hasBits0 & 262144) != 0) { return dummy19_; } else { return Dummy19DefaultValue; } }
      set {
        _hasBits0 |= 262144;
        dummy19_ = value;
      }
    }
    /// <summary>Gets whether the "dummy19" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy19 {
      get { return (_hasBits0 & 262144) != 0; }
    }
    /// <summary>Clears the value of the "dummy19" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy19() {
      _hasBits0 &= ~262144;
    }

    /// <summary>Field number for the "dummy20" field.</summary>
    public const int Dummy20FieldNumber = 20;
    private readonly static int Dummy20DefaultValue = 0;

    private int dummy20_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy20 {
      get { if ((_hasBits0 & 524288) != 0) { return dummy20_; } else { return Dummy20DefaultValue; } }
      set {
        _hasBits0 |= 524288;
        dummy20_ = value;
      }
    }
    /// <summary>Gets whether the "dummy20" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy20 {
      get { return (_hasBits0 & 524288) != 0; }
    }
    /// <summary>Clears the value of the "dummy20" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy20() {
      _hasBits0 &= ~524288;
    }

    /// <summary>Field number for the "dummy21" field.</summary>
    public const int Dummy21FieldNumber = 21;
    private readonly static int Dummy21DefaultValue = 0;

    private int dummy21_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy21 {
      get { if ((_hasBits0 & 1048576) != 0) { return dummy21_; } else { return Dummy21DefaultValue; } }
      set {
        _hasBits0 |= 1048576;
        dummy21_ = value;
      }
    }
    /// <summary>Gets whether the "dummy21" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy21 {
      get { return (_hasBits0 & 1048576) != 0; }
    }
    /// <summary>Clears the value of the "dummy21" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy21() {
      _hasBits0 &= ~1048576;
    }

    /// <summary>Field number for the "dummy22" field.</summary>
    public const int Dummy22FieldNumber = 22;
    private readonly static int Dummy22DefaultValue = 0;

    private int dummy22_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy22 {
      get { if ((_hasBits0 & 2097152) != 0) { return dummy22_; } else { return Dummy22DefaultValue; } }
      set {
        _hasBits0 |= 2097152;
        dummy22_ = value;
      }
    }
    /// <summary>Gets whether the "dummy22" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy22 {
      get { return (_hasBits0 & 2097152) != 0; }
    }
    /// <summary>Clears the value of the "dummy22" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy22() {
      _hasBits0 &= ~2097152;
    }

    /// <summary>Field number for the "dummy23" field.</summary>
    public const int Dummy23FieldNumber = 23;
    private readonly static int Dummy23DefaultValue = 0;

    private int dummy23_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy23 {
      get { if ((_hasBits0 & 4194304) != 0) { return dummy23_; } else { return Dummy23DefaultValue; } }
      set {
        _hasBits0 |= 4194304;
        dummy23_ = value;
      }
    }
    /// <summary>Gets whether the "dummy23" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy23 {
      get { return (_hasBits0 & 4194304) != 0; }
    }
    /// <summary>Clears the value of the "dummy23" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy23() {
      _hasBits0 &= ~4194304;
    }

    /// <summary>Field number for the "dummy24" field.</summary>
    public const int Dummy24FieldNumber = 24;
    private readonly static int Dummy24DefaultValue = 0;

    private int dummy24_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy24 {
      get { if ((_hasBits0 & 8388608) != 0) { return dummy24_; } else { return Dummy24DefaultValue; } }
      set {
        _hasBits0 |= 8388608;
        dummy24_ = value;
      }
    }
    /// <summary>Gets whether the "dummy24" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy24 {
      get { return (_hasBits0 & 8388608) != 0; }
    }
    /// <summary>Clears the value of the "dummy24" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy24() {
      _hasBits0 &= ~8388608;
    }

    /// <summary>Field number for the "dummy25" field.</summary>
    public const int Dummy25FieldNumber = 25;
    private readonly static int Dummy25DefaultValue = 0;

    private int dummy25_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy25 {
      get { if ((_hasBits0 & 16777216) != 0) { return dummy25_; } else { return Dummy25DefaultValue; } }
      set {
        _hasBits0 |= 16777216;
        dummy25_ = value;
      }
    }
    /// <summary>Gets whether the "dummy25" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy25 {
      get { return (_hasBits0 & 16777216) != 0; }
    }
    /// <summary>Clears the value of the "dummy25" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy25() {
      _hasBits0 &= ~16777216;
    }

    /// <summary>Field number for the "dummy26" field.</summary>
    public const int Dummy26FieldNumber = 26;
    private readonly static int Dummy26DefaultValue = 0;

    private int dummy26_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy26 {
      get { if ((_hasBits0 & 33554432) != 0) { return dummy26_; } else { return Dummy26DefaultValue; } }
      set {
        _hasBits0 |= 33554432;
        dummy26_ = value;
      }
    }
    /// <summary>Gets whether the "dummy26" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy26 {
      get { return (_hasBits0 & 33554432) != 0; }
    }
    /// <summary>Clears the value of the "dummy26" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy26() {
      _hasBits0 &= ~33554432;
    }

    /// <summary>Field number for the "dummy27" field.</summary>
    public const int Dummy27FieldNumber = 27;
    private readonly static int Dummy27DefaultValue = 0;

    private int dummy27_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy27 {
      get { if ((_hasBits0 & 67108864) != 0) { return dummy27_; } else { return Dummy27DefaultValue; } }
      set {
        _hasBits0 |= 67108864;
        dummy27_ = value;
      }
    }
    /// <summary>Gets whether the "dummy27" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy27 {
      get { return (_hasBits0 & 67108864) != 0; }
    }
    /// <summary>Clears the value of the "dummy27" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy27() {
      _hasBits0 &= ~67108864;
    }

    /// <summary>Field number for the "dummy28" field.</summary>
    public const int Dummy28FieldNumber = 28;
    private readonly static int Dummy28DefaultValue = 0;

    private int dummy28_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy28 {
      get { if ((_hasBits0 & 134217728) != 0) { return dummy28_; } else { return Dummy28DefaultValue; } }
      set {
        _hasBits0 |= 134217728;
        dummy28_ = value;
      }
    }
    /// <summary>Gets whether the "dummy28" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy28 {
      get { return (_hasBits0 & 134217728) != 0; }
    }
    /// <summary>Clears the value of the "dummy28" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy28() {
      _hasBits0 &= ~134217728;
    }

    /// <summary>Field number for the "dummy29" field.</summary>
    public const int Dummy29FieldNumber = 29;
    private readonly static int Dummy29DefaultValue = 0;

    private int dummy29_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy29 {
      get { if ((_hasBits0 & 268435456) != 0) { return dummy29_; } else { return Dummy29DefaultValue; } }
      set {
        _hasBits0 |= 268435456;
        dummy29_ = value;
      }
    }
    /// <summary>Gets whether the "dummy29" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy29 {
      get { return (_hasBits0 & 268435456) != 0; }
    }
    /// <summary>Clears the value of the "dummy29" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy29() {
      _hasBits0 &= ~268435456;
    }

    /// <summary>Field number for the "dummy30" field.</summary>
    public const int Dummy30FieldNumber = 30;
    private readonly static int Dummy30DefaultValue = 0;

    private int dummy30_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy30 {
      get { if ((_hasBits0 & 536870912) != 0) { return dummy30_; } else { return Dummy30DefaultValue; } }
      set {
        _hasBits0 |= 536870912;
        dummy30_ = value;
      }
    }
    /// <summary>Gets whether the "dummy30" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy30 {
      get { return (_hasBits0 & 536870912) != 0; }
    }
    /// <summary>Clears the value of the "dummy30" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy30() {
      _hasBits0 &= ~536870912;
    }

    /// <summary>Field number for the "dummy31" field.</summary>
    public const int Dummy31FieldNumber = 31;
    private readonly static int Dummy31DefaultValue = 0;

    private int dummy31_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy31 {
      get { if ((_hasBits0 & 1073741824) != 0) { return dummy31_; } else { return Dummy31DefaultValue; } }
      set {
        _hasBits0 |= 1073741824;
        dummy31_ = value;
      }
    }
    /// <summary>Gets whether the "dummy31" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy31 {
      get { return (_hasBits0 & 1073741824) != 0; }
    }
    /// <summary>Clears the value of the "dummy31" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy31() {
      _hasBits0 &= ~1073741824;
    }

    /// <summary>Field number for the "dummy32" field.</summary>
    public const int Dummy32FieldNumber = 32;
    private readonly static int Dummy32DefaultValue = 0;

    private int dummy32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy32 {
      get { if ((_hasBits0 & -2147483648) != 0) { return dummy32_; } else { return Dummy32DefaultValue; } }
      set {
        _hasBits0 |= -2147483648;
        dummy32_ = value;
      }
    }
    /// <summary>Gets whether the "dummy32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy32 {
      get { return (_hasBits0 & -2147483648) != 0; }
    }
    /// <summary>Clears the value of the "dummy32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy32() {
      _hasBits0 &= ~-2147483648;
    }

    /// <summary>Field number for the "c" field.</summary>
    public const int CFieldNumber = 33;
    private readonly static int CDefaultValue = 0;

    private int c_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int C {
      get { if ((_hasBits1 & 1) != 0) { return c_; } else { return CDefaultValue; } }
      set {
        _hasBits1 |= 1;
        c_ = value;
      }
    }
    /// <summary>Gets whether the "c" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasC {
      get { return (_hasBits1 & 1) != 0; }
    }
    /// <summary>Clears the value of the "c" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearC() {
      _hasBits1 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRequired);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRequired other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      if (Dummy2 != other.Dummy2) return false;
      if (B != other.B) return false;
      if (Dummy4 != other.Dummy4) return false;
      if (Dummy5 != other.Dummy5) return false;
      if (Dummy6 != other.Dummy6) return false;
      if (Dummy7 != other.Dummy7) return false;
      if (Dummy8 != other.Dummy8) return false;
      if (Dummy9 != other.Dummy9) return false;
      if (Dummy10 != other.Dummy10) return false;
      if (Dummy11 != other.Dummy11) return false;
      if (Dummy12 != other.Dummy12) return false;
      if (Dummy13 != other.Dummy13) return false;
      if (Dummy14 != other.Dummy14) return false;
      if (Dummy15 != other.Dummy15) return false;
      if (Dummy16 != other.Dummy16) return false;
      if (Dummy17 != other.Dummy17) return false;
      if (Dummy18 != other.Dummy18) return false;
      if (Dummy19 != other.Dummy19) return false;
      if (Dummy20 != other.Dummy20) return false;
      if (Dummy21 != other.Dummy21) return false;
      if (Dummy22 != other.Dummy22) return false;
      if (Dummy23 != other.Dummy23) return false;
      if (Dummy24 != other.Dummy24) return false;
      if (Dummy25 != other.Dummy25) return false;
      if (Dummy26 != other.Dummy26) return false;
      if (Dummy27 != other.Dummy27) return false;
      if (Dummy28 != other.Dummy28) return false;
      if (Dummy29 != other.Dummy29) return false;
      if (Dummy30 != other.Dummy30) return false;
      if (Dummy31 != other.Dummy31) return false;
      if (Dummy32 != other.Dummy32) return false;
      if (C != other.C) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (HasDummy2) hash ^= Dummy2.GetHashCode();
      if (HasB) hash ^= B.GetHashCode();
      if (HasDummy4) hash ^= Dummy4.GetHashCode();
      if (HasDummy5) hash ^= Dummy5.GetHashCode();
      if (HasDummy6) hash ^= Dummy6.GetHashCode();
      if (HasDummy7) hash ^= Dummy7.GetHashCode();
      if (HasDummy8) hash ^= Dummy8.GetHashCode();
      if (HasDummy9) hash ^= Dummy9.GetHashCode();
      if (HasDummy10) hash ^= Dummy10.GetHashCode();
      if (HasDummy11) hash ^= Dummy11.GetHashCode();
      if (HasDummy12) hash ^= Dummy12.GetHashCode();
      if (HasDummy13) hash ^= Dummy13.GetHashCode();
      if (HasDummy14) hash ^= Dummy14.GetHashCode();
      if (HasDummy15) hash ^= Dummy15.GetHashCode();
      if (HasDummy16) hash ^= Dummy16.GetHashCode();
      if (HasDummy17) hash ^= Dummy17.GetHashCode();
      if (HasDummy18) hash ^= Dummy18.GetHashCode();
      if (HasDummy19) hash ^= Dummy19.GetHashCode();
      if (HasDummy20) hash ^= Dummy20.GetHashCode();
      if (HasDummy21) hash ^= Dummy21.GetHashCode();
      if (HasDummy22) hash ^= Dummy22.GetHashCode();
      if (HasDummy23) hash ^= Dummy23.GetHashCode();
      if (HasDummy24) hash ^= Dummy24.GetHashCode();
      if (HasDummy25) hash ^= Dummy25.GetHashCode();
      if (HasDummy26) hash ^= Dummy26.GetHashCode();
      if (HasDummy27) hash ^= Dummy27.GetHashCode();
      if (HasDummy28) hash ^= Dummy28.GetHashCode();
      if (HasDummy29) hash ^= Dummy29.GetHashCode();
      if (HasDummy30) hash ^= Dummy30.GetHashCode();
      if (HasDummy31) hash ^= Dummy31.GetHashCode();
      if (HasDummy32) hash ^= Dummy32.GetHashCode();
      if (HasC) hash ^= C.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasDummy2) {
        output.WriteRawTag(16);
        output.WriteInt32(Dummy2);
      }
      if (HasB) {
        output.WriteRawTag(24);
        output.WriteInt32(B);
      }
      if (HasDummy4) {
        output.WriteRawTag(32);
        output.WriteInt32(Dummy4);
      }
      if (HasDummy5) {
        output.WriteRawTag(40);
        output.WriteInt32(Dummy5);
      }
      if (HasDummy6) {
        output.WriteRawTag(48);
        output.WriteInt32(Dummy6);
      }
      if (HasDummy7) {
        output.WriteRawTag(56);
        output.WriteInt32(Dummy7);
      }
      if (HasDummy8) {
        output.WriteRawTag(64);
        output.WriteInt32(Dummy8);
      }
      if (HasDummy9) {
        output.WriteRawTag(72);
        output.WriteInt32(Dummy9);
      }
      if (HasDummy10) {
        output.WriteRawTag(80);
        output.WriteInt32(Dummy10);
      }
      if (HasDummy11) {
        output.WriteRawTag(88);
        output.WriteInt32(Dummy11);
      }
      if (HasDummy12) {
        output.WriteRawTag(96);
        output.WriteInt32(Dummy12);
      }
      if (HasDummy13) {
        output.WriteRawTag(104);
        output.WriteInt32(Dummy13);
      }
      if (HasDummy14) {
        output.WriteRawTag(112);
        output.WriteInt32(Dummy14);
      }
      if (HasDummy15) {
        output.WriteRawTag(120);
        output.WriteInt32(Dummy15);
      }
      if (HasDummy16) {
        output.WriteRawTag(128, 1);
        output.WriteInt32(Dummy16);
      }
      if (HasDummy17) {
        output.WriteRawTag(136, 1);
        output.WriteInt32(Dummy17);
      }
      if (HasDummy18) {
        output.WriteRawTag(144, 1);
        output.WriteInt32(Dummy18);
      }
      if (HasDummy19) {
        output.WriteRawTag(152, 1);
        output.WriteInt32(Dummy19);
      }
      if (HasDummy20) {
        output.WriteRawTag(160, 1);
        output.WriteInt32(Dummy20);
      }
      if (HasDummy21) {
        output.WriteRawTag(168, 1);
        output.WriteInt32(Dummy21);
      }
      if (HasDummy22) {
        output.WriteRawTag(176, 1);
        output.WriteInt32(Dummy22);
      }
      if (HasDummy23) {
        output.WriteRawTag(184, 1);
        output.WriteInt32(Dummy23);
      }
      if (HasDummy24) {
        output.WriteRawTag(192, 1);
        output.WriteInt32(Dummy24);
      }
      if (HasDummy25) {
        output.WriteRawTag(200, 1);
        output.WriteInt32(Dummy25);
      }
      if (HasDummy26) {
        output.WriteRawTag(208, 1);
        output.WriteInt32(Dummy26);
      }
      if (HasDummy27) {
        output.WriteRawTag(216, 1);
        output.WriteInt32(Dummy27);
      }
      if (HasDummy28) {
        output.WriteRawTag(224, 1);
        output.WriteInt32(Dummy28);
      }
      if (HasDummy29) {
        output.WriteRawTag(232, 1);
        output.WriteInt32(Dummy29);
      }
      if (HasDummy30) {
        output.WriteRawTag(240, 1);
        output.WriteInt32(Dummy30);
      }
      if (HasDummy31) {
        output.WriteRawTag(248, 1);
        output.WriteInt32(Dummy31);
      }
      if (HasDummy32) {
        output.WriteRawTag(128, 2);
        output.WriteInt32(Dummy32);
      }
      if (HasC) {
        output.WriteRawTag(136, 2);
        output.WriteInt32(C);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasDummy2) {
        output.WriteRawTag(16);
        output.WriteInt32(Dummy2);
      }
      if (HasB) {
        output.WriteRawTag(24);
        output.WriteInt32(B);
      }
      if (HasDummy4) {
        output.WriteRawTag(32);
        output.WriteInt32(Dummy4);
      }
      if (HasDummy5) {
        output.WriteRawTag(40);
        output.WriteInt32(Dummy5);
      }
      if (HasDummy6) {
        output.WriteRawTag(48);
        output.WriteInt32(Dummy6);
      }
      if (HasDummy7) {
        output.WriteRawTag(56);
        output.WriteInt32(Dummy7);
      }
      if (HasDummy8) {
        output.WriteRawTag(64);
        output.WriteInt32(Dummy8);
      }
      if (HasDummy9) {
        output.WriteRawTag(72);
        output.WriteInt32(Dummy9);
      }
      if (HasDummy10) {
        output.WriteRawTag(80);
        output.WriteInt32(Dummy10);
      }
      if (HasDummy11) {
        output.WriteRawTag(88);
        output.WriteInt32(Dummy11);
      }
      if (HasDummy12) {
        output.WriteRawTag(96);
        output.WriteInt32(Dummy12);
      }
      if (HasDummy13) {
        output.WriteRawTag(104);
        output.WriteInt32(Dummy13);
      }
      if (HasDummy14) {
        output.WriteRawTag(112);
        output.WriteInt32(Dummy14);
      }
      if (HasDummy15) {
        output.WriteRawTag(120);
        output.WriteInt32(Dummy15);
      }
      if (HasDummy16) {
        output.WriteRawTag(128, 1);
        output.WriteInt32(Dummy16);
      }
      if (HasDummy17) {
        output.WriteRawTag(136, 1);
        output.WriteInt32(Dummy17);
      }
      if (HasDummy18) {
        output.WriteRawTag(144, 1);
        output.WriteInt32(Dummy18);
      }
      if (HasDummy19) {
        output.WriteRawTag(152, 1);
        output.WriteInt32(Dummy19);
      }
      if (HasDummy20) {
        output.WriteRawTag(160, 1);
        output.WriteInt32(Dummy20);
      }
      if (HasDummy21) {
        output.WriteRawTag(168, 1);
        output.WriteInt32(Dummy21);
      }
      if (HasDummy22) {
        output.WriteRawTag(176, 1);
        output.WriteInt32(Dummy22);
      }
      if (HasDummy23) {
        output.WriteRawTag(184, 1);
        output.WriteInt32(Dummy23);
      }
      if (HasDummy24) {
        output.WriteRawTag(192, 1);
        output.WriteInt32(Dummy24);
      }
      if (HasDummy25) {
        output.WriteRawTag(200, 1);
        output.WriteInt32(Dummy25);
      }
      if (HasDummy26) {
        output.WriteRawTag(208, 1);
        output.WriteInt32(Dummy26);
      }
      if (HasDummy27) {
        output.WriteRawTag(216, 1);
        output.WriteInt32(Dummy27);
      }
      if (HasDummy28) {
        output.WriteRawTag(224, 1);
        output.WriteInt32(Dummy28);
      }
      if (HasDummy29) {
        output.WriteRawTag(232, 1);
        output.WriteInt32(Dummy29);
      }
      if (HasDummy30) {
        output.WriteRawTag(240, 1);
        output.WriteInt32(Dummy30);
      }
      if (HasDummy31) {
        output.WriteRawTag(248, 1);
        output.WriteInt32(Dummy31);
      }
      if (HasDummy32) {
        output.WriteRawTag(128, 2);
        output.WriteInt32(Dummy32);
      }
      if (HasC) {
        output.WriteRawTag(136, 2);
        output.WriteInt32(C);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
      }
      if (HasDummy2) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy2);
      }
      if (HasB) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(B);
      }
      if (HasDummy4) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy4);
      }
      if (HasDummy5) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy5);
      }
      if (HasDummy6) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy6);
      }
      if (HasDummy7) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy7);
      }
      if (HasDummy8) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy8);
      }
      if (HasDummy9) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy9);
      }
      if (HasDummy10) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy10);
      }
      if (HasDummy11) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy11);
      }
      if (HasDummy12) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy12);
      }
      if (HasDummy13) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy13);
      }
      if (HasDummy14) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy14);
      }
      if (HasDummy15) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy15);
      }
      if (HasDummy16) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy16);
      }
      if (HasDummy17) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy17);
      }
      if (HasDummy18) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy18);
      }
      if (HasDummy19) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy19);
      }
      if (HasDummy20) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy20);
      }
      if (HasDummy21) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy21);
      }
      if (HasDummy22) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy22);
      }
      if (HasDummy23) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy23);
      }
      if (HasDummy24) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy24);
      }
      if (HasDummy25) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy25);
      }
      if (HasDummy26) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy26);
      }
      if (HasDummy27) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy27);
      }
      if (HasDummy28) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy28);
      }
      if (HasDummy29) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy29);
      }
      if (HasDummy30) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy30);
      }
      if (HasDummy31) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy31);
      }
      if (HasDummy32) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(Dummy32);
      }
      if (HasC) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(C);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRequired other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      if (other.HasDummy2) {
        Dummy2 = other.Dummy2;
      }
      if (other.HasB) {
        B = other.B;
      }
      if (other.HasDummy4) {
        Dummy4 = other.Dummy4;
      }
      if (other.HasDummy5) {
        Dummy5 = other.Dummy5;
      }
      if (other.HasDummy6) {
        Dummy6 = other.Dummy6;
      }
      if (other.HasDummy7) {
        Dummy7 = other.Dummy7;
      }
      if (other.HasDummy8) {
        Dummy8 = other.Dummy8;
      }
      if (other.HasDummy9) {
        Dummy9 = other.Dummy9;
      }
      if (other.HasDummy10) {
        Dummy10 = other.Dummy10;
      }
      if (other.HasDummy11) {
        Dummy11 = other.Dummy11;
      }
      if (other.HasDummy12) {
        Dummy12 = other.Dummy12;
      }
      if (other.HasDummy13) {
        Dummy13 = other.Dummy13;
      }
      if (other.HasDummy14) {
        Dummy14 = other.Dummy14;
      }
      if (other.HasDummy15) {
        Dummy15 = other.Dummy15;
      }
      if (other.HasDummy16) {
        Dummy16 = other.Dummy16;
      }
      if (other.HasDummy17) {
        Dummy17 = other.Dummy17;
      }
      if (other.HasDummy18) {
        Dummy18 = other.Dummy18;
      }
      if (other.HasDummy19) {
        Dummy19 = other.Dummy19;
      }
      if (other.HasDummy20) {
        Dummy20 = other.Dummy20;
      }
      if (other.HasDummy21) {
        Dummy21 = other.Dummy21;
      }
      if (other.HasDummy22) {
        Dummy22 = other.Dummy22;
      }
      if (other.HasDummy23) {
        Dummy23 = other.Dummy23;
      }
      if (other.HasDummy24) {
        Dummy24 = other.Dummy24;
      }
      if (other.HasDummy25) {
        Dummy25 = other.Dummy25;
      }
      if (other.HasDummy26) {
        Dummy26 = other.Dummy26;
      }
      if (other.HasDummy27) {
        Dummy27 = other.Dummy27;
      }
      if (other.HasDummy28) {
        Dummy28 = other.Dummy28;
      }
      if (other.HasDummy29) {
        Dummy29 = other.Dummy29;
      }
      if (other.HasDummy30) {
        Dummy30 = other.Dummy30;
      }
      if (other.HasDummy31) {
        Dummy31 = other.Dummy31;
      }
      if (other.HasDummy32) {
        Dummy32 = other.Dummy32;
      }
      if (other.HasC) {
        C = other.C;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 16: {
            Dummy2 = input.ReadInt32();
            break;
          }
          case 24: {
            B = input.ReadInt32();
            break;
          }
          case 32: {
            Dummy4 = input.ReadInt32();
            break;
          }
          case 40: {
            Dummy5 = input.ReadInt32();
            break;
          }
          case 48: {
            Dummy6 = input.ReadInt32();
            break;
          }
          case 56: {
            Dummy7 = input.ReadInt32();
            break;
          }
          case 64: {
            Dummy8 = input.ReadInt32();
            break;
          }
          case 72: {
            Dummy9 = input.ReadInt32();
            break;
          }
          case 80: {
            Dummy10 = input.ReadInt32();
            break;
          }
          case 88: {
            Dummy11 = input.ReadInt32();
            break;
          }
          case 96: {
            Dummy12 = input.ReadInt32();
            break;
          }
          case 104: {
            Dummy13 = input.ReadInt32();
            break;
          }
          case 112: {
            Dummy14 = input.ReadInt32();
            break;
          }
          case 120: {
            Dummy15 = input.ReadInt32();
            break;
          }
          case 128: {
            Dummy16 = input.ReadInt32();
            break;
          }
          case 136: {
            Dummy17 = input.ReadInt32();
            break;
          }
          case 144: {
            Dummy18 = input.ReadInt32();
            break;
          }
          case 152: {
            Dummy19 = input.ReadInt32();
            break;
          }
          case 160: {
            Dummy20 = input.ReadInt32();
            break;
          }
          case 168: {
            Dummy21 = input.ReadInt32();
            break;
          }
          case 176: {
            Dummy22 = input.ReadInt32();
            break;
          }
          case 184: {
            Dummy23 = input.ReadInt32();
            break;
          }
          case 192: {
            Dummy24 = input.ReadInt32();
            break;
          }
          case 200: {
            Dummy25 = input.ReadInt32();
            break;
          }
          case 208: {
            Dummy26 = input.ReadInt32();
            break;
          }
          case 216: {
            Dummy27 = input.ReadInt32();
            break;
          }
          case 224: {
            Dummy28 = input.ReadInt32();
            break;
          }
          case 232: {
            Dummy29 = input.ReadInt32();
            break;
          }
          case 240: {
            Dummy30 = input.ReadInt32();
            break;
          }
          case 248: {
            Dummy31 = input.ReadInt32();
            break;
          }
          case 256: {
            Dummy32 = input.ReadInt32();
            break;
          }
          case 264: {
            C = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 16: {
            Dummy2 = input.ReadInt32();
            break;
          }
          case 24: {
            B = input.ReadInt32();
            break;
          }
          case 32: {
            Dummy4 = input.ReadInt32();
            break;
          }
          case 40: {
            Dummy5 = input.ReadInt32();
            break;
          }
          case 48: {
            Dummy6 = input.ReadInt32();
            break;
          }
          case 56: {
            Dummy7 = input.ReadInt32();
            break;
          }
          case 64: {
            Dummy8 = input.ReadInt32();
            break;
          }
          case 72: {
            Dummy9 = input.ReadInt32();
            break;
          }
          case 80: {
            Dummy10 = input.ReadInt32();
            break;
          }
          case 88: {
            Dummy11 = input.ReadInt32();
            break;
          }
          case 96: {
            Dummy12 = input.ReadInt32();
            break;
          }
          case 104: {
            Dummy13 = input.ReadInt32();
            break;
          }
          case 112: {
            Dummy14 = input.ReadInt32();
            break;
          }
          case 120: {
            Dummy15 = input.ReadInt32();
            break;
          }
          case 128: {
            Dummy16 = input.ReadInt32();
            break;
          }
          case 136: {
            Dummy17 = input.ReadInt32();
            break;
          }
          case 144: {
            Dummy18 = input.ReadInt32();
            break;
          }
          case 152: {
            Dummy19 = input.ReadInt32();
            break;
          }
          case 160: {
            Dummy20 = input.ReadInt32();
            break;
          }
          case 168: {
            Dummy21 = input.ReadInt32();
            break;
          }
          case 176: {
            Dummy22 = input.ReadInt32();
            break;
          }
          case 184: {
            Dummy23 = input.ReadInt32();
            break;
          }
          case 192: {
            Dummy24 = input.ReadInt32();
            break;
          }
          case 200: {
            Dummy25 = input.ReadInt32();
            break;
          }
          case 208: {
            Dummy26 = input.ReadInt32();
            break;
          }
          case 216: {
            Dummy27 = input.ReadInt32();
            break;
          }
          case 224: {
            Dummy28 = input.ReadInt32();
            break;
          }
          case 232: {
            Dummy29 = input.ReadInt32();
            break;
          }
          case 240: {
            Dummy30 = input.ReadInt32();
            break;
          }
          case 248: {
            Dummy31 = input.ReadInt32();
            break;
          }
          case 256: {
            Dummy32 = input.ReadInt32();
            break;
          }
          case 264: {
            C = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestRequired message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Extensions {
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestRequired> Single =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestRequired>(1000, pb::FieldCodec.ForMessage(8002, global::Google.Protobuf.TestProtos.Proto2.TestRequired.Parser));
      public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestRequired> Multi =
        new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestRequired>(1001, pb::FieldCodec.ForMessage(8010, global::Google.Protobuf.TestProtos.Proto2.TestRequired.Parser));
    }
    #endregion

  }

  public sealed partial class TestRequiredForeign : pb::IMessage<TestRequiredForeign>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRequiredForeign> _parser = new pb::MessageParser<TestRequiredForeign>(() => new TestRequiredForeign());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRequiredForeign> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[13]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredForeign() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredForeign(TestRequiredForeign other) : this() {
      _hasBits0 = other._hasBits0;
      optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null;
      repeatedMessage_ = other.repeatedMessage_.Clone();
      dummy_ = other.dummy_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredForeign Clone() {
      return new TestRequiredForeign(this);
    }

    /// <summary>Field number for the "optional_message" field.</summary>
    public const int OptionalMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestRequired optionalMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestRequired OptionalMessage {
      get { return optionalMessage_; }
      set {
        optionalMessage_ = value;
      }
    }

    /// <summary>Field number for the "repeated_message" field.</summary>
    public const int RepeatedMessageFieldNumber = 2;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestRequired> _repeated_repeatedMessage_codec
        = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.Proto2.TestRequired.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired> repeatedMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired> RepeatedMessage {
      get { return repeatedMessage_; }
    }

    /// <summary>Field number for the "dummy" field.</summary>
    public const int DummyFieldNumber = 3;
    private readonly static int DummyDefaultValue = 0;

    private int dummy_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Dummy {
      get { if ((_hasBits0 & 1) != 0) { return dummy_; } else { return DummyDefaultValue; } }
      set {
        _hasBits0 |= 1;
        dummy_ = value;
      }
    }
    /// <summary>Gets whether the "dummy" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDummy {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "dummy" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDummy() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRequiredForeign);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRequiredForeign other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(OptionalMessage, other.OptionalMessage)) return false;
      if(!repeatedMessage_.Equals(other.repeatedMessage_)) return false;
      if (Dummy != other.Dummy) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode();
      hash ^= repeatedMessage_.GetHashCode();
      if (HasDummy) hash ^= Dummy.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (optionalMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalMessage);
      }
      repeatedMessage_.WriteTo(output, _repeated_repeatedMessage_codec);
      if (HasDummy) {
        output.WriteRawTag(24);
        output.WriteInt32(Dummy);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (optionalMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalMessage);
      }
      repeatedMessage_.WriteTo(ref output, _repeated_repeatedMessage_codec);
      if (HasDummy) {
        output.WriteRawTag(24);
        output.WriteInt32(Dummy);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (optionalMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage);
      }
      size += repeatedMessage_.CalculateSize(_repeated_repeatedMessage_codec);
      if (HasDummy) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Dummy);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRequiredForeign other) {
      if (other == null) {
        return;
      }
      if (other.optionalMessage_ != null) {
        if (optionalMessage_ == null) {
          OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
        }
        OptionalMessage.MergeFrom(other.OptionalMessage);
      }
      repeatedMessage_.Add(other.repeatedMessage_);
      if (other.HasDummy) {
        Dummy = other.Dummy;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 18: {
            repeatedMessage_.AddEntriesFrom(input, _repeated_repeatedMessage_codec);
            break;
          }
          case 24: {
            Dummy = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 18: {
            repeatedMessage_.AddEntriesFrom(ref input, _repeated_repeatedMessage_codec);
            break;
          }
          case 24: {
            Dummy = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestRequiredMessage : pb::IMessage<TestRequiredMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRequiredMessage> _parser = new pb::MessageParser<TestRequiredMessage>(() => new TestRequiredMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRequiredMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[14]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMessage(TestRequiredMessage other) : this() {
      optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null;
      repeatedMessage_ = other.repeatedMessage_.Clone();
      requiredMessage_ = other.requiredMessage_ != null ? other.requiredMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMessage Clone() {
      return new TestRequiredMessage(this);
    }

    /// <summary>Field number for the "optional_message" field.</summary>
    public const int OptionalMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestRequired optionalMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestRequired OptionalMessage {
      get { return optionalMessage_; }
      set {
        optionalMessage_ = value;
      }
    }

    /// <summary>Field number for the "repeated_message" field.</summary>
    public const int RepeatedMessageFieldNumber = 2;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestRequired> _repeated_repeatedMessage_codec
        = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.Proto2.TestRequired.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired> repeatedMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestRequired> RepeatedMessage {
      get { return repeatedMessage_; }
    }

    /// <summary>Field number for the "required_message" field.</summary>
    public const int RequiredMessageFieldNumber = 3;
    private global::Google.Protobuf.TestProtos.Proto2.TestRequired requiredMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestRequired RequiredMessage {
      get { return requiredMessage_; }
      set {
        requiredMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRequiredMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRequiredMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(OptionalMessage, other.OptionalMessage)) return false;
      if(!repeatedMessage_.Equals(other.repeatedMessage_)) return false;
      if (!object.Equals(RequiredMessage, other.RequiredMessage)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode();
      hash ^= repeatedMessage_.GetHashCode();
      if (requiredMessage_ != null) hash ^= RequiredMessage.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (optionalMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalMessage);
      }
      repeatedMessage_.WriteTo(output, _repeated_repeatedMessage_codec);
      if (requiredMessage_ != null) {
        output.WriteRawTag(26);
        output.WriteMessage(RequiredMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (optionalMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalMessage);
      }
      repeatedMessage_.WriteTo(ref output, _repeated_repeatedMessage_codec);
      if (requiredMessage_ != null) {
        output.WriteRawTag(26);
        output.WriteMessage(RequiredMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (optionalMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage);
      }
      size += repeatedMessage_.CalculateSize(_repeated_repeatedMessage_codec);
      if (requiredMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(RequiredMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRequiredMessage other) {
      if (other == null) {
        return;
      }
      if (other.optionalMessage_ != null) {
        if (optionalMessage_ == null) {
          OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
        }
        OptionalMessage.MergeFrom(other.OptionalMessage);
      }
      repeatedMessage_.Add(other.repeatedMessage_);
      if (other.requiredMessage_ != null) {
        if (requiredMessage_ == null) {
          RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
        }
        RequiredMessage.MergeFrom(other.RequiredMessage);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 18: {
            repeatedMessage_.AddEntriesFrom(input, _repeated_repeatedMessage_codec);
            break;
          }
          case 26: {
            if (requiredMessage_ == null) {
              RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(RequiredMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 18: {
            repeatedMessage_.AddEntriesFrom(ref input, _repeated_repeatedMessage_codec);
            break;
          }
          case 26: {
            if (requiredMessage_ == null) {
              RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired();
            }
            input.ReadMessage(RequiredMessage);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test that we can use NestedMessage from outside TestAllTypes.
  /// </summary>
  public sealed partial class TestForeignNested : pb::IMessage<TestForeignNested>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestForeignNested> _parser = new pb::MessageParser<TestForeignNested>(() => new TestForeignNested());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestForeignNested> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[15]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestForeignNested() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestForeignNested(TestForeignNested other) : this() {
      foreignNested_ = other.foreignNested_ != null ? other.foreignNested_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestForeignNested Clone() {
      return new TestForeignNested(this);
    }

    /// <summary>Field number for the "foreign_nested" field.</summary>
    public const int ForeignNestedFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage foreignNested_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage ForeignNested {
      get { return foreignNested_; }
      set {
        foreignNested_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestForeignNested);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestForeignNested other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(ForeignNested, other.ForeignNested)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (foreignNested_ != null) hash ^= ForeignNested.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (foreignNested_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(ForeignNested);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (foreignNested_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(ForeignNested);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (foreignNested_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(ForeignNested);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestForeignNested other) {
      if (other == null) {
        return;
      }
      if (other.foreignNested_ != null) {
        if (foreignNested_ == null) {
          ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
        }
        ForeignNested.MergeFrom(other.ForeignNested);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (foreignNested_ == null) {
              ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(ForeignNested);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (foreignNested_ == null) {
              ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage();
            }
            input.ReadMessage(ForeignNested);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// TestEmptyMessage is used to test unknown field support.
  /// </summary>
  public sealed partial class TestEmptyMessage : pb::IMessage<TestEmptyMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestEmptyMessage> _parser = new pb::MessageParser<TestEmptyMessage>(() => new TestEmptyMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestEmptyMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[16]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessage(TestEmptyMessage other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessage Clone() {
      return new TestEmptyMessage(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestEmptyMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestEmptyMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestEmptyMessage other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Like above, but declare all field numbers as potential extensions.  No
  /// actual extensions should ever be defined for this type.
  /// </summary>
  public sealed partial class TestEmptyMessageWithExtensions : pb::IExtendableMessage<TestEmptyMessageWithExtensions>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestEmptyMessageWithExtensions> _parser = new pb::MessageParser<TestEmptyMessageWithExtensions>(() => new TestEmptyMessageWithExtensions());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestEmptyMessageWithExtensions> _extensions;
    private pb::ExtensionSet<TestEmptyMessageWithExtensions> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestEmptyMessageWithExtensions> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[17]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessageWithExtensions() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessageWithExtensions(TestEmptyMessageWithExtensions other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEmptyMessageWithExtensions Clone() {
      return new TestEmptyMessageWithExtensions(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestEmptyMessageWithExtensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestEmptyMessageWithExtensions other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestEmptyMessageWithExtensions other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestEmptyMessageWithExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestEmptyMessageWithExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestEmptyMessageWithExtensions, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestEmptyMessageWithExtensions, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestEmptyMessageWithExtensions, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestEmptyMessageWithExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestEmptyMessageWithExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  public sealed partial class TestMultipleExtensionRanges : pb::IExtendableMessage<TestMultipleExtensionRanges>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestMultipleExtensionRanges> _parser = new pb::MessageParser<TestMultipleExtensionRanges>(() => new TestMultipleExtensionRanges());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestMultipleExtensionRanges> _extensions;
    private pb::ExtensionSet<TestMultipleExtensionRanges> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestMultipleExtensionRanges> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[18]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMultipleExtensionRanges() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMultipleExtensionRanges(TestMultipleExtensionRanges other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMultipleExtensionRanges Clone() {
      return new TestMultipleExtensionRanges(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestMultipleExtensionRanges);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestMultipleExtensionRanges other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestMultipleExtensionRanges other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestMultipleExtensionRanges, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestMultipleExtensionRanges, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestMultipleExtensionRanges, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestMultipleExtensionRanges, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestMultipleExtensionRanges, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestMultipleExtensionRanges, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestMultipleExtensionRanges, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  /// <summary>
  /// Test that really large tag numbers don't break anything.
  /// </summary>
  public sealed partial class TestReallyLargeTagNumber : pb::IMessage<TestReallyLargeTagNumber>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestReallyLargeTagNumber> _parser = new pb::MessageParser<TestReallyLargeTagNumber>(() => new TestReallyLargeTagNumber());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestReallyLargeTagNumber> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[19]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReallyLargeTagNumber() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReallyLargeTagNumber(TestReallyLargeTagNumber other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_;
      bb_ = other.bb_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestReallyLargeTagNumber Clone() {
      return new TestReallyLargeTagNumber(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private readonly static int ADefaultValue = 0;

    private int a_;
    /// <summary>
    /// The largest possible tag number is 2^28 - 1, since the wire format uses
    /// three bits to communicate wire type.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int A {
      get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
      set {
        _hasBits0 |= 1;
        a_ = value;
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "bb" field.</summary>
    public const int BbFieldNumber = 268435455;
    private readonly static int BbDefaultValue = 0;

    private int bb_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Bb {
      get { if ((_hasBits0 & 2) != 0) { return bb_; } else { return BbDefaultValue; } }
      set {
        _hasBits0 |= 2;
        bb_ = value;
      }
    }
    /// <summary>Gets whether the "bb" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBb {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "bb" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBb() {
      _hasBits0 &= ~2;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestReallyLargeTagNumber);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestReallyLargeTagNumber other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      if (Bb != other.Bb) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (HasBb) hash ^= Bb.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasBb) {
        output.WriteRawTag(248, 255, 255, 255, 7);
        output.WriteInt32(Bb);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasBb) {
        output.WriteRawTag(248, 255, 255, 255, 7);
        output.WriteInt32(Bb);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
      }
      if (HasBb) {
        size += 5 + pb::CodedOutputStream.ComputeInt32Size(Bb);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestReallyLargeTagNumber other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      if (other.HasBb) {
        Bb = other.Bb;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 2147483640: {
            Bb = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 2147483640: {
            Bb = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestRecursiveMessage : pb::IMessage<TestRecursiveMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRecursiveMessage> _parser = new pb::MessageParser<TestRecursiveMessage>(() => new TestRecursiveMessage());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRecursiveMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[20]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRecursiveMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRecursiveMessage(TestRecursiveMessage other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_ != null ? other.a_.Clone() : null;
      i_ = other.i_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRecursiveMessage Clone() {
      return new TestRecursiveMessage(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage a_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage A {
      get { return a_; }
      set {
        a_ = value;
      }
    }

    /// <summary>Field number for the "i" field.</summary>
    public const int IFieldNumber = 2;
    private readonly static int IDefaultValue = 0;

    private int i_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int I {
      get { if ((_hasBits0 & 1) != 0) { return i_; } else { return IDefaultValue; } }
      set {
        _hasBits0 |= 1;
        i_ = value;
      }
    }
    /// <summary>Gets whether the "i" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasI {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "i" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearI() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRecursiveMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRecursiveMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(A, other.A)) return false;
      if (I != other.I) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (a_ != null) hash ^= A.GetHashCode();
      if (HasI) hash ^= I.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (a_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(A);
      }
      if (HasI) {
        output.WriteRawTag(16);
        output.WriteInt32(I);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (a_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(A);
      }
      if (HasI) {
        output.WriteRawTag(16);
        output.WriteInt32(I);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (a_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(A);
      }
      if (HasI) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(I);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRecursiveMessage other) {
      if (other == null) {
        return;
      }
      if (other.a_ != null) {
        if (a_ == null) {
          A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage();
        }
        A.MergeFrom(other.A);
      }
      if (other.HasI) {
        I = other.I;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (a_ == null) {
              A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage();
            }
            input.ReadMessage(A);
            break;
          }
          case 16: {
            I = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (a_ == null) {
              A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage();
            }
            input.ReadMessage(A);
            break;
          }
          case 16: {
            I = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test that mutual recursion works.
  /// </summary>
  public sealed partial class TestMutualRecursionA : pb::IMessage<TestMutualRecursionA>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestMutualRecursionA> _parser = new pb::MessageParser<TestMutualRecursionA>(() => new TestMutualRecursionA());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestMutualRecursionA> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[21]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionA() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionA(TestMutualRecursionA other) : this() {
      bb_ = other.bb_ != null ? other.bb_.Clone() : null;
      subGroup_ = other.HasSubGroup ? other.subGroup_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionA Clone() {
      return new TestMutualRecursionA(this);
    }

    /// <summary>Field number for the "bb" field.</summary>
    public const int BbFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB bb_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB Bb {
      get { return bb_; }
      set {
        bb_ = value;
      }
    }

    /// <summary>Field number for the "subgroup" field.</summary>
    public const int SubGroupFieldNumber = 2;
    private global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup subGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup SubGroup {
      get { return subGroup_; }
      set {
        subGroup_ = value;
      }
    }
    /// <summary>Gets whether the subgroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSubGroup {
      get { return subGroup_ != null; }
    }
    /// <summary>Clears the value of the subgroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSubGroup() {
      subGroup_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestMutualRecursionA);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestMutualRecursionA other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(Bb, other.Bb)) return false;
      if (!object.Equals(SubGroup, other.SubGroup)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (bb_ != null) hash ^= Bb.GetHashCode();
      if (HasSubGroup) hash ^= SubGroup.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (bb_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(Bb);
      }
      if (HasSubGroup) {
        output.WriteRawTag(19);
        output.WriteGroup(SubGroup);
        output.WriteRawTag(20);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (bb_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(Bb);
      }
      if (HasSubGroup) {
        output.WriteRawTag(19);
        output.WriteGroup(SubGroup);
        output.WriteRawTag(20);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (bb_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(Bb);
      }
      if (HasSubGroup) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(SubGroup);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestMutualRecursionA other) {
      if (other == null) {
        return;
      }
      if (other.bb_ != null) {
        if (bb_ == null) {
          Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
        }
        Bb.MergeFrom(other.Bb);
      }
      if (other.HasSubGroup) {
        if (!HasSubGroup) {
          SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup();
        }
        SubGroup.MergeFrom(other.SubGroup);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (bb_ == null) {
              Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
            }
            input.ReadMessage(Bb);
            break;
          }
          case 19: {
            if (!HasSubGroup) {
              SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup();
            }
            input.ReadGroup(SubGroup);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (bb_ == null) {
              Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
            }
            input.ReadMessage(Bb);
            break;
          }
          case 19: {
            if (!HasSubGroup) {
              SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup();
            }
            input.ReadGroup(SubGroup);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestMutualRecursionA message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class SubMessage : pb::IMessage<SubMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<SubMessage> _parser = new pb::MessageParser<SubMessage>(() => new SubMessage());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<SubMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage(SubMessage other) : this() {
          b_ = other.b_ != null ? other.b_.Clone() : null;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage Clone() {
          return new SubMessage(this);
        }

        /// <summary>Field number for the "b" field.</summary>
        public const int BFieldNumber = 1;
        private global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB b_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB B {
          get { return b_; }
          set {
            b_ = value;
          }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as SubMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(SubMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!object.Equals(B, other.B)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (b_ != null) hash ^= B.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (b_ != null) {
            output.WriteRawTag(10);
            output.WriteMessage(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (b_ != null) {
            output.WriteRawTag(10);
            output.WriteMessage(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (b_ != null) {
            size += 1 + pb::CodedOutputStream.ComputeMessageSize(B);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(SubMessage other) {
          if (other == null) {
            return;
          }
          if (other.b_ != null) {
            if (b_ == null) {
              B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
            }
            B.MergeFrom(other.B);
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 10: {
                if (b_ == null) {
                  B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
                }
                input.ReadMessage(B);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 10: {
                if (b_ == null) {
                  B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB();
                }
                input.ReadMessage(B);
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class SubGroup : pb::IMessage<SubGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<SubGroup> _parser = new pb::MessageParser<SubGroup>(() => new SubGroup());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<SubGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubGroup(SubGroup other) : this() {
          subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null;
          notInThisScc_ = other.notInThisScc_ != null ? other.notInThisScc_.Clone() : null;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubGroup Clone() {
          return new SubGroup(this);
        }

        /// <summary>Field number for the "sub_message" field.</summary>
        public const int SubMessageFieldNumber = 3;
        private global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage subMessage_;
        /// <summary>
        /// Needed because of bug in javatest
        /// </summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage SubMessage {
          get { return subMessage_; }
          set {
            subMessage_ = value;
          }
        }

        /// <summary>Field number for the "not_in_this_scc" field.</summary>
        public const int NotInThisSccFieldNumber = 4;
        private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes notInThisScc_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes NotInThisScc {
          get { return notInThisScc_; }
          set {
            notInThisScc_ = value;
          }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as SubGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(SubGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!object.Equals(SubMessage, other.SubMessage)) return false;
          if (!object.Equals(NotInThisScc, other.NotInThisScc)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (subMessage_ != null) hash ^= SubMessage.GetHashCode();
          if (notInThisScc_ != null) hash ^= NotInThisScc.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (subMessage_ != null) {
            output.WriteRawTag(26);
            output.WriteMessage(SubMessage);
          }
          if (notInThisScc_ != null) {
            output.WriteRawTag(34);
            output.WriteMessage(NotInThisScc);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (subMessage_ != null) {
            output.WriteRawTag(26);
            output.WriteMessage(SubMessage);
          }
          if (notInThisScc_ != null) {
            output.WriteRawTag(34);
            output.WriteMessage(NotInThisScc);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (subMessage_ != null) {
            size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage);
          }
          if (notInThisScc_ != null) {
            size += 1 + pb::CodedOutputStream.ComputeMessageSize(NotInThisScc);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(SubGroup other) {
          if (other == null) {
            return;
          }
          if (other.subMessage_ != null) {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage();
            }
            SubMessage.MergeFrom(other.SubMessage);
          }
          if (other.notInThisScc_ != null) {
            if (notInThisScc_ == null) {
              NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            NotInThisScc.MergeFrom(other.NotInThisScc);
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 20:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 26: {
                if (subMessage_ == null) {
                  SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage();
                }
                input.ReadMessage(SubMessage);
                break;
              }
              case 34: {
                if (notInThisScc_ == null) {
                  NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(NotInThisScc);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 20:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 26: {
                if (subMessage_ == null) {
                  SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage();
                }
                input.ReadMessage(SubMessage);
                break;
              }
              case 34: {
                if (notInThisScc_ == null) {
                  NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(NotInThisScc);
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestMutualRecursionB : pb::IMessage<TestMutualRecursionB>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestMutualRecursionB> _parser = new pb::MessageParser<TestMutualRecursionB>(() => new TestMutualRecursionB());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestMutualRecursionB> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[22]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionB() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionB(TestMutualRecursionB other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_ != null ? other.a_.Clone() : null;
      optionalInt32_ = other.optionalInt32_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestMutualRecursionB Clone() {
      return new TestMutualRecursionB(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA a_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA A {
      get { return a_; }
      set {
        a_ = value;
      }
    }

    /// <summary>Field number for the "optional_int32" field.</summary>
    public const int OptionalInt32FieldNumber = 2;
    private readonly static int OptionalInt32DefaultValue = 0;

    private int optionalInt32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int OptionalInt32 {
      get { if ((_hasBits0 & 1) != 0) { return optionalInt32_; } else { return OptionalInt32DefaultValue; } }
      set {
        _hasBits0 |= 1;
        optionalInt32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalInt32 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "optional_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalInt32() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestMutualRecursionB);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestMutualRecursionB other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(A, other.A)) return false;
      if (OptionalInt32 != other.OptionalInt32) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (a_ != null) hash ^= A.GetHashCode();
      if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (a_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(A);
      }
      if (HasOptionalInt32) {
        output.WriteRawTag(16);
        output.WriteInt32(OptionalInt32);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (a_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(A);
      }
      if (HasOptionalInt32) {
        output.WriteRawTag(16);
        output.WriteInt32(OptionalInt32);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (a_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(A);
      }
      if (HasOptionalInt32) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(OptionalInt32);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestMutualRecursionB other) {
      if (other == null) {
        return;
      }
      if (other.a_ != null) {
        if (a_ == null) {
          A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA();
        }
        A.MergeFrom(other.A);
      }
      if (other.HasOptionalInt32) {
        OptionalInt32 = other.OptionalInt32;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (a_ == null) {
              A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA();
            }
            input.ReadMessage(A);
            break;
          }
          case 16: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (a_ == null) {
              A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA();
            }
            input.ReadMessage(A);
            break;
          }
          case 16: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestIsInitialized : pb::IMessage<TestIsInitialized>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestIsInitialized> _parser = new pb::MessageParser<TestIsInitialized>(() => new TestIsInitialized());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestIsInitialized> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[23]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestIsInitialized() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestIsInitialized(TestIsInitialized other) : this() {
      subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestIsInitialized Clone() {
      return new TestIsInitialized(this);
    }

    /// <summary>Field number for the "sub_message" field.</summary>
    public const int SubMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage subMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage SubMessage {
      get { return subMessage_; }
      set {
        subMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestIsInitialized);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestIsInitialized other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(SubMessage, other.SubMessage)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (subMessage_ != null) hash ^= SubMessage.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (subMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestIsInitialized other) {
      if (other == null) {
        return;
      }
      if (other.subMessage_ != null) {
        if (subMessage_ == null) {
          SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage();
        }
        SubMessage.MergeFrom(other.SubMessage);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestIsInitialized message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class SubMessage : pb::IMessage<SubMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<SubMessage> _parser = new pb::MessageParser<SubMessage>(() => new SubMessage());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<SubMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage(SubMessage other) : this() {
          subGroup_ = other.HasSubGroup ? other.subGroup_.Clone() : null;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public SubMessage Clone() {
          return new SubMessage(this);
        }

        /// <summary>Field number for the "subgroup" field.</summary>
        public const int SubGroupFieldNumber = 1;
        private global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup subGroup_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup SubGroup {
          get { return subGroup_; }
          set {
            subGroup_ = value;
          }
        }
        /// <summary>Gets whether the subgroup field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasSubGroup {
          get { return subGroup_ != null; }
        }
        /// <summary>Clears the value of the subgroup field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearSubGroup() {
          subGroup_ = null;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as SubMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(SubMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!object.Equals(SubGroup, other.SubGroup)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasSubGroup) hash ^= SubGroup.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasSubGroup) {
            output.WriteRawTag(11);
            output.WriteGroup(SubGroup);
            output.WriteRawTag(12);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasSubGroup) {
            output.WriteRawTag(11);
            output.WriteGroup(SubGroup);
            output.WriteRawTag(12);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasSubGroup) {
            size += 2 + pb::CodedOutputStream.ComputeGroupSize(SubGroup);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(SubMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasSubGroup) {
            if (!HasSubGroup) {
              SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup();
            }
            SubGroup.MergeFrom(other.SubGroup);
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 11: {
                if (!HasSubGroup) {
                  SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup();
                }
                input.ReadGroup(SubGroup);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 11: {
                if (!HasSubGroup) {
                  SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup();
                }
                input.ReadGroup(SubGroup);
                break;
              }
            }
          }
        }
        #endif

        #region Nested types
        /// <summary>Container for nested types declared in the SubMessage message type.</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static partial class Types {
          public sealed partial class SubGroup : pb::IMessage<SubGroup>
          #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              , pb::IBufferMessage
          #endif
          {
            private static readonly pb::MessageParser<SubGroup> _parser = new pb::MessageParser<SubGroup>(() => new SubGroup());
            private pb::UnknownFieldSet _unknownFields;
            private int _hasBits0;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pb::MessageParser<SubGroup> Parser { get { return _parser; } }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pbr::MessageDescriptor Descriptor {
              get { return global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Descriptor.NestedTypes[0]; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            pbr::MessageDescriptor pb::IMessage.Descriptor {
              get { return Descriptor; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public SubGroup() {
              OnConstruction();
            }

            partial void OnConstruction();

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public SubGroup(SubGroup other) : this() {
              _hasBits0 = other._hasBits0;
              i_ = other.i_;
              _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public SubGroup Clone() {
              return new SubGroup(this);
            }

            /// <summary>Field number for the "i" field.</summary>
            public const int IFieldNumber = 2;
            private readonly static int IDefaultValue = 0;

            private int i_;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public int I {
              get { if ((_hasBits0 & 1) != 0) { return i_; } else { return IDefaultValue; } }
              set {
                _hasBits0 |= 1;
                i_ = value;
              }
            }
            /// <summary>Gets whether the "i" field is set</summary>
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public bool HasI {
              get { return (_hasBits0 & 1) != 0; }
            }
            /// <summary>Clears the value of the "i" field</summary>
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void ClearI() {
              _hasBits0 &= ~1;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override bool Equals(object other) {
              return Equals(other as SubGroup);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public bool Equals(SubGroup other) {
              if (ReferenceEquals(other, null)) {
                return false;
              }
              if (ReferenceEquals(other, this)) {
                return true;
              }
              if (I != other.I) return false;
              return Equals(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override int GetHashCode() {
              int hash = 1;
              if (HasI) hash ^= I.GetHashCode();
              if (_unknownFields != null) {
                hash ^= _unknownFields.GetHashCode();
              }
              return hash;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override string ToString() {
              return pb::JsonFormatter.ToDiagnosticString(this);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void WriteTo(pb::CodedOutputStream output) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              output.WriteRawMessage(this);
            #else
              if (HasI) {
                output.WriteRawTag(16);
                output.WriteInt32(I);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(output);
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
              if (HasI) {
                output.WriteRawTag(16);
                output.WriteInt32(I);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(ref output);
              }
            }
            #endif

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public int CalculateSize() {
              int size = 0;
              if (HasI) {
                size += 1 + pb::CodedOutputStream.ComputeInt32Size(I);
              }
              if (_unknownFields != null) {
                size += _unknownFields.CalculateSize();
              }
              return size;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(SubGroup other) {
              if (other == null) {
                return;
              }
              if (other.HasI) {
                I = other.I;
              }
              _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(pb::CodedInputStream input) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              input.ReadRawMessage(this);
            #else
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 12:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;
                  case 16: {
                    I = input.ReadInt32();
                    break;
                  }
                }
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 12:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                    break;
                  case 16: {
                    I = input.ReadInt32();
                    break;
                  }
                }
              }
            }
            #endif

          }

        }
        #endregion

      }

    }
    #endregion

  }

  /// <summary>
  /// Test that groups have disjoint field numbers from their siblings and
  /// parents.  This is NOT possible in proto1; only google.protobuf.  When
  /// attempting to compile with proto1, this will emit an error; so we only
  /// include it in protobuf_unittest_proto.
  /// </summary>
  public sealed partial class TestDupFieldNumber : pb::IMessage<TestDupFieldNumber>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestDupFieldNumber> _parser = new pb::MessageParser<TestDupFieldNumber>(() => new TestDupFieldNumber());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestDupFieldNumber> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[24]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDupFieldNumber() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDupFieldNumber(TestDupFieldNumber other) : this() {
      _hasBits0 = other._hasBits0;
      a_ = other.a_;
      foo_ = other.HasFoo ? other.foo_.Clone() : null;
      bar_ = other.HasBar ? other.bar_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDupFieldNumber Clone() {
      return new TestDupFieldNumber(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private readonly static int ADefaultValue = 0;

    private int a_;
    /// <summary>
    /// NO_PROTO1
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int A {
      get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
      set {
        _hasBits0 |= 1;
        a_ = value;
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "foo" field.</summary>
    public const int FooFieldNumber = 2;
    private global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo foo_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo Foo {
      get { return foo_; }
      set {
        foo_ = value;
      }
    }
    /// <summary>Gets whether the foo field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFoo {
      get { return foo_ != null; }
    }
    /// <summary>Clears the value of the foo field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFoo() {
      foo_ = null;
    }

    /// <summary>Field number for the "bar" field.</summary>
    public const int BarFieldNumber = 3;
    private global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar bar_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar Bar {
      get { return bar_; }
      set {
        bar_ = value;
      }
    }
    /// <summary>Gets whether the bar field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBar {
      get { return bar_ != null; }
    }
    /// <summary>Clears the value of the bar field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBar() {
      bar_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestDupFieldNumber);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestDupFieldNumber other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      if (!object.Equals(Foo, other.Foo)) return false;
      if (!object.Equals(Bar, other.Bar)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (HasFoo) hash ^= Foo.GetHashCode();
      if (HasBar) hash ^= Bar.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasFoo) {
        output.WriteRawTag(19);
        output.WriteGroup(Foo);
        output.WriteRawTag(20);
      }
      if (HasBar) {
        output.WriteRawTag(27);
        output.WriteGroup(Bar);
        output.WriteRawTag(28);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(8);
        output.WriteInt32(A);
      }
      if (HasFoo) {
        output.WriteRawTag(19);
        output.WriteGroup(Foo);
        output.WriteRawTag(20);
      }
      if (HasBar) {
        output.WriteRawTag(27);
        output.WriteGroup(Bar);
        output.WriteRawTag(28);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
      }
      if (HasFoo) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(Foo);
      }
      if (HasBar) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(Bar);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestDupFieldNumber other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      if (other.HasFoo) {
        if (!HasFoo) {
          Foo = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo();
        }
        Foo.MergeFrom(other.Foo);
      }
      if (other.HasBar) {
        if (!HasBar) {
          Bar = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar();
        }
        Bar.MergeFrom(other.Bar);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 19: {
            if (!HasFoo) {
              Foo = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo();
            }
            input.ReadGroup(Foo);
            break;
          }
          case 27: {
            if (!HasBar) {
              Bar = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar();
            }
            input.ReadGroup(Bar);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            A = input.ReadInt32();
            break;
          }
          case 19: {
            if (!HasFoo) {
              Foo = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo();
            }
            input.ReadGroup(Foo);
            break;
          }
          case 27: {
            if (!HasBar) {
              Bar = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar();
            }
            input.ReadGroup(Bar);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestDupFieldNumber message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class Foo : pb::IMessage<Foo>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<Foo> _parser = new pb::MessageParser<Foo>(() => new Foo());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<Foo> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Foo() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Foo(Foo other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Foo Clone() {
          return new Foo(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 1;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as Foo);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(Foo other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(8);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(8);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(Foo other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 20:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 20:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class Bar : pb::IMessage<Bar>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<Bar> _parser = new pb::MessageParser<Bar>(() => new Bar());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<Bar> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Bar() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Bar(Bar other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public Bar Clone() {
          return new Bar(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 1;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as Bar);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(Bar other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(8);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(8);
            output.WriteInt32(A);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(Bar other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 28:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 28:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                A = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  /// <summary>
  /// Additional messages for testing lazy fields.
  /// </summary>
  public sealed partial class TestEagerMessage : pb::IMessage<TestEagerMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestEagerMessage> _parser = new pb::MessageParser<TestEagerMessage>(() => new TestEagerMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestEagerMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[25]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEagerMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEagerMessage(TestEagerMessage other) : this() {
      subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestEagerMessage Clone() {
      return new TestEagerMessage(this);
    }

    /// <summary>Field number for the "sub_message" field.</summary>
    public const int SubMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes SubMessage {
      get { return subMessage_; }
      set {
        subMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestEagerMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestEagerMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(SubMessage, other.SubMessage)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (subMessage_ != null) hash ^= SubMessage.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (subMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestEagerMessage other) {
      if (other == null) {
        return;
      }
      if (other.subMessage_ != null) {
        if (subMessage_ == null) {
          SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        SubMessage.MergeFrom(other.SubMessage);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestLazyMessage : pb::IMessage<TestLazyMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestLazyMessage> _parser = new pb::MessageParser<TestLazyMessage>(() => new TestLazyMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestLazyMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[26]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestLazyMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestLazyMessage(TestLazyMessage other) : this() {
      subMessage_ = other.subMessage_ != null ? other.subMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestLazyMessage Clone() {
      return new TestLazyMessage(this);
    }

    /// <summary>Field number for the "sub_message" field.</summary>
    public const int SubMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes SubMessage {
      get { return subMessage_; }
      set {
        subMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestLazyMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestLazyMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(SubMessage, other.SubMessage)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (subMessage_ != null) hash ^= SubMessage.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (subMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(SubMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (subMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(SubMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestLazyMessage other) {
      if (other == null) {
        return;
      }
      if (other.subMessage_ != null) {
        if (subMessage_ == null) {
          SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        SubMessage.MergeFrom(other.SubMessage);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (subMessage_ == null) {
              SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(SubMessage);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Needed for a Python test.
  /// </summary>
  public sealed partial class TestNestedMessageHasBits : pb::IMessage<TestNestedMessageHasBits>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestNestedMessageHasBits> _parser = new pb::MessageParser<TestNestedMessageHasBits>(() => new TestNestedMessageHasBits());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestNestedMessageHasBits> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[27]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedMessageHasBits() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedMessageHasBits(TestNestedMessageHasBits other) : this() {
      optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestNestedMessageHasBits Clone() {
      return new TestNestedMessageHasBits(this);
    }

    /// <summary>Field number for the "optional_nested_message" field.</summary>
    public const int OptionalNestedMessageFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage optionalNestedMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage OptionalNestedMessage {
      get { return optionalNestedMessage_; }
      set {
        optionalNestedMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestNestedMessageHasBits);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestNestedMessageHasBits other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (optionalNestedMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestNestedMessageHasBits other) {
      if (other == null) {
        return;
      }
      if (other.optionalNestedMessage_ != null) {
        if (optionalNestedMessage_ == null) {
          OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage();
        }
        OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestNestedMessageHasBits message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          nestedmessageRepeatedInt32_ = other.nestedmessageRepeatedInt32_.Clone();
          nestedmessageRepeatedForeignmessage_ = other.nestedmessageRepeatedForeignmessage_.Clone();
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "nestedmessage_repeated_int32" field.</summary>
        public const int NestedmessageRepeatedInt32FieldNumber = 1;
        private static readonly pb::FieldCodec<int> _repeated_nestedmessageRepeatedInt32_codec
            = pb::FieldCodec.ForInt32(8);
        private readonly pbc::RepeatedField<int> nestedmessageRepeatedInt32_ = new pbc::RepeatedField<int>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<int> NestedmessageRepeatedInt32 {
          get { return nestedmessageRepeatedInt32_; }
        }

        /// <summary>Field number for the "nestedmessage_repeated_foreignmessage" field.</summary>
        public const int NestedmessageRepeatedForeignmessageFieldNumber = 2;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> _repeated_nestedmessageRepeatedForeignmessage_codec
            = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> nestedmessageRepeatedForeignmessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> NestedmessageRepeatedForeignmessage {
          get { return nestedmessageRepeatedForeignmessage_; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if(!nestedmessageRepeatedInt32_.Equals(other.nestedmessageRepeatedInt32_)) return false;
          if(!nestedmessageRepeatedForeignmessage_.Equals(other.nestedmessageRepeatedForeignmessage_)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          hash ^= nestedmessageRepeatedInt32_.GetHashCode();
          hash ^= nestedmessageRepeatedForeignmessage_.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          nestedmessageRepeatedInt32_.WriteTo(output, _repeated_nestedmessageRepeatedInt32_codec);
          nestedmessageRepeatedForeignmessage_.WriteTo(output, _repeated_nestedmessageRepeatedForeignmessage_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          nestedmessageRepeatedInt32_.WriteTo(ref output, _repeated_nestedmessageRepeatedInt32_codec);
          nestedmessageRepeatedForeignmessage_.WriteTo(ref output, _repeated_nestedmessageRepeatedForeignmessage_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          size += nestedmessageRepeatedInt32_.CalculateSize(_repeated_nestedmessageRepeatedInt32_codec);
          size += nestedmessageRepeatedForeignmessage_.CalculateSize(_repeated_nestedmessageRepeatedForeignmessage_codec);
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          nestedmessageRepeatedInt32_.Add(other.nestedmessageRepeatedInt32_);
          nestedmessageRepeatedForeignmessage_.Add(other.nestedmessageRepeatedForeignmessage_);
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 10:
              case 8: {
                nestedmessageRepeatedInt32_.AddEntriesFrom(input, _repeated_nestedmessageRepeatedInt32_codec);
                break;
              }
              case 18: {
                nestedmessageRepeatedForeignmessage_.AddEntriesFrom(input, _repeated_nestedmessageRepeatedForeignmessage_codec);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 10:
              case 8: {
                nestedmessageRepeatedInt32_.AddEntriesFrom(ref input, _repeated_nestedmessageRepeatedInt32_codec);
                break;
              }
              case 18: {
                nestedmessageRepeatedForeignmessage_.AddEntriesFrom(ref input, _repeated_nestedmessageRepeatedForeignmessage_codec);
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  /// <summary>
  /// Test message with CamelCase field names.  This violates Protocol Buffer
  /// standard style.
  /// </summary>
  public sealed partial class TestCamelCaseFieldNames : pb::IMessage<TestCamelCaseFieldNames>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestCamelCaseFieldNames> _parser = new pb::MessageParser<TestCamelCaseFieldNames>(() => new TestCamelCaseFieldNames());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestCamelCaseFieldNames> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[28]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCamelCaseFieldNames() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCamelCaseFieldNames(TestCamelCaseFieldNames other) : this() {
      _hasBits0 = other._hasBits0;
      primitiveField_ = other.primitiveField_;
      stringField_ = other.stringField_;
      enumField_ = other.enumField_;
      messageField_ = other.messageField_ != null ? other.messageField_.Clone() : null;
      stringPieceField_ = other.stringPieceField_;
      cordField_ = other.cordField_;
      repeatedPrimitiveField_ = other.repeatedPrimitiveField_.Clone();
      repeatedStringField_ = other.repeatedStringField_.Clone();
      repeatedEnumField_ = other.repeatedEnumField_.Clone();
      repeatedMessageField_ = other.repeatedMessageField_.Clone();
      repeatedStringPieceField_ = other.repeatedStringPieceField_.Clone();
      repeatedCordField_ = other.repeatedCordField_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCamelCaseFieldNames Clone() {
      return new TestCamelCaseFieldNames(this);
    }

    /// <summary>Field number for the "PrimitiveField" field.</summary>
    public const int PrimitiveFieldFieldNumber = 1;
    private readonly static int PrimitiveFieldDefaultValue = 0;

    private int primitiveField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int PrimitiveField {
      get { if ((_hasBits0 & 1) != 0) { return primitiveField_; } else { return PrimitiveFieldDefaultValue; } }
      set {
        _hasBits0 |= 1;
        primitiveField_ = value;
      }
    }
    /// <summary>Gets whether the "PrimitiveField" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasPrimitiveField {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "PrimitiveField" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearPrimitiveField() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "StringField" field.</summary>
    public const int StringFieldFieldNumber = 2;
    private readonly static string StringFieldDefaultValue = "";

    private string stringField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string StringField {
      get { return stringField_ ?? StringFieldDefaultValue; }
      set {
        stringField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "StringField" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasStringField {
      get { return stringField_ != null; }
    }
    /// <summary>Clears the value of the "StringField" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearStringField() {
      stringField_ = null;
    }

    /// <summary>Field number for the "EnumField" field.</summary>
    public const int EnumFieldFieldNumber = 3;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum EnumFieldDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum enumField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum EnumField {
      get { if ((_hasBits0 & 2) != 0) { return enumField_; } else { return EnumFieldDefaultValue; } }
      set {
        _hasBits0 |= 2;
        enumField_ = value;
      }
    }
    /// <summary>Gets whether the "EnumField" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasEnumField {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "EnumField" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearEnumField() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "MessageField" field.</summary>
    public const int MessageFieldFieldNumber = 4;
    private global::Google.Protobuf.TestProtos.Proto2.ForeignMessage messageField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignMessage MessageField {
      get { return messageField_; }
      set {
        messageField_ = value;
      }
    }

    /// <summary>Field number for the "StringPieceField" field.</summary>
    public const int StringPieceFieldFieldNumber = 5;
    private readonly static string StringPieceFieldDefaultValue = "";

    private string stringPieceField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string StringPieceField {
      get { return stringPieceField_ ?? StringPieceFieldDefaultValue; }
      set {
        stringPieceField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "StringPieceField" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasStringPieceField {
      get { return stringPieceField_ != null; }
    }
    /// <summary>Clears the value of the "StringPieceField" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearStringPieceField() {
      stringPieceField_ = null;
    }

    /// <summary>Field number for the "CordField" field.</summary>
    public const int CordFieldFieldNumber = 6;
    private readonly static string CordFieldDefaultValue = "";

    private string cordField_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string CordField {
      get { return cordField_ ?? CordFieldDefaultValue; }
      set {
        cordField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "CordField" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasCordField {
      get { return cordField_ != null; }
    }
    /// <summary>Clears the value of the "CordField" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearCordField() {
      cordField_ = null;
    }

    /// <summary>Field number for the "RepeatedPrimitiveField" field.</summary>
    public const int RepeatedPrimitiveFieldFieldNumber = 7;
    private static readonly pb::FieldCodec<int> _repeated_repeatedPrimitiveField_codec
        = pb::FieldCodec.ForInt32(56);
    private readonly pbc::RepeatedField<int> repeatedPrimitiveField_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedPrimitiveField {
      get { return repeatedPrimitiveField_; }
    }

    /// <summary>Field number for the "RepeatedStringField" field.</summary>
    public const int RepeatedStringFieldFieldNumber = 8;
    private static readonly pb::FieldCodec<string> _repeated_repeatedStringField_codec
        = pb::FieldCodec.ForString(66);
    private readonly pbc::RepeatedField<string> repeatedStringField_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedStringField {
      get { return repeatedStringField_; }
    }

    /// <summary>Field number for the "RepeatedEnumField" field.</summary>
    public const int RepeatedEnumFieldFieldNumber = 9;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> _repeated_repeatedEnumField_codec
        = pb::FieldCodec.ForEnum(72, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> repeatedEnumField_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> RepeatedEnumField {
      get { return repeatedEnumField_; }
    }

    /// <summary>Field number for the "RepeatedMessageField" field.</summary>
    public const int RepeatedMessageFieldFieldNumber = 10;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> _repeated_repeatedMessageField_codec
        = pb::FieldCodec.ForMessage(82, global::Google.Protobuf.TestProtos.Proto2.ForeignMessage.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> repeatedMessageField_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignMessage> RepeatedMessageField {
      get { return repeatedMessageField_; }
    }

    /// <summary>Field number for the "RepeatedStringPieceField" field.</summary>
    public const int RepeatedStringPieceFieldFieldNumber = 11;
    private static readonly pb::FieldCodec<string> _repeated_repeatedStringPieceField_codec
        = pb::FieldCodec.ForString(90);
    private readonly pbc::RepeatedField<string> repeatedStringPieceField_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedStringPieceField {
      get { return repeatedStringPieceField_; }
    }

    /// <summary>Field number for the "RepeatedCordField" field.</summary>
    public const int RepeatedCordFieldFieldNumber = 12;
    private static readonly pb::FieldCodec<string> _repeated_repeatedCordField_codec
        = pb::FieldCodec.ForString(98);
    private readonly pbc::RepeatedField<string> repeatedCordField_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedCordField {
      get { return repeatedCordField_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestCamelCaseFieldNames);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestCamelCaseFieldNames other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (PrimitiveField != other.PrimitiveField) return false;
      if (StringField != other.StringField) return false;
      if (EnumField != other.EnumField) return false;
      if (!object.Equals(MessageField, other.MessageField)) return false;
      if (StringPieceField != other.StringPieceField) return false;
      if (CordField != other.CordField) return false;
      if(!repeatedPrimitiveField_.Equals(other.repeatedPrimitiveField_)) return false;
      if(!repeatedStringField_.Equals(other.repeatedStringField_)) return false;
      if(!repeatedEnumField_.Equals(other.repeatedEnumField_)) return false;
      if(!repeatedMessageField_.Equals(other.repeatedMessageField_)) return false;
      if(!repeatedStringPieceField_.Equals(other.repeatedStringPieceField_)) return false;
      if(!repeatedCordField_.Equals(other.repeatedCordField_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasPrimitiveField) hash ^= PrimitiveField.GetHashCode();
      if (HasStringField) hash ^= StringField.GetHashCode();
      if (HasEnumField) hash ^= EnumField.GetHashCode();
      if (messageField_ != null) hash ^= MessageField.GetHashCode();
      if (HasStringPieceField) hash ^= StringPieceField.GetHashCode();
      if (HasCordField) hash ^= CordField.GetHashCode();
      hash ^= repeatedPrimitiveField_.GetHashCode();
      hash ^= repeatedStringField_.GetHashCode();
      hash ^= repeatedEnumField_.GetHashCode();
      hash ^= repeatedMessageField_.GetHashCode();
      hash ^= repeatedStringPieceField_.GetHashCode();
      hash ^= repeatedCordField_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasPrimitiveField) {
        output.WriteRawTag(8);
        output.WriteInt32(PrimitiveField);
      }
      if (HasStringField) {
        output.WriteRawTag(18);
        output.WriteString(StringField);
      }
      if (HasEnumField) {
        output.WriteRawTag(24);
        output.WriteEnum((int) EnumField);
      }
      if (messageField_ != null) {
        output.WriteRawTag(34);
        output.WriteMessage(MessageField);
      }
      if (HasStringPieceField) {
        output.WriteRawTag(42);
        output.WriteString(StringPieceField);
      }
      if (HasCordField) {
        output.WriteRawTag(50);
        output.WriteString(CordField);
      }
      repeatedPrimitiveField_.WriteTo(output, _repeated_repeatedPrimitiveField_codec);
      repeatedStringField_.WriteTo(output, _repeated_repeatedStringField_codec);
      repeatedEnumField_.WriteTo(output, _repeated_repeatedEnumField_codec);
      repeatedMessageField_.WriteTo(output, _repeated_repeatedMessageField_codec);
      repeatedStringPieceField_.WriteTo(output, _repeated_repeatedStringPieceField_codec);
      repeatedCordField_.WriteTo(output, _repeated_repeatedCordField_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasPrimitiveField) {
        output.WriteRawTag(8);
        output.WriteInt32(PrimitiveField);
      }
      if (HasStringField) {
        output.WriteRawTag(18);
        output.WriteString(StringField);
      }
      if (HasEnumField) {
        output.WriteRawTag(24);
        output.WriteEnum((int) EnumField);
      }
      if (messageField_ != null) {
        output.WriteRawTag(34);
        output.WriteMessage(MessageField);
      }
      if (HasStringPieceField) {
        output.WriteRawTag(42);
        output.WriteString(StringPieceField);
      }
      if (HasCordField) {
        output.WriteRawTag(50);
        output.WriteString(CordField);
      }
      repeatedPrimitiveField_.WriteTo(ref output, _repeated_repeatedPrimitiveField_codec);
      repeatedStringField_.WriteTo(ref output, _repeated_repeatedStringField_codec);
      repeatedEnumField_.WriteTo(ref output, _repeated_repeatedEnumField_codec);
      repeatedMessageField_.WriteTo(ref output, _repeated_repeatedMessageField_codec);
      repeatedStringPieceField_.WriteTo(ref output, _repeated_repeatedStringPieceField_codec);
      repeatedCordField_.WriteTo(ref output, _repeated_repeatedCordField_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasPrimitiveField) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(PrimitiveField);
      }
      if (HasStringField) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(StringField);
      }
      if (HasEnumField) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumField);
      }
      if (messageField_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(MessageField);
      }
      if (HasStringPieceField) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(StringPieceField);
      }
      if (HasCordField) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(CordField);
      }
      size += repeatedPrimitiveField_.CalculateSize(_repeated_repeatedPrimitiveField_codec);
      size += repeatedStringField_.CalculateSize(_repeated_repeatedStringField_codec);
      size += repeatedEnumField_.CalculateSize(_repeated_repeatedEnumField_codec);
      size += repeatedMessageField_.CalculateSize(_repeated_repeatedMessageField_codec);
      size += repeatedStringPieceField_.CalculateSize(_repeated_repeatedStringPieceField_codec);
      size += repeatedCordField_.CalculateSize(_repeated_repeatedCordField_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestCamelCaseFieldNames other) {
      if (other == null) {
        return;
      }
      if (other.HasPrimitiveField) {
        PrimitiveField = other.PrimitiveField;
      }
      if (other.HasStringField) {
        StringField = other.StringField;
      }
      if (other.HasEnumField) {
        EnumField = other.EnumField;
      }
      if (other.messageField_ != null) {
        if (messageField_ == null) {
          MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
        }
        MessageField.MergeFrom(other.MessageField);
      }
      if (other.HasStringPieceField) {
        StringPieceField = other.StringPieceField;
      }
      if (other.HasCordField) {
        CordField = other.CordField;
      }
      repeatedPrimitiveField_.Add(other.repeatedPrimitiveField_);
      repeatedStringField_.Add(other.repeatedStringField_);
      repeatedEnumField_.Add(other.repeatedEnumField_);
      repeatedMessageField_.Add(other.repeatedMessageField_);
      repeatedStringPieceField_.Add(other.repeatedStringPieceField_);
      repeatedCordField_.Add(other.repeatedCordField_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            PrimitiveField = input.ReadInt32();
            break;
          }
          case 18: {
            StringField = input.ReadString();
            break;
          }
          case 24: {
            EnumField = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 34: {
            if (messageField_ == null) {
              MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(MessageField);
            break;
          }
          case 42: {
            StringPieceField = input.ReadString();
            break;
          }
          case 50: {
            CordField = input.ReadString();
            break;
          }
          case 58:
          case 56: {
            repeatedPrimitiveField_.AddEntriesFrom(input, _repeated_repeatedPrimitiveField_codec);
            break;
          }
          case 66: {
            repeatedStringField_.AddEntriesFrom(input, _repeated_repeatedStringField_codec);
            break;
          }
          case 74:
          case 72: {
            repeatedEnumField_.AddEntriesFrom(input, _repeated_repeatedEnumField_codec);
            break;
          }
          case 82: {
            repeatedMessageField_.AddEntriesFrom(input, _repeated_repeatedMessageField_codec);
            break;
          }
          case 90: {
            repeatedStringPieceField_.AddEntriesFrom(input, _repeated_repeatedStringPieceField_codec);
            break;
          }
          case 98: {
            repeatedCordField_.AddEntriesFrom(input, _repeated_repeatedCordField_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            PrimitiveField = input.ReadInt32();
            break;
          }
          case 18: {
            StringField = input.ReadString();
            break;
          }
          case 24: {
            EnumField = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 34: {
            if (messageField_ == null) {
              MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(MessageField);
            break;
          }
          case 42: {
            StringPieceField = input.ReadString();
            break;
          }
          case 50: {
            CordField = input.ReadString();
            break;
          }
          case 58:
          case 56: {
            repeatedPrimitiveField_.AddEntriesFrom(ref input, _repeated_repeatedPrimitiveField_codec);
            break;
          }
          case 66: {
            repeatedStringField_.AddEntriesFrom(ref input, _repeated_repeatedStringField_codec);
            break;
          }
          case 74:
          case 72: {
            repeatedEnumField_.AddEntriesFrom(ref input, _repeated_repeatedEnumField_codec);
            break;
          }
          case 82: {
            repeatedMessageField_.AddEntriesFrom(ref input, _repeated_repeatedMessageField_codec);
            break;
          }
          case 90: {
            repeatedStringPieceField_.AddEntriesFrom(ref input, _repeated_repeatedStringPieceField_codec);
            break;
          }
          case 98: {
            repeatedCordField_.AddEntriesFrom(ref input, _repeated_repeatedCordField_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// We list fields out of order, to ensure that we're using field number and not
  /// field index to determine serialization order.
  /// </summary>
  public sealed partial class TestFieldOrderings : pb::IExtendableMessage<TestFieldOrderings>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestFieldOrderings> _parser = new pb::MessageParser<TestFieldOrderings>(() => new TestFieldOrderings());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestFieldOrderings> _extensions;
    private pb::ExtensionSet<TestFieldOrderings> _Extensions { get { return _extensions; } }
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestFieldOrderings> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[29]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestFieldOrderings() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestFieldOrderings(TestFieldOrderings other) : this() {
      _hasBits0 = other._hasBits0;
      myString_ = other.myString_;
      myInt_ = other.myInt_;
      myFloat_ = other.myFloat_;
      optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestFieldOrderings Clone() {
      return new TestFieldOrderings(this);
    }

    /// <summary>Field number for the "my_string" field.</summary>
    public const int MyStringFieldNumber = 11;
    private readonly static string MyStringDefaultValue = "";

    private string myString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string MyString {
      get { return myString_ ?? MyStringDefaultValue; }
      set {
        myString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "my_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMyString {
      get { return myString_ != null; }
    }
    /// <summary>Clears the value of the "my_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMyString() {
      myString_ = null;
    }

    /// <summary>Field number for the "my_int" field.</summary>
    public const int MyIntFieldNumber = 1;
    private readonly static long MyIntDefaultValue = 0L;

    private long myInt_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long MyInt {
      get { if ((_hasBits0 & 1) != 0) { return myInt_; } else { return MyIntDefaultValue; } }
      set {
        _hasBits0 |= 1;
        myInt_ = value;
      }
    }
    /// <summary>Gets whether the "my_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMyInt {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "my_int" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMyInt() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "my_float" field.</summary>
    public const int MyFloatFieldNumber = 101;
    private readonly static float MyFloatDefaultValue = 0F;

    private float myFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float MyFloat {
      get { if ((_hasBits0 & 2) != 0) { return myFloat_; } else { return MyFloatDefaultValue; } }
      set {
        _hasBits0 |= 2;
        myFloat_ = value;
      }
    }
    /// <summary>Gets whether the "my_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMyFloat {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "my_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMyFloat() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "optional_nested_message" field.</summary>
    public const int OptionalNestedMessageFieldNumber = 200;
    private global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage optionalNestedMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage OptionalNestedMessage {
      get { return optionalNestedMessage_; }
      set {
        optionalNestedMessage_ = value;
      }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestFieldOrderings);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestFieldOrderings other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (MyString != other.MyString) return false;
      if (MyInt != other.MyInt) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(MyFloat, other.MyFloat)) return false;
      if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false;
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasMyString) hash ^= MyString.GetHashCode();
      if (HasMyInt) hash ^= MyInt.GetHashCode();
      if (HasMyFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(MyFloat);
      if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasMyInt) {
        output.WriteRawTag(8);
        output.WriteInt64(MyInt);
      }
      if (HasMyString) {
        output.WriteRawTag(90);
        output.WriteString(MyString);
      }
      if (HasMyFloat) {
        output.WriteRawTag(173, 6);
        output.WriteFloat(MyFloat);
      }
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(194, 12);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasMyInt) {
        output.WriteRawTag(8);
        output.WriteInt64(MyInt);
      }
      if (HasMyString) {
        output.WriteRawTag(90);
        output.WriteString(MyString);
      }
      if (HasMyFloat) {
        output.WriteRawTag(173, 6);
        output.WriteFloat(MyFloat);
      }
      if (optionalNestedMessage_ != null) {
        output.WriteRawTag(194, 12);
        output.WriteMessage(OptionalNestedMessage);
      }
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasMyString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(MyString);
      }
      if (HasMyInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt64Size(MyInt);
      }
      if (HasMyFloat) {
        size += 2 + 4;
      }
      if (optionalNestedMessage_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
      }
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestFieldOrderings other) {
      if (other == null) {
        return;
      }
      if (other.HasMyString) {
        MyString = other.MyString;
      }
      if (other.HasMyInt) {
        MyInt = other.MyInt;
      }
      if (other.HasMyFloat) {
        MyFloat = other.MyFloat;
      }
      if (other.optionalNestedMessage_ != null) {
        if (optionalNestedMessage_ == null) {
          OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage();
        }
        OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
          case 8: {
            MyInt = input.ReadInt64();
            break;
          }
          case 90: {
            MyString = input.ReadString();
            break;
          }
          case 813: {
            MyFloat = input.ReadFloat();
            break;
          }
          case 1602: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
          case 8: {
            MyInt = input.ReadInt64();
            break;
          }
          case 90: {
            MyString = input.ReadString();
            break;
          }
          case 813: {
            MyFloat = input.ReadFloat();
            break;
          }
          case 1602: {
            if (optionalNestedMessage_ == null) {
              OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage();
            }
            input.ReadMessage(OptionalNestedMessage);
            break;
          }
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestFieldOrderings, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestFieldOrderings, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestFieldOrderings, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestFieldOrderings, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestFieldOrderings, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestFieldOrderings, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestFieldOrderings, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

    #region Nested types
    /// <summary>Container for nested types declared in the TestFieldOrderings message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          _hasBits0 = other._hasBits0;
          oo_ = other.oo_;
          bb_ = other.bb_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "oo" field.</summary>
        public const int OoFieldNumber = 2;
        private readonly static long OoDefaultValue = 0L;

        private long oo_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public long Oo {
          get { if ((_hasBits0 & 2) != 0) { return oo_; } else { return OoDefaultValue; } }
          set {
            _hasBits0 |= 2;
            oo_ = value;
          }
        }
        /// <summary>Gets whether the "oo" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasOo {
          get { return (_hasBits0 & 2) != 0; }
        }
        /// <summary>Clears the value of the "oo" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearOo() {
          _hasBits0 &= ~2;
        }

        /// <summary>Field number for the "bb" field.</summary>
        public const int BbFieldNumber = 1;
        private readonly static int BbDefaultValue = 0;

        private int bb_;
        /// <summary>
        /// The field name "b" fails to compile in proto1 because it conflicts with
        /// a local variable named "b" in one of the generated methods.  Doh.
        /// This file needs to compile in proto1 to test backwards-compatibility.
        /// </summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int Bb {
          get { if ((_hasBits0 & 1) != 0) { return bb_; } else { return BbDefaultValue; } }
          set {
            _hasBits0 |= 1;
            bb_ = value;
          }
        }
        /// <summary>Gets whether the "bb" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasBb {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "bb" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearBb() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (Oo != other.Oo) return false;
          if (Bb != other.Bb) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasOo) hash ^= Oo.GetHashCode();
          if (HasBb) hash ^= Bb.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasBb) {
            output.WriteRawTag(8);
            output.WriteInt32(Bb);
          }
          if (HasOo) {
            output.WriteRawTag(16);
            output.WriteInt64(Oo);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasBb) {
            output.WriteRawTag(8);
            output.WriteInt32(Bb);
          }
          if (HasOo) {
            output.WriteRawTag(16);
            output.WriteInt64(Oo);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasOo) {
            size += 1 + pb::CodedOutputStream.ComputeInt64Size(Oo);
          }
          if (HasBb) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(Bb);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasOo) {
            Oo = other.Oo;
          }
          if (other.HasBb) {
            Bb = other.Bb;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                Bb = input.ReadInt32();
                break;
              }
              case 16: {
                Oo = input.ReadInt64();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                Bb = input.ReadInt32();
                break;
              }
              case 16: {
                Oo = input.ReadInt64();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestExtensionOrderings1 : pb::IMessage<TestExtensionOrderings1>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestExtensionOrderings1> _parser = new pb::MessageParser<TestExtensionOrderings1>(() => new TestExtensionOrderings1());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestExtensionOrderings1> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[30]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings1() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings1(TestExtensionOrderings1 other) : this() {
      myString_ = other.myString_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings1 Clone() {
      return new TestExtensionOrderings1(this);
    }

    /// <summary>Field number for the "my_string" field.</summary>
    public const int MyStringFieldNumber = 1;
    private readonly static string MyStringDefaultValue = "";

    private string myString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string MyString {
      get { return myString_ ?? MyStringDefaultValue; }
      set {
        myString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "my_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMyString {
      get { return myString_ != null; }
    }
    /// <summary>Clears the value of the "my_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMyString() {
      myString_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestExtensionOrderings1);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestExtensionOrderings1 other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (MyString != other.MyString) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasMyString) hash ^= MyString.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasMyString) {
        output.WriteRawTag(10);
        output.WriteString(MyString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasMyString) {
        output.WriteRawTag(10);
        output.WriteString(MyString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasMyString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(MyString);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestExtensionOrderings1 other) {
      if (other == null) {
        return;
      }
      if (other.HasMyString) {
        MyString = other.MyString;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            MyString = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            MyString = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestExtensionOrderings1 message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Extensions {
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1> TestExtOrderings1 =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1>(13, pb::FieldCodec.ForMessage(106, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings1.Parser));
    }
    #endregion

  }

  public sealed partial class TestExtensionOrderings2 : pb::IMessage<TestExtensionOrderings2>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestExtensionOrderings2> _parser = new pb::MessageParser<TestExtensionOrderings2>(() => new TestExtensionOrderings2());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestExtensionOrderings2> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[31]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings2() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings2(TestExtensionOrderings2 other) : this() {
      myString_ = other.myString_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionOrderings2 Clone() {
      return new TestExtensionOrderings2(this);
    }

    /// <summary>Field number for the "my_string" field.</summary>
    public const int MyStringFieldNumber = 1;
    private readonly static string MyStringDefaultValue = "";

    private string myString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string MyString {
      get { return myString_ ?? MyStringDefaultValue; }
      set {
        myString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "my_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMyString {
      get { return myString_ != null; }
    }
    /// <summary>Clears the value of the "my_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMyString() {
      myString_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestExtensionOrderings2);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestExtensionOrderings2 other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (MyString != other.MyString) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasMyString) hash ^= MyString.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasMyString) {
        output.WriteRawTag(10);
        output.WriteString(MyString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasMyString) {
        output.WriteRawTag(10);
        output.WriteString(MyString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasMyString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(MyString);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestExtensionOrderings2 other) {
      if (other == null) {
        return;
      }
      if (other.HasMyString) {
        MyString = other.MyString;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            MyString = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            MyString = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestExtensionOrderings2 message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class TestExtensionOrderings3 : pb::IMessage<TestExtensionOrderings3>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<TestExtensionOrderings3> _parser = new pb::MessageParser<TestExtensionOrderings3>(() => new TestExtensionOrderings3());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<TestExtensionOrderings3> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public TestExtensionOrderings3() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public TestExtensionOrderings3(TestExtensionOrderings3 other) : this() {
          myString_ = other.myString_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public TestExtensionOrderings3 Clone() {
          return new TestExtensionOrderings3(this);
        }

        /// <summary>Field number for the "my_string" field.</summary>
        public const int MyStringFieldNumber = 1;
        private readonly static string MyStringDefaultValue = "";

        private string myString_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public string MyString {
          get { return myString_ ?? MyStringDefaultValue; }
          set {
            myString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
          }
        }
        /// <summary>Gets whether the "my_string" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasMyString {
          get { return myString_ != null; }
        }
        /// <summary>Clears the value of the "my_string" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearMyString() {
          myString_ = null;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as TestExtensionOrderings3);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(TestExtensionOrderings3 other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (MyString != other.MyString) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasMyString) hash ^= MyString.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasMyString) {
            output.WriteRawTag(10);
            output.WriteString(MyString);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasMyString) {
            output.WriteRawTag(10);
            output.WriteString(MyString);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasMyString) {
            size += 1 + pb::CodedOutputStream.ComputeStringSize(MyString);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(TestExtensionOrderings3 other) {
          if (other == null) {
            return;
          }
          if (other.HasMyString) {
            MyString = other.MyString;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 10: {
                MyString = input.ReadString();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 10: {
                MyString = input.ReadString();
                break;
              }
            }
          }
        }
        #endif

        #region Extensions
        /// <summary>Container for extensions for other messages declared in the TestExtensionOrderings3 message type.</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static partial class Extensions {
          public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3> TestExtOrderings3 =
            new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3>(14, pb::FieldCodec.ForMessage(114, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Types.TestExtensionOrderings3.Parser));
        }
        #endregion

      }

    }
    #endregion

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestExtensionOrderings2 message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Extensions {
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2> TestExtOrderings2 =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2>(12, pb::FieldCodec.ForMessage(98, global::Google.Protobuf.TestProtos.Proto2.TestExtensionOrderings2.Parser));
    }
    #endregion

  }

  public sealed partial class TestExtremeDefaultValues : pb::IMessage<TestExtremeDefaultValues>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestExtremeDefaultValues> _parser = new pb::MessageParser<TestExtremeDefaultValues>(() => new TestExtremeDefaultValues());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestExtremeDefaultValues> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[32]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtremeDefaultValues() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtremeDefaultValues(TestExtremeDefaultValues other) : this() {
      _hasBits0 = other._hasBits0;
      escapedBytes_ = other.escapedBytes_;
      largeUint32_ = other.largeUint32_;
      largeUint64_ = other.largeUint64_;
      smallInt32_ = other.smallInt32_;
      smallInt64_ = other.smallInt64_;
      reallySmallInt32_ = other.reallySmallInt32_;
      reallySmallInt64_ = other.reallySmallInt64_;
      utf8String_ = other.utf8String_;
      zeroFloat_ = other.zeroFloat_;
      oneFloat_ = other.oneFloat_;
      smallFloat_ = other.smallFloat_;
      negativeOneFloat_ = other.negativeOneFloat_;
      negativeFloat_ = other.negativeFloat_;
      largeFloat_ = other.largeFloat_;
      smallNegativeFloat_ = other.smallNegativeFloat_;
      infDouble_ = other.infDouble_;
      negInfDouble_ = other.negInfDouble_;
      nanDouble_ = other.nanDouble_;
      infFloat_ = other.infFloat_;
      negInfFloat_ = other.negInfFloat_;
      nanFloat_ = other.nanFloat_;
      cppTrigraph_ = other.cppTrigraph_;
      stringWithZero_ = other.stringWithZero_;
      bytesWithZero_ = other.bytesWithZero_;
      stringPieceWithZero_ = other.stringPieceWithZero_;
      cordWithZero_ = other.cordWithZero_;
      replacementString_ = other.replacementString_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtremeDefaultValues Clone() {
      return new TestExtremeDefaultValues(this);
    }

    /// <summary>Field number for the "escaped_bytes" field.</summary>
    public const int EscapedBytesFieldNumber = 1;
    private readonly static pb::ByteString EscapedBytesDefaultValue = pb::ByteString.FromBase64("AAEHCAwKDQkLXCci/g==");

    private pb::ByteString escapedBytes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString EscapedBytes {
      get { return escapedBytes_ ?? EscapedBytesDefaultValue; }
      set {
        escapedBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "escaped_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasEscapedBytes {
      get { return escapedBytes_ != null; }
    }
    /// <summary>Clears the value of the "escaped_bytes" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearEscapedBytes() {
      escapedBytes_ = null;
    }

    /// <summary>Field number for the "large_uint32" field.</summary>
    public const int LargeUint32FieldNumber = 2;
    private readonly static uint LargeUint32DefaultValue = 4294967295;

    private uint largeUint32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint LargeUint32 {
      get { if ((_hasBits0 & 1) != 0) { return largeUint32_; } else { return LargeUint32DefaultValue; } }
      set {
        _hasBits0 |= 1;
        largeUint32_ = value;
      }
    }
    /// <summary>Gets whether the "large_uint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasLargeUint32 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "large_uint32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearLargeUint32() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "large_uint64" field.</summary>
    public const int LargeUint64FieldNumber = 3;
    private readonly static ulong LargeUint64DefaultValue = 18446744073709551615UL;

    private ulong largeUint64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong LargeUint64 {
      get { if ((_hasBits0 & 2) != 0) { return largeUint64_; } else { return LargeUint64DefaultValue; } }
      set {
        _hasBits0 |= 2;
        largeUint64_ = value;
      }
    }
    /// <summary>Gets whether the "large_uint64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasLargeUint64 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "large_uint64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearLargeUint64() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "small_int32" field.</summary>
    public const int SmallInt32FieldNumber = 4;
    private readonly static int SmallInt32DefaultValue = -2147483647;

    private int smallInt32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int SmallInt32 {
      get { if ((_hasBits0 & 4) != 0) { return smallInt32_; } else { return SmallInt32DefaultValue; } }
      set {
        _hasBits0 |= 4;
        smallInt32_ = value;
      }
    }
    /// <summary>Gets whether the "small_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSmallInt32 {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "small_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSmallInt32() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "small_int64" field.</summary>
    public const int SmallInt64FieldNumber = 5;
    private readonly static long SmallInt64DefaultValue = -9223372036854775807L;

    private long smallInt64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long SmallInt64 {
      get { if ((_hasBits0 & 8) != 0) { return smallInt64_; } else { return SmallInt64DefaultValue; } }
      set {
        _hasBits0 |= 8;
        smallInt64_ = value;
      }
    }
    /// <summary>Gets whether the "small_int64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSmallInt64 {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "small_int64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSmallInt64() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "really_small_int32" field.</summary>
    public const int ReallySmallInt32FieldNumber = 21;
    private readonly static int ReallySmallInt32DefaultValue = -2147483648;

    private int reallySmallInt32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int ReallySmallInt32 {
      get { if ((_hasBits0 & 131072) != 0) { return reallySmallInt32_; } else { return ReallySmallInt32DefaultValue; } }
      set {
        _hasBits0 |= 131072;
        reallySmallInt32_ = value;
      }
    }
    /// <summary>Gets whether the "really_small_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasReallySmallInt32 {
      get { return (_hasBits0 & 131072) != 0; }
    }
    /// <summary>Clears the value of the "really_small_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearReallySmallInt32() {
      _hasBits0 &= ~131072;
    }

    /// <summary>Field number for the "really_small_int64" field.</summary>
    public const int ReallySmallInt64FieldNumber = 22;
    private readonly static long ReallySmallInt64DefaultValue = -9223372036854775808L;

    private long reallySmallInt64_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long ReallySmallInt64 {
      get { if ((_hasBits0 & 262144) != 0) { return reallySmallInt64_; } else { return ReallySmallInt64DefaultValue; } }
      set {
        _hasBits0 |= 262144;
        reallySmallInt64_ = value;
      }
    }
    /// <summary>Gets whether the "really_small_int64" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasReallySmallInt64 {
      get { return (_hasBits0 & 262144) != 0; }
    }
    /// <summary>Clears the value of the "really_small_int64" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearReallySmallInt64() {
      _hasBits0 &= ~262144;
    }

    /// <summary>Field number for the "utf8_string" field.</summary>
    public const int Utf8StringFieldNumber = 6;
    private readonly static string Utf8StringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("4Yi0"), 0, 3);

    private string utf8String_;
    /// <summary>
    /// The default value here is UTF-8 for "\u1234".  (We could also just type
    /// the UTF-8 text directly into this text file rather than escape it, but
    /// lots of people use editors that would be confused by this.)
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string Utf8String {
      get { return utf8String_ ?? Utf8StringDefaultValue; }
      set {
        utf8String_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "utf8_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasUtf8String {
      get { return utf8String_ != null; }
    }
    /// <summary>Clears the value of the "utf8_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearUtf8String() {
      utf8String_ = null;
    }

    /// <summary>Field number for the "zero_float" field.</summary>
    public const int ZeroFloatFieldNumber = 7;
    private readonly static float ZeroFloatDefaultValue = 0F;

    private float zeroFloat_;
    /// <summary>
    /// Tests for single-precision floating-point values.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float ZeroFloat {
      get { if ((_hasBits0 & 16) != 0) { return zeroFloat_; } else { return ZeroFloatDefaultValue; } }
      set {
        _hasBits0 |= 16;
        zeroFloat_ = value;
      }
    }
    /// <summary>Gets whether the "zero_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasZeroFloat {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "zero_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearZeroFloat() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "one_float" field.</summary>
    public const int OneFloatFieldNumber = 8;
    private readonly static float OneFloatDefaultValue = 1F;

    private float oneFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float OneFloat {
      get { if ((_hasBits0 & 32) != 0) { return oneFloat_; } else { return OneFloatDefaultValue; } }
      set {
        _hasBits0 |= 32;
        oneFloat_ = value;
      }
    }
    /// <summary>Gets whether the "one_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneFloat {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "one_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneFloat() {
      _hasBits0 &= ~32;
    }

    /// <summary>Field number for the "small_float" field.</summary>
    public const int SmallFloatFieldNumber = 9;
    private readonly static float SmallFloatDefaultValue = 1.5F;

    private float smallFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float SmallFloat {
      get { if ((_hasBits0 & 64) != 0) { return smallFloat_; } else { return SmallFloatDefaultValue; } }
      set {
        _hasBits0 |= 64;
        smallFloat_ = value;
      }
    }
    /// <summary>Gets whether the "small_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSmallFloat {
      get { return (_hasBits0 & 64) != 0; }
    }
    /// <summary>Clears the value of the "small_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSmallFloat() {
      _hasBits0 &= ~64;
    }

    /// <summary>Field number for the "negative_one_float" field.</summary>
    public const int NegativeOneFloatFieldNumber = 10;
    private readonly static float NegativeOneFloatDefaultValue = -1F;

    private float negativeOneFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float NegativeOneFloat {
      get { if ((_hasBits0 & 128) != 0) { return negativeOneFloat_; } else { return NegativeOneFloatDefaultValue; } }
      set {
        _hasBits0 |= 128;
        negativeOneFloat_ = value;
      }
    }
    /// <summary>Gets whether the "negative_one_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNegativeOneFloat {
      get { return (_hasBits0 & 128) != 0; }
    }
    /// <summary>Clears the value of the "negative_one_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNegativeOneFloat() {
      _hasBits0 &= ~128;
    }

    /// <summary>Field number for the "negative_float" field.</summary>
    public const int NegativeFloatFieldNumber = 11;
    private readonly static float NegativeFloatDefaultValue = -1.5F;

    private float negativeFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float NegativeFloat {
      get { if ((_hasBits0 & 256) != 0) { return negativeFloat_; } else { return NegativeFloatDefaultValue; } }
      set {
        _hasBits0 |= 256;
        negativeFloat_ = value;
      }
    }
    /// <summary>Gets whether the "negative_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNegativeFloat {
      get { return (_hasBits0 & 256) != 0; }
    }
    /// <summary>Clears the value of the "negative_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNegativeFloat() {
      _hasBits0 &= ~256;
    }

    /// <summary>Field number for the "large_float" field.</summary>
    public const int LargeFloatFieldNumber = 12;
    private readonly static float LargeFloatDefaultValue = 2e+08F;

    private float largeFloat_;
    /// <summary>
    /// Using exponents
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float LargeFloat {
      get { if ((_hasBits0 & 512) != 0) { return largeFloat_; } else { return LargeFloatDefaultValue; } }
      set {
        _hasBits0 |= 512;
        largeFloat_ = value;
      }
    }
    /// <summary>Gets whether the "large_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasLargeFloat {
      get { return (_hasBits0 & 512) != 0; }
    }
    /// <summary>Clears the value of the "large_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearLargeFloat() {
      _hasBits0 &= ~512;
    }

    /// <summary>Field number for the "small_negative_float" field.</summary>
    public const int SmallNegativeFloatFieldNumber = 13;
    private readonly static float SmallNegativeFloatDefaultValue = -8e-28F;

    private float smallNegativeFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float SmallNegativeFloat {
      get { if ((_hasBits0 & 1024) != 0) { return smallNegativeFloat_; } else { return SmallNegativeFloatDefaultValue; } }
      set {
        _hasBits0 |= 1024;
        smallNegativeFloat_ = value;
      }
    }
    /// <summary>Gets whether the "small_negative_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSmallNegativeFloat {
      get { return (_hasBits0 & 1024) != 0; }
    }
    /// <summary>Clears the value of the "small_negative_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSmallNegativeFloat() {
      _hasBits0 &= ~1024;
    }

    /// <summary>Field number for the "inf_double" field.</summary>
    public const int InfDoubleFieldNumber = 14;
    private readonly static double InfDoubleDefaultValue = double.PositiveInfinity;

    private double infDouble_;
    /// <summary>
    /// Text for nonfinite floating-point values.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public double InfDouble {
      get { if ((_hasBits0 & 2048) != 0) { return infDouble_; } else { return InfDoubleDefaultValue; } }
      set {
        _hasBits0 |= 2048;
        infDouble_ = value;
      }
    }
    /// <summary>Gets whether the "inf_double" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasInfDouble {
      get { return (_hasBits0 & 2048) != 0; }
    }
    /// <summary>Clears the value of the "inf_double" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearInfDouble() {
      _hasBits0 &= ~2048;
    }

    /// <summary>Field number for the "neg_inf_double" field.</summary>
    public const int NegInfDoubleFieldNumber = 15;
    private readonly static double NegInfDoubleDefaultValue = double.NegativeInfinity;

    private double negInfDouble_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public double NegInfDouble {
      get { if ((_hasBits0 & 4096) != 0) { return negInfDouble_; } else { return NegInfDoubleDefaultValue; } }
      set {
        _hasBits0 |= 4096;
        negInfDouble_ = value;
      }
    }
    /// <summary>Gets whether the "neg_inf_double" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNegInfDouble {
      get { return (_hasBits0 & 4096) != 0; }
    }
    /// <summary>Clears the value of the "neg_inf_double" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNegInfDouble() {
      _hasBits0 &= ~4096;
    }

    /// <summary>Field number for the "nan_double" field.</summary>
    public const int NanDoubleFieldNumber = 16;
    private readonly static double NanDoubleDefaultValue = double.NaN;

    private double nanDouble_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public double NanDouble {
      get { if ((_hasBits0 & 8192) != 0) { return nanDouble_; } else { return NanDoubleDefaultValue; } }
      set {
        _hasBits0 |= 8192;
        nanDouble_ = value;
      }
    }
    /// <summary>Gets whether the "nan_double" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNanDouble {
      get { return (_hasBits0 & 8192) != 0; }
    }
    /// <summary>Clears the value of the "nan_double" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNanDouble() {
      _hasBits0 &= ~8192;
    }

    /// <summary>Field number for the "inf_float" field.</summary>
    public const int InfFloatFieldNumber = 17;
    private readonly static float InfFloatDefaultValue = float.PositiveInfinity;

    private float infFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float InfFloat {
      get { if ((_hasBits0 & 16384) != 0) { return infFloat_; } else { return InfFloatDefaultValue; } }
      set {
        _hasBits0 |= 16384;
        infFloat_ = value;
      }
    }
    /// <summary>Gets whether the "inf_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasInfFloat {
      get { return (_hasBits0 & 16384) != 0; }
    }
    /// <summary>Clears the value of the "inf_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearInfFloat() {
      _hasBits0 &= ~16384;
    }

    /// <summary>Field number for the "neg_inf_float" field.</summary>
    public const int NegInfFloatFieldNumber = 18;
    private readonly static float NegInfFloatDefaultValue = float.NegativeInfinity;

    private float negInfFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float NegInfFloat {
      get { if ((_hasBits0 & 32768) != 0) { return negInfFloat_; } else { return NegInfFloatDefaultValue; } }
      set {
        _hasBits0 |= 32768;
        negInfFloat_ = value;
      }
    }
    /// <summary>Gets whether the "neg_inf_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNegInfFloat {
      get { return (_hasBits0 & 32768) != 0; }
    }
    /// <summary>Clears the value of the "neg_inf_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNegInfFloat() {
      _hasBits0 &= ~32768;
    }

    /// <summary>Field number for the "nan_float" field.</summary>
    public const int NanFloatFieldNumber = 19;
    private readonly static float NanFloatDefaultValue = float.NaN;

    private float nanFloat_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public float NanFloat {
      get { if ((_hasBits0 & 65536) != 0) { return nanFloat_; } else { return NanFloatDefaultValue; } }
      set {
        _hasBits0 |= 65536;
        nanFloat_ = value;
      }
    }
    /// <summary>Gets whether the "nan_float" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasNanFloat {
      get { return (_hasBits0 & 65536) != 0; }
    }
    /// <summary>Clears the value of the "nan_float" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearNanFloat() {
      _hasBits0 &= ~65536;
    }

    /// <summary>Field number for the "cpp_trigraph" field.</summary>
    public const int CppTrigraphFieldNumber = 20;
    private readonly static string CppTrigraphDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PyA/ID8/ID8/ID8/PyA/Py8gPz8t"), 0, 21);

    private string cppTrigraph_;
    /// <summary>
    /// Tests for C++ trigraphs.
    /// Trigraphs should be escaped in C++ generated files, but they should not be
    /// escaped for other languages.
    /// Note that in .proto file, "\?" is a valid way to escape ? in string
    /// literals.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string CppTrigraph {
      get { return cppTrigraph_ ?? CppTrigraphDefaultValue; }
      set {
        cppTrigraph_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "cpp_trigraph" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasCppTrigraph {
      get { return cppTrigraph_ != null; }
    }
    /// <summary>Clears the value of the "cpp_trigraph" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearCppTrigraph() {
      cppTrigraph_ = null;
    }

    /// <summary>Field number for the "string_with_zero" field.</summary>
    public const int StringWithZeroFieldNumber = 23;
    private readonly static string StringWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsAGxv"), 0, 6);

    private string stringWithZero_;
    /// <summary>
    /// String defaults containing the character '\000'
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string StringWithZero {
      get { return stringWithZero_ ?? StringWithZeroDefaultValue; }
      set {
        stringWithZero_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "string_with_zero" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasStringWithZero {
      get { return stringWithZero_ != null; }
    }
    /// <summary>Clears the value of the "string_with_zero" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearStringWithZero() {
      stringWithZero_ = null;
    }

    /// <summary>Field number for the "bytes_with_zero" field.</summary>
    public const int BytesWithZeroFieldNumber = 24;
    private readonly static pb::ByteString BytesWithZeroDefaultValue = pb::ByteString.FromBase64("d29yAGxk");

    private pb::ByteString bytesWithZero_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString BytesWithZero {
      get { return bytesWithZero_ ?? BytesWithZeroDefaultValue; }
      set {
        bytesWithZero_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "bytes_with_zero" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBytesWithZero {
      get { return bytesWithZero_ != null; }
    }
    /// <summary>Clears the value of the "bytes_with_zero" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBytesWithZero() {
      bytesWithZero_ = null;
    }

    /// <summary>Field number for the "string_piece_with_zero" field.</summary>
    public const int StringPieceWithZeroFieldNumber = 25;
    private readonly static string StringPieceWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWIAYw=="), 0, 4);

    private string stringPieceWithZero_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string StringPieceWithZero {
      get { return stringPieceWithZero_ ?? StringPieceWithZeroDefaultValue; }
      set {
        stringPieceWithZero_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "string_piece_with_zero" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasStringPieceWithZero {
      get { return stringPieceWithZero_ != null; }
    }
    /// <summary>Clears the value of the "string_piece_with_zero" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearStringPieceWithZero() {
      stringPieceWithZero_ = null;
    }

    /// <summary>Field number for the "cord_with_zero" field.</summary>
    public const int CordWithZeroFieldNumber = 26;
    private readonly static string CordWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIAMw=="), 0, 4);

    private string cordWithZero_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string CordWithZero {
      get { return cordWithZero_ ?? CordWithZeroDefaultValue; }
      set {
        cordWithZero_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "cord_with_zero" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasCordWithZero {
      get { return cordWithZero_ != null; }
    }
    /// <summary>Clears the value of the "cord_with_zero" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearCordWithZero() {
      cordWithZero_ = null;
    }

    /// <summary>Field number for the "replacement_string" field.</summary>
    public const int ReplacementStringFieldNumber = 27;
    private readonly static string ReplacementStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("JHt1bmtub3dufQ=="), 0, 10);

    private string replacementString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string ReplacementString {
      get { return replacementString_ ?? ReplacementStringDefaultValue; }
      set {
        replacementString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "replacement_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasReplacementString {
      get { return replacementString_ != null; }
    }
    /// <summary>Clears the value of the "replacement_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearReplacementString() {
      replacementString_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestExtremeDefaultValues);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestExtremeDefaultValues other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (EscapedBytes != other.EscapedBytes) return false;
      if (LargeUint32 != other.LargeUint32) return false;
      if (LargeUint64 != other.LargeUint64) return false;
      if (SmallInt32 != other.SmallInt32) return false;
      if (SmallInt64 != other.SmallInt64) return false;
      if (ReallySmallInt32 != other.ReallySmallInt32) return false;
      if (ReallySmallInt64 != other.ReallySmallInt64) return false;
      if (Utf8String != other.Utf8String) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(ZeroFloat, other.ZeroFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(OneFloat, other.OneFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(SmallFloat, other.SmallFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(NegativeOneFloat, other.NegativeOneFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(NegativeFloat, other.NegativeFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(LargeFloat, other.LargeFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(SmallNegativeFloat, other.SmallNegativeFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(InfDouble, other.InfDouble)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(NegInfDouble, other.NegInfDouble)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(NanDouble, other.NanDouble)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(InfFloat, other.InfFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(NegInfFloat, other.NegInfFloat)) return false;
      if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(NanFloat, other.NanFloat)) return false;
      if (CppTrigraph != other.CppTrigraph) return false;
      if (StringWithZero != other.StringWithZero) return false;
      if (BytesWithZero != other.BytesWithZero) return false;
      if (StringPieceWithZero != other.StringPieceWithZero) return false;
      if (CordWithZero != other.CordWithZero) return false;
      if (ReplacementString != other.ReplacementString) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasEscapedBytes) hash ^= EscapedBytes.GetHashCode();
      if (HasLargeUint32) hash ^= LargeUint32.GetHashCode();
      if (HasLargeUint64) hash ^= LargeUint64.GetHashCode();
      if (HasSmallInt32) hash ^= SmallInt32.GetHashCode();
      if (HasSmallInt64) hash ^= SmallInt64.GetHashCode();
      if (HasReallySmallInt32) hash ^= ReallySmallInt32.GetHashCode();
      if (HasReallySmallInt64) hash ^= ReallySmallInt64.GetHashCode();
      if (HasUtf8String) hash ^= Utf8String.GetHashCode();
      if (HasZeroFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(ZeroFloat);
      if (HasOneFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(OneFloat);
      if (HasSmallFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(SmallFloat);
      if (HasNegativeOneFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(NegativeOneFloat);
      if (HasNegativeFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(NegativeFloat);
      if (HasLargeFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(LargeFloat);
      if (HasSmallNegativeFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(SmallNegativeFloat);
      if (HasInfDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(InfDouble);
      if (HasNegInfDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(NegInfDouble);
      if (HasNanDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(NanDouble);
      if (HasInfFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(InfFloat);
      if (HasNegInfFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(NegInfFloat);
      if (HasNanFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(NanFloat);
      if (HasCppTrigraph) hash ^= CppTrigraph.GetHashCode();
      if (HasStringWithZero) hash ^= StringWithZero.GetHashCode();
      if (HasBytesWithZero) hash ^= BytesWithZero.GetHashCode();
      if (HasStringPieceWithZero) hash ^= StringPieceWithZero.GetHashCode();
      if (HasCordWithZero) hash ^= CordWithZero.GetHashCode();
      if (HasReplacementString) hash ^= ReplacementString.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasEscapedBytes) {
        output.WriteRawTag(10);
        output.WriteBytes(EscapedBytes);
      }
      if (HasLargeUint32) {
        output.WriteRawTag(16);
        output.WriteUInt32(LargeUint32);
      }
      if (HasLargeUint64) {
        output.WriteRawTag(24);
        output.WriteUInt64(LargeUint64);
      }
      if (HasSmallInt32) {
        output.WriteRawTag(32);
        output.WriteInt32(SmallInt32);
      }
      if (HasSmallInt64) {
        output.WriteRawTag(40);
        output.WriteInt64(SmallInt64);
      }
      if (HasUtf8String) {
        output.WriteRawTag(50);
        output.WriteString(Utf8String);
      }
      if (HasZeroFloat) {
        output.WriteRawTag(61);
        output.WriteFloat(ZeroFloat);
      }
      if (HasOneFloat) {
        output.WriteRawTag(69);
        output.WriteFloat(OneFloat);
      }
      if (HasSmallFloat) {
        output.WriteRawTag(77);
        output.WriteFloat(SmallFloat);
      }
      if (HasNegativeOneFloat) {
        output.WriteRawTag(85);
        output.WriteFloat(NegativeOneFloat);
      }
      if (HasNegativeFloat) {
        output.WriteRawTag(93);
        output.WriteFloat(NegativeFloat);
      }
      if (HasLargeFloat) {
        output.WriteRawTag(101);
        output.WriteFloat(LargeFloat);
      }
      if (HasSmallNegativeFloat) {
        output.WriteRawTag(109);
        output.WriteFloat(SmallNegativeFloat);
      }
      if (HasInfDouble) {
        output.WriteRawTag(113);
        output.WriteDouble(InfDouble);
      }
      if (HasNegInfDouble) {
        output.WriteRawTag(121);
        output.WriteDouble(NegInfDouble);
      }
      if (HasNanDouble) {
        output.WriteRawTag(129, 1);
        output.WriteDouble(NanDouble);
      }
      if (HasInfFloat) {
        output.WriteRawTag(141, 1);
        output.WriteFloat(InfFloat);
      }
      if (HasNegInfFloat) {
        output.WriteRawTag(149, 1);
        output.WriteFloat(NegInfFloat);
      }
      if (HasNanFloat) {
        output.WriteRawTag(157, 1);
        output.WriteFloat(NanFloat);
      }
      if (HasCppTrigraph) {
        output.WriteRawTag(162, 1);
        output.WriteString(CppTrigraph);
      }
      if (HasReallySmallInt32) {
        output.WriteRawTag(168, 1);
        output.WriteInt32(ReallySmallInt32);
      }
      if (HasReallySmallInt64) {
        output.WriteRawTag(176, 1);
        output.WriteInt64(ReallySmallInt64);
      }
      if (HasStringWithZero) {
        output.WriteRawTag(186, 1);
        output.WriteString(StringWithZero);
      }
      if (HasBytesWithZero) {
        output.WriteRawTag(194, 1);
        output.WriteBytes(BytesWithZero);
      }
      if (HasStringPieceWithZero) {
        output.WriteRawTag(202, 1);
        output.WriteString(StringPieceWithZero);
      }
      if (HasCordWithZero) {
        output.WriteRawTag(210, 1);
        output.WriteString(CordWithZero);
      }
      if (HasReplacementString) {
        output.WriteRawTag(218, 1);
        output.WriteString(ReplacementString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasEscapedBytes) {
        output.WriteRawTag(10);
        output.WriteBytes(EscapedBytes);
      }
      if (HasLargeUint32) {
        output.WriteRawTag(16);
        output.WriteUInt32(LargeUint32);
      }
      if (HasLargeUint64) {
        output.WriteRawTag(24);
        output.WriteUInt64(LargeUint64);
      }
      if (HasSmallInt32) {
        output.WriteRawTag(32);
        output.WriteInt32(SmallInt32);
      }
      if (HasSmallInt64) {
        output.WriteRawTag(40);
        output.WriteInt64(SmallInt64);
      }
      if (HasUtf8String) {
        output.WriteRawTag(50);
        output.WriteString(Utf8String);
      }
      if (HasZeroFloat) {
        output.WriteRawTag(61);
        output.WriteFloat(ZeroFloat);
      }
      if (HasOneFloat) {
        output.WriteRawTag(69);
        output.WriteFloat(OneFloat);
      }
      if (HasSmallFloat) {
        output.WriteRawTag(77);
        output.WriteFloat(SmallFloat);
      }
      if (HasNegativeOneFloat) {
        output.WriteRawTag(85);
        output.WriteFloat(NegativeOneFloat);
      }
      if (HasNegativeFloat) {
        output.WriteRawTag(93);
        output.WriteFloat(NegativeFloat);
      }
      if (HasLargeFloat) {
        output.WriteRawTag(101);
        output.WriteFloat(LargeFloat);
      }
      if (HasSmallNegativeFloat) {
        output.WriteRawTag(109);
        output.WriteFloat(SmallNegativeFloat);
      }
      if (HasInfDouble) {
        output.WriteRawTag(113);
        output.WriteDouble(InfDouble);
      }
      if (HasNegInfDouble) {
        output.WriteRawTag(121);
        output.WriteDouble(NegInfDouble);
      }
      if (HasNanDouble) {
        output.WriteRawTag(129, 1);
        output.WriteDouble(NanDouble);
      }
      if (HasInfFloat) {
        output.WriteRawTag(141, 1);
        output.WriteFloat(InfFloat);
      }
      if (HasNegInfFloat) {
        output.WriteRawTag(149, 1);
        output.WriteFloat(NegInfFloat);
      }
      if (HasNanFloat) {
        output.WriteRawTag(157, 1);
        output.WriteFloat(NanFloat);
      }
      if (HasCppTrigraph) {
        output.WriteRawTag(162, 1);
        output.WriteString(CppTrigraph);
      }
      if (HasReallySmallInt32) {
        output.WriteRawTag(168, 1);
        output.WriteInt32(ReallySmallInt32);
      }
      if (HasReallySmallInt64) {
        output.WriteRawTag(176, 1);
        output.WriteInt64(ReallySmallInt64);
      }
      if (HasStringWithZero) {
        output.WriteRawTag(186, 1);
        output.WriteString(StringWithZero);
      }
      if (HasBytesWithZero) {
        output.WriteRawTag(194, 1);
        output.WriteBytes(BytesWithZero);
      }
      if (HasStringPieceWithZero) {
        output.WriteRawTag(202, 1);
        output.WriteString(StringPieceWithZero);
      }
      if (HasCordWithZero) {
        output.WriteRawTag(210, 1);
        output.WriteString(CordWithZero);
      }
      if (HasReplacementString) {
        output.WriteRawTag(218, 1);
        output.WriteString(ReplacementString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasEscapedBytes) {
        size += 1 + pb::CodedOutputStream.ComputeBytesSize(EscapedBytes);
      }
      if (HasLargeUint32) {
        size += 1 + pb::CodedOutputStream.ComputeUInt32Size(LargeUint32);
      }
      if (HasLargeUint64) {
        size += 1 + pb::CodedOutputStream.ComputeUInt64Size(LargeUint64);
      }
      if (HasSmallInt32) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(SmallInt32);
      }
      if (HasSmallInt64) {
        size += 1 + pb::CodedOutputStream.ComputeInt64Size(SmallInt64);
      }
      if (HasReallySmallInt32) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(ReallySmallInt32);
      }
      if (HasReallySmallInt64) {
        size += 2 + pb::CodedOutputStream.ComputeInt64Size(ReallySmallInt64);
      }
      if (HasUtf8String) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(Utf8String);
      }
      if (HasZeroFloat) {
        size += 1 + 4;
      }
      if (HasOneFloat) {
        size += 1 + 4;
      }
      if (HasSmallFloat) {
        size += 1 + 4;
      }
      if (HasNegativeOneFloat) {
        size += 1 + 4;
      }
      if (HasNegativeFloat) {
        size += 1 + 4;
      }
      if (HasLargeFloat) {
        size += 1 + 4;
      }
      if (HasSmallNegativeFloat) {
        size += 1 + 4;
      }
      if (HasInfDouble) {
        size += 1 + 8;
      }
      if (HasNegInfDouble) {
        size += 1 + 8;
      }
      if (HasNanDouble) {
        size += 2 + 8;
      }
      if (HasInfFloat) {
        size += 2 + 4;
      }
      if (HasNegInfFloat) {
        size += 2 + 4;
      }
      if (HasNanFloat) {
        size += 2 + 4;
      }
      if (HasCppTrigraph) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(CppTrigraph);
      }
      if (HasStringWithZero) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(StringWithZero);
      }
      if (HasBytesWithZero) {
        size += 2 + pb::CodedOutputStream.ComputeBytesSize(BytesWithZero);
      }
      if (HasStringPieceWithZero) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(StringPieceWithZero);
      }
      if (HasCordWithZero) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(CordWithZero);
      }
      if (HasReplacementString) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(ReplacementString);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestExtremeDefaultValues other) {
      if (other == null) {
        return;
      }
      if (other.HasEscapedBytes) {
        EscapedBytes = other.EscapedBytes;
      }
      if (other.HasLargeUint32) {
        LargeUint32 = other.LargeUint32;
      }
      if (other.HasLargeUint64) {
        LargeUint64 = other.LargeUint64;
      }
      if (other.HasSmallInt32) {
        SmallInt32 = other.SmallInt32;
      }
      if (other.HasSmallInt64) {
        SmallInt64 = other.SmallInt64;
      }
      if (other.HasReallySmallInt32) {
        ReallySmallInt32 = other.ReallySmallInt32;
      }
      if (other.HasReallySmallInt64) {
        ReallySmallInt64 = other.ReallySmallInt64;
      }
      if (other.HasUtf8String) {
        Utf8String = other.Utf8String;
      }
      if (other.HasZeroFloat) {
        ZeroFloat = other.ZeroFloat;
      }
      if (other.HasOneFloat) {
        OneFloat = other.OneFloat;
      }
      if (other.HasSmallFloat) {
        SmallFloat = other.SmallFloat;
      }
      if (other.HasNegativeOneFloat) {
        NegativeOneFloat = other.NegativeOneFloat;
      }
      if (other.HasNegativeFloat) {
        NegativeFloat = other.NegativeFloat;
      }
      if (other.HasLargeFloat) {
        LargeFloat = other.LargeFloat;
      }
      if (other.HasSmallNegativeFloat) {
        SmallNegativeFloat = other.SmallNegativeFloat;
      }
      if (other.HasInfDouble) {
        InfDouble = other.InfDouble;
      }
      if (other.HasNegInfDouble) {
        NegInfDouble = other.NegInfDouble;
      }
      if (other.HasNanDouble) {
        NanDouble = other.NanDouble;
      }
      if (other.HasInfFloat) {
        InfFloat = other.InfFloat;
      }
      if (other.HasNegInfFloat) {
        NegInfFloat = other.NegInfFloat;
      }
      if (other.HasNanFloat) {
        NanFloat = other.NanFloat;
      }
      if (other.HasCppTrigraph) {
        CppTrigraph = other.CppTrigraph;
      }
      if (other.HasStringWithZero) {
        StringWithZero = other.StringWithZero;
      }
      if (other.HasBytesWithZero) {
        BytesWithZero = other.BytesWithZero;
      }
      if (other.HasStringPieceWithZero) {
        StringPieceWithZero = other.StringPieceWithZero;
      }
      if (other.HasCordWithZero) {
        CordWithZero = other.CordWithZero;
      }
      if (other.HasReplacementString) {
        ReplacementString = other.ReplacementString;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            EscapedBytes = input.ReadBytes();
            break;
          }
          case 16: {
            LargeUint32 = input.ReadUInt32();
            break;
          }
          case 24: {
            LargeUint64 = input.ReadUInt64();
            break;
          }
          case 32: {
            SmallInt32 = input.ReadInt32();
            break;
          }
          case 40: {
            SmallInt64 = input.ReadInt64();
            break;
          }
          case 50: {
            Utf8String = input.ReadString();
            break;
          }
          case 61: {
            ZeroFloat = input.ReadFloat();
            break;
          }
          case 69: {
            OneFloat = input.ReadFloat();
            break;
          }
          case 77: {
            SmallFloat = input.ReadFloat();
            break;
          }
          case 85: {
            NegativeOneFloat = input.ReadFloat();
            break;
          }
          case 93: {
            NegativeFloat = input.ReadFloat();
            break;
          }
          case 101: {
            LargeFloat = input.ReadFloat();
            break;
          }
          case 109: {
            SmallNegativeFloat = input.ReadFloat();
            break;
          }
          case 113: {
            InfDouble = input.ReadDouble();
            break;
          }
          case 121: {
            NegInfDouble = input.ReadDouble();
            break;
          }
          case 129: {
            NanDouble = input.ReadDouble();
            break;
          }
          case 141: {
            InfFloat = input.ReadFloat();
            break;
          }
          case 149: {
            NegInfFloat = input.ReadFloat();
            break;
          }
          case 157: {
            NanFloat = input.ReadFloat();
            break;
          }
          case 162: {
            CppTrigraph = input.ReadString();
            break;
          }
          case 168: {
            ReallySmallInt32 = input.ReadInt32();
            break;
          }
          case 176: {
            ReallySmallInt64 = input.ReadInt64();
            break;
          }
          case 186: {
            StringWithZero = input.ReadString();
            break;
          }
          case 194: {
            BytesWithZero = input.ReadBytes();
            break;
          }
          case 202: {
            StringPieceWithZero = input.ReadString();
            break;
          }
          case 210: {
            CordWithZero = input.ReadString();
            break;
          }
          case 218: {
            ReplacementString = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            EscapedBytes = input.ReadBytes();
            break;
          }
          case 16: {
            LargeUint32 = input.ReadUInt32();
            break;
          }
          case 24: {
            LargeUint64 = input.ReadUInt64();
            break;
          }
          case 32: {
            SmallInt32 = input.ReadInt32();
            break;
          }
          case 40: {
            SmallInt64 = input.ReadInt64();
            break;
          }
          case 50: {
            Utf8String = input.ReadString();
            break;
          }
          case 61: {
            ZeroFloat = input.ReadFloat();
            break;
          }
          case 69: {
            OneFloat = input.ReadFloat();
            break;
          }
          case 77: {
            SmallFloat = input.ReadFloat();
            break;
          }
          case 85: {
            NegativeOneFloat = input.ReadFloat();
            break;
          }
          case 93: {
            NegativeFloat = input.ReadFloat();
            break;
          }
          case 101: {
            LargeFloat = input.ReadFloat();
            break;
          }
          case 109: {
            SmallNegativeFloat = input.ReadFloat();
            break;
          }
          case 113: {
            InfDouble = input.ReadDouble();
            break;
          }
          case 121: {
            NegInfDouble = input.ReadDouble();
            break;
          }
          case 129: {
            NanDouble = input.ReadDouble();
            break;
          }
          case 141: {
            InfFloat = input.ReadFloat();
            break;
          }
          case 149: {
            NegInfFloat = input.ReadFloat();
            break;
          }
          case 157: {
            NanFloat = input.ReadFloat();
            break;
          }
          case 162: {
            CppTrigraph = input.ReadString();
            break;
          }
          case 168: {
            ReallySmallInt32 = input.ReadInt32();
            break;
          }
          case 176: {
            ReallySmallInt64 = input.ReadInt64();
            break;
          }
          case 186: {
            StringWithZero = input.ReadString();
            break;
          }
          case 194: {
            BytesWithZero = input.ReadBytes();
            break;
          }
          case 202: {
            StringPieceWithZero = input.ReadString();
            break;
          }
          case 210: {
            CordWithZero = input.ReadString();
            break;
          }
          case 218: {
            ReplacementString = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class SparseEnumMessage : pb::IMessage<SparseEnumMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<SparseEnumMessage> _parser = new pb::MessageParser<SparseEnumMessage>(() => new SparseEnumMessage());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<SparseEnumMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[33]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public SparseEnumMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public SparseEnumMessage(SparseEnumMessage other) : this() {
      _hasBits0 = other._hasBits0;
      sparseEnum_ = other.sparseEnum_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public SparseEnumMessage Clone() {
      return new SparseEnumMessage(this);
    }

    /// <summary>Field number for the "sparse_enum" field.</summary>
    public const int SparseEnumFieldNumber = 1;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum SparseEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum.SparseA;

    private global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum sparseEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum SparseEnum {
      get { if ((_hasBits0 & 1) != 0) { return sparseEnum_; } else { return SparseEnumDefaultValue; } }
      set {
        _hasBits0 |= 1;
        sparseEnum_ = value;
      }
    }
    /// <summary>Gets whether the "sparse_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSparseEnum {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "sparse_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSparseEnum() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as SparseEnumMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(SparseEnumMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (SparseEnum != other.SparseEnum) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasSparseEnum) hash ^= SparseEnum.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasSparseEnum) {
        output.WriteRawTag(8);
        output.WriteEnum((int) SparseEnum);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasSparseEnum) {
        output.WriteRawTag(8);
        output.WriteEnum((int) SparseEnum);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasSparseEnum) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) SparseEnum);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(SparseEnumMessage other) {
      if (other == null) {
        return;
      }
      if (other.HasSparseEnum) {
        SparseEnum = other.SparseEnum;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            SparseEnum = (global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum) input.ReadEnum();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            SparseEnum = (global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum) input.ReadEnum();
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test String and Bytes: string is for valid UTF-8 strings
  /// </summary>
  public sealed partial class OneString : pb::IMessage<OneString>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<OneString> _parser = new pb::MessageParser<OneString>(() => new OneString());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<OneString> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[34]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneString() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneString(OneString other) : this() {
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneString Clone() {
      return new OneString(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static string DataDefaultValue = "";

    private string data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string Data {
      get { return data_ ?? DataDefaultValue; }
      set {
        data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return data_ != null; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      data_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as OneString);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(OneString other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(10);
        output.WriteString(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(10);
        output.WriteString(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(OneString other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            Data = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            Data = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class MoreString : pb::IMessage<MoreString>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<MoreString> _parser = new pb::MessageParser<MoreString>(() => new MoreString());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<MoreString> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[35]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreString() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreString(MoreString other) : this() {
      data_ = other.data_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreString Clone() {
      return new MoreString(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private static readonly pb::FieldCodec<string> _repeated_data_codec
        = pb::FieldCodec.ForString(10);
    private readonly pbc::RepeatedField<string> data_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> Data {
      get { return data_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as MoreString);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(MoreString other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if(!data_.Equals(other.data_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= data_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      data_.WriteTo(output, _repeated_data_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      data_.WriteTo(ref output, _repeated_data_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += data_.CalculateSize(_repeated_data_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(MoreString other) {
      if (other == null) {
        return;
      }
      data_.Add(other.data_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            data_.AddEntriesFrom(input, _repeated_data_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            data_.AddEntriesFrom(ref input, _repeated_data_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class OneBytes : pb::IMessage<OneBytes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<OneBytes> _parser = new pb::MessageParser<OneBytes>(() => new OneBytes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<OneBytes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[36]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneBytes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneBytes(OneBytes other) : this() {
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneBytes Clone() {
      return new OneBytes(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static pb::ByteString DataDefaultValue = pb::ByteString.Empty;

    private pb::ByteString data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString Data {
      get { return data_ ?? DataDefaultValue; }
      set {
        data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return data_ != null; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      data_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as OneBytes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(OneBytes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(10);
        output.WriteBytes(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(10);
        output.WriteBytes(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(OneBytes other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            Data = input.ReadBytes();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            Data = input.ReadBytes();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class MoreBytes : pb::IMessage<MoreBytes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<MoreBytes> _parser = new pb::MessageParser<MoreBytes>(() => new MoreBytes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<MoreBytes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[37]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreBytes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreBytes(MoreBytes other) : this() {
      data_ = other.data_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public MoreBytes Clone() {
      return new MoreBytes(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private static readonly pb::FieldCodec<pb::ByteString> _repeated_data_codec
        = pb::FieldCodec.ForBytes(10);
    private readonly pbc::RepeatedField<pb::ByteString> data_ = new pbc::RepeatedField<pb::ByteString>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<pb::ByteString> Data {
      get { return data_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as MoreBytes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(MoreBytes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if(!data_.Equals(other.data_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= data_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      data_.WriteTo(output, _repeated_data_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      data_.WriteTo(ref output, _repeated_data_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += data_.CalculateSize(_repeated_data_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(MoreBytes other) {
      if (other == null) {
        return;
      }
      data_.Add(other.data_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            data_.AddEntriesFrom(input, _repeated_data_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            data_.AddEntriesFrom(ref input, _repeated_data_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test int32, uint32, int64, uint64, and bool are all compatible
  /// </summary>
  public sealed partial class Int32Message : pb::IMessage<Int32Message>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<Int32Message> _parser = new pb::MessageParser<Int32Message>(() => new Int32Message());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<Int32Message> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[38]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int32Message() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int32Message(Int32Message other) : this() {
      _hasBits0 = other._hasBits0;
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int32Message Clone() {
      return new Int32Message(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static int DataDefaultValue = 0;

    private int data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Data {
      get { if ((_hasBits0 & 1) != 0) { return data_; } else { return DataDefaultValue; } }
      set {
        _hasBits0 |= 1;
        data_ = value;
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as Int32Message);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(Int32Message other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteInt32(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteInt32(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(Int32Message other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            Data = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            Data = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class Uint32Message : pb::IMessage<Uint32Message>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<Uint32Message> _parser = new pb::MessageParser<Uint32Message>(() => new Uint32Message());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<Uint32Message> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[39]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint32Message() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint32Message(Uint32Message other) : this() {
      _hasBits0 = other._hasBits0;
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint32Message Clone() {
      return new Uint32Message(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static uint DataDefaultValue = 0;

    private uint data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint Data {
      get { if ((_hasBits0 & 1) != 0) { return data_; } else { return DataDefaultValue; } }
      set {
        _hasBits0 |= 1;
        data_ = value;
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as Uint32Message);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(Uint32Message other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteUInt32(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteUInt32(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(Uint32Message other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            Data = input.ReadUInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            Data = input.ReadUInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class Int64Message : pb::IMessage<Int64Message>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<Int64Message> _parser = new pb::MessageParser<Int64Message>(() => new Int64Message());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<Int64Message> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[40]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int64Message() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int64Message(Int64Message other) : this() {
      _hasBits0 = other._hasBits0;
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Int64Message Clone() {
      return new Int64Message(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static long DataDefaultValue = 0L;

    private long data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public long Data {
      get { if ((_hasBits0 & 1) != 0) { return data_; } else { return DataDefaultValue; } }
      set {
        _hasBits0 |= 1;
        data_ = value;
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as Int64Message);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(Int64Message other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteInt64(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteInt64(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeInt64Size(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(Int64Message other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            Data = input.ReadInt64();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            Data = input.ReadInt64();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class Uint64Message : pb::IMessage<Uint64Message>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<Uint64Message> _parser = new pb::MessageParser<Uint64Message>(() => new Uint64Message());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<Uint64Message> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[41]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint64Message() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint64Message(Uint64Message other) : this() {
      _hasBits0 = other._hasBits0;
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public Uint64Message Clone() {
      return new Uint64Message(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static ulong DataDefaultValue = 0UL;

    private ulong data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public ulong Data {
      get { if ((_hasBits0 & 1) != 0) { return data_; } else { return DataDefaultValue; } }
      set {
        _hasBits0 |= 1;
        data_ = value;
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as Uint64Message);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(Uint64Message other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteUInt64(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteUInt64(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Data);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(Uint64Message other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            Data = input.ReadUInt64();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            Data = input.ReadUInt64();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class BoolMessage : pb::IMessage<BoolMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<BoolMessage> _parser = new pb::MessageParser<BoolMessage>(() => new BoolMessage());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<BoolMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[42]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BoolMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BoolMessage(BoolMessage other) : this() {
      _hasBits0 = other._hasBits0;
      data_ = other.data_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BoolMessage Clone() {
      return new BoolMessage(this);
    }

    /// <summary>Field number for the "data" field.</summary>
    public const int DataFieldNumber = 1;
    private readonly static bool DataDefaultValue = false;

    private bool data_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Data {
      get { if ((_hasBits0 & 1) != 0) { return data_; } else { return DataDefaultValue; } }
      set {
        _hasBits0 |= 1;
        data_ = value;
      }
    }
    /// <summary>Gets whether the "data" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasData {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "data" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearData() {
      _hasBits0 &= ~1;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as BoolMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(BoolMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Data != other.Data) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasData) hash ^= Data.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteBool(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasData) {
        output.WriteRawTag(8);
        output.WriteBool(Data);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasData) {
        size += 1 + 1;
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(BoolMessage other) {
      if (other == null) {
        return;
      }
      if (other.HasData) {
        Data = other.Data;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            Data = input.ReadBool();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            Data = input.ReadBool();
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test oneofs.
  /// </summary>
  public sealed partial class TestOneof : pb::IMessage<TestOneof>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestOneof> _parser = new pb::MessageParser<TestOneof>(() => new TestOneof());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestOneof> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[43]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof(TestOneof other) : this() {
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooMessage:
          FooMessage = other.FooMessage.Clone();
          break;
        case FooOneofCase.FooGroup:
          FooGroup = other.FooGroup.Clone();
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof Clone() {
      return new TestOneof(this);
    }

    /// <summary>Field number for the "foo_int" field.</summary>
    public const int FooIntFieldNumber = 1;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FooInt {
      get { return HasFooInt ? (int) foo_ : 0; }
      set {
        foo_ = value;
        fooCase_ = FooOneofCase.FooInt;
      }
    }
    /// <summary>Gets whether the "foo_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooInt {
      get { return fooCase_ == FooOneofCase.FooInt; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_int" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooInt() {
      if (HasFooInt) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_string" field.</summary>
    public const int FooStringFieldNumber = 2;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooString {
      get { return HasFooString ? (string) foo_ : ""; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooString;
      }
    }
    /// <summary>Gets whether the "foo_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooString {
      get { return fooCase_ == FooOneofCase.FooString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooString() {
      if (HasFooString) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_message" field.</summary>
    public const int FooMessageFieldNumber = 3;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes FooMessage {
      get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage;
      }
    }

    /// <summary>Field number for the "foogroup" field.</summary>
    public const int FooGroupFieldNumber = 4;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup FooGroup {
      get { return HasFooGroup ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooGroup;
      }
    }
    /// <summary>Gets whether the "foogroup" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooGroup {
      get { return fooCase_ == FooOneofCase.FooGroup; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foogroup" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooGroup() {
      if (HasFooGroup) {
        ClearFoo();
      }
    }

    private object foo_;
    /// <summary>Enum of possible cases for the "foo" oneof.</summary>
    public enum FooOneofCase {
      None = 0,
      FooInt = 1,
      FooString = 2,
      FooMessage = 3,
      FooGroup = 4,
    }
    private FooOneofCase fooCase_ = FooOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooOneofCase FooCase {
      get { return fooCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFoo() {
      fooCase_ = FooOneofCase.None;
      foo_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestOneof);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestOneof other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FooInt != other.FooInt) return false;
      if (FooString != other.FooString) return false;
      if (!object.Equals(FooMessage, other.FooMessage)) return false;
      if (!object.Equals(FooGroup, other.FooGroup)) return false;
      if (FooCase != other.FooCase) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasFooInt) hash ^= FooInt.GetHashCode();
      if (HasFooString) hash ^= FooString.GetHashCode();
      if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode();
      if (HasFooGroup) hash ^= FooGroup.GetHashCode();
      hash ^= (int) fooCase_;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(35);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(36);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(35);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(36);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasFooInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt);
      }
      if (HasFooString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage);
      }
      if (HasFooGroup) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(FooGroup);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestOneof other) {
      if (other == null) {
        return;
      }
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooMessage:
          if (FooMessage == null) {
            FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
          }
          FooMessage.MergeFrom(other.FooMessage);
          break;
        case FooOneofCase.FooGroup:
          if (FooGroup == null) {
            FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup();
          }
          FooGroup.MergeFrom(other.FooGroup);
          break;
      }

      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
          case 35: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup();
            if (HasFooGroup) {
              subBuilder.MergeFrom(FooGroup);
            }
            input.ReadGroup(subBuilder);
            FooGroup = subBuilder;
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
          case 35: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup();
            if (HasFooGroup) {
              subBuilder.MergeFrom(FooGroup);
            }
            input.ReadGroup(subBuilder);
            FooGroup = subBuilder;
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestOneof message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class FooGroup : pb::IMessage<FooGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<FooGroup> _parser = new pb::MessageParser<FooGroup>(() => new FooGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<FooGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestOneof.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup(FooGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          b_ = other.b_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup Clone() {
          return new FooGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 5;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        /// <summary>Field number for the "b" field.</summary>
        public const int BFieldNumber = 6;
        private readonly static string BDefaultValue = "";

        private string b_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public string B {
          get { return b_ ?? BDefaultValue; }
          set {
            b_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
          }
        }
        /// <summary>Gets whether the "b" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasB {
          get { return b_ != null; }
        }
        /// <summary>Clears the value of the "b" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearB() {
          b_ = null;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as FooGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(FooGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          if (B != other.B) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (HasB) hash ^= B.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(40);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(50);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(40);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(50);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (HasB) {
            size += 1 + pb::CodedOutputStream.ComputeStringSize(B);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(FooGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          if (other.HasB) {
            B = other.B;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 36:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 40: {
                A = input.ReadInt32();
                break;
              }
              case 50: {
                B = input.ReadString();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 36:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 40: {
                A = input.ReadInt32();
                break;
              }
              case 50: {
                B = input.ReadString();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestOneofBackwardsCompatible : pb::IMessage<TestOneofBackwardsCompatible>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestOneofBackwardsCompatible> _parser = new pb::MessageParser<TestOneofBackwardsCompatible>(() => new TestOneofBackwardsCompatible());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestOneofBackwardsCompatible> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[44]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneofBackwardsCompatible() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneofBackwardsCompatible(TestOneofBackwardsCompatible other) : this() {
      _hasBits0 = other._hasBits0;
      fooInt_ = other.fooInt_;
      fooString_ = other.fooString_;
      fooMessage_ = other.fooMessage_ != null ? other.fooMessage_.Clone() : null;
      fooGroup_ = other.HasFooGroup ? other.fooGroup_.Clone() : null;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneofBackwardsCompatible Clone() {
      return new TestOneofBackwardsCompatible(this);
    }

    /// <summary>Field number for the "foo_int" field.</summary>
    public const int FooIntFieldNumber = 1;
    private readonly static int FooIntDefaultValue = 0;

    private int fooInt_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FooInt {
      get { if ((_hasBits0 & 1) != 0) { return fooInt_; } else { return FooIntDefaultValue; } }
      set {
        _hasBits0 |= 1;
        fooInt_ = value;
      }
    }
    /// <summary>Gets whether the "foo_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooInt {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "foo_int" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooInt() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "foo_string" field.</summary>
    public const int FooStringFieldNumber = 2;
    private readonly static string FooStringDefaultValue = "";

    private string fooString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooString {
      get { return fooString_ ?? FooStringDefaultValue; }
      set {
        fooString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "foo_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooString {
      get { return fooString_ != null; }
    }
    /// <summary>Clears the value of the "foo_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooString() {
      fooString_ = null;
    }

    /// <summary>Field number for the "foo_message" field.</summary>
    public const int FooMessageFieldNumber = 3;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes fooMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes FooMessage {
      get { return fooMessage_; }
      set {
        fooMessage_ = value;
      }
    }

    /// <summary>Field number for the "foogroup" field.</summary>
    public const int FooGroupFieldNumber = 4;
    private global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup fooGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup FooGroup {
      get { return fooGroup_; }
      set {
        fooGroup_ = value;
      }
    }
    /// <summary>Gets whether the foogroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooGroup {
      get { return fooGroup_ != null; }
    }
    /// <summary>Clears the value of the foogroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooGroup() {
      fooGroup_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestOneofBackwardsCompatible);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestOneofBackwardsCompatible other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FooInt != other.FooInt) return false;
      if (FooString != other.FooString) return false;
      if (!object.Equals(FooMessage, other.FooMessage)) return false;
      if (!object.Equals(FooGroup, other.FooGroup)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasFooInt) hash ^= FooInt.GetHashCode();
      if (HasFooString) hash ^= FooString.GetHashCode();
      if (fooMessage_ != null) hash ^= FooMessage.GetHashCode();
      if (HasFooGroup) hash ^= FooGroup.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooMessage_ != null) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(35);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(36);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooMessage_ != null) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(35);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(36);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasFooInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt);
      }
      if (HasFooString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString);
      }
      if (fooMessage_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage);
      }
      if (HasFooGroup) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(FooGroup);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestOneofBackwardsCompatible other) {
      if (other == null) {
        return;
      }
      if (other.HasFooInt) {
        FooInt = other.FooInt;
      }
      if (other.HasFooString) {
        FooString = other.FooString;
      }
      if (other.fooMessage_ != null) {
        if (fooMessage_ == null) {
          FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        FooMessage.MergeFrom(other.FooMessage);
      }
      if (other.HasFooGroup) {
        if (!HasFooGroup) {
          FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup();
        }
        FooGroup.MergeFrom(other.FooGroup);
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            if (fooMessage_ == null) {
              FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(FooMessage);
            break;
          }
          case 35: {
            if (!HasFooGroup) {
              FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup();
            }
            input.ReadGroup(FooGroup);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            if (fooMessage_ == null) {
              FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(FooMessage);
            break;
          }
          case 35: {
            if (!HasFooGroup) {
              FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup();
            }
            input.ReadGroup(FooGroup);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestOneofBackwardsCompatible message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class FooGroup : pb::IMessage<FooGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<FooGroup> _parser = new pb::MessageParser<FooGroup>(() => new FooGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<FooGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup(FooGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          b_ = other.b_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup Clone() {
          return new FooGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 5;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        /// <summary>Field number for the "b" field.</summary>
        public const int BFieldNumber = 6;
        private readonly static string BDefaultValue = "";

        private string b_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public string B {
          get { return b_ ?? BDefaultValue; }
          set {
            b_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
          }
        }
        /// <summary>Gets whether the "b" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasB {
          get { return b_ != null; }
        }
        /// <summary>Clears the value of the "b" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearB() {
          b_ = null;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as FooGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(FooGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          if (B != other.B) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (HasB) hash ^= B.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(40);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(50);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(40);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(50);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (HasB) {
            size += 1 + pb::CodedOutputStream.ComputeStringSize(B);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(FooGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          if (other.HasB) {
            B = other.B;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 36:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 40: {
                A = input.ReadInt32();
                break;
              }
              case 50: {
                B = input.ReadString();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 36:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 40: {
                A = input.ReadInt32();
                break;
              }
              case 50: {
                B = input.ReadString();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestOneof2 : pb::IMessage<TestOneof2>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestOneof2> _parser = new pb::MessageParser<TestOneof2>(() => new TestOneof2());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestOneof2> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[45]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof2() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof2(TestOneof2 other) : this() {
      _hasBits0 = other._hasBits0;
      bazInt_ = other.bazInt_;
      bazString_ = other.bazString_;
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooCord:
          FooCord = other.FooCord;
          break;
        case FooOneofCase.FooStringPiece:
          FooStringPiece = other.FooStringPiece;
          break;
        case FooOneofCase.FooBytes:
          FooBytes = other.FooBytes;
          break;
        case FooOneofCase.FooEnum:
          FooEnum = other.FooEnum;
          break;
        case FooOneofCase.FooMessage:
          FooMessage = other.FooMessage.Clone();
          break;
        case FooOneofCase.FooGroup:
          FooGroup = other.FooGroup.Clone();
          break;
        case FooOneofCase.FooLazyMessage:
          FooLazyMessage = other.FooLazyMessage.Clone();
          break;
      }

      switch (other.BarCase) {
        case BarOneofCase.BarInt:
          BarInt = other.BarInt;
          break;
        case BarOneofCase.BarString:
          BarString = other.BarString;
          break;
        case BarOneofCase.BarCord:
          BarCord = other.BarCord;
          break;
        case BarOneofCase.BarStringPiece:
          BarStringPiece = other.BarStringPiece;
          break;
        case BarOneofCase.BarBytes:
          BarBytes = other.BarBytes;
          break;
        case BarOneofCase.BarEnum:
          BarEnum = other.BarEnum;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestOneof2 Clone() {
      return new TestOneof2(this);
    }

    /// <summary>Field number for the "foo_int" field.</summary>
    public const int FooIntFieldNumber = 1;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FooInt {
      get { return HasFooInt ? (int) foo_ : 0; }
      set {
        foo_ = value;
        fooCase_ = FooOneofCase.FooInt;
      }
    }
    /// <summary>Gets whether the "foo_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooInt {
      get { return fooCase_ == FooOneofCase.FooInt; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_int" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooInt() {
      if (HasFooInt) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_string" field.</summary>
    public const int FooStringFieldNumber = 2;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooString {
      get { return HasFooString ? (string) foo_ : ""; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooString;
      }
    }
    /// <summary>Gets whether the "foo_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooString {
      get { return fooCase_ == FooOneofCase.FooString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooString() {
      if (HasFooString) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_cord" field.</summary>
    public const int FooCordFieldNumber = 3;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooCord {
      get { return HasFooCord ? (string) foo_ : ""; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooCord;
      }
    }
    /// <summary>Gets whether the "foo_cord" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooCord {
      get { return fooCase_ == FooOneofCase.FooCord; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_cord" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooCord() {
      if (HasFooCord) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_string_piece" field.</summary>
    public const int FooStringPieceFieldNumber = 4;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooStringPiece {
      get { return HasFooStringPiece ? (string) foo_ : ""; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooStringPiece;
      }
    }
    /// <summary>Gets whether the "foo_string_piece" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooStringPiece {
      get { return fooCase_ == FooOneofCase.FooStringPiece; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_string_piece" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooStringPiece() {
      if (HasFooStringPiece) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_bytes" field.</summary>
    public const int FooBytesFieldNumber = 5;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString FooBytes {
      get { return HasFooBytes ? (pb::ByteString) foo_ : pb::ByteString.Empty; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooBytes;
      }
    }
    /// <summary>Gets whether the "foo_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooBytes {
      get { return fooCase_ == FooOneofCase.FooBytes; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_bytes" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooBytes() {
      if (HasFooBytes) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_enum" field.</summary>
    public const int FooEnumFieldNumber = 6;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum FooEnum {
      get { return HasFooEnum ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum) foo_ : global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum.Foo; }
      set {
        foo_ = value;
        fooCase_ = FooOneofCase.FooEnum;
      }
    }
    /// <summary>Gets whether the "foo_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooEnum {
      get { return fooCase_ == FooOneofCase.FooEnum; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_enum" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooEnum() {
      if (HasFooEnum) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_message" field.</summary>
    public const int FooMessageFieldNumber = 7;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage FooMessage {
      get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage;
      }
    }

    /// <summary>Field number for the "foogroup" field.</summary>
    public const int FooGroupFieldNumber = 8;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup FooGroup {
      get { return HasFooGroup ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooGroup;
      }
    }
    /// <summary>Gets whether the "foogroup" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooGroup {
      get { return fooCase_ == FooOneofCase.FooGroup; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foogroup" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooGroup() {
      if (HasFooGroup) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_lazy_message" field.</summary>
    public const int FooLazyMessageFieldNumber = 11;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage FooLazyMessage {
      get { return fooCase_ == FooOneofCase.FooLazyMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooLazyMessage;
      }
    }

    /// <summary>Field number for the "bar_int" field.</summary>
    public const int BarIntFieldNumber = 12;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int BarInt {
      get { return HasBarInt ? (int) bar_ : 5; }
      set {
        bar_ = value;
        barCase_ = BarOneofCase.BarInt;
      }
    }
    /// <summary>Gets whether the "bar_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarInt {
      get { return barCase_ == BarOneofCase.BarInt; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_int" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarInt() {
      if (HasBarInt) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "bar_string" field.</summary>
    public const int BarStringFieldNumber = 13;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string BarString {
      get { return HasBarString ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("U1RSSU5H"), 0, 6); }
      set {
        bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        barCase_ = BarOneofCase.BarString;
      }
    }
    /// <summary>Gets whether the "bar_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarString {
      get { return barCase_ == BarOneofCase.BarString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarString() {
      if (HasBarString) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "bar_cord" field.</summary>
    public const int BarCordFieldNumber = 14;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string BarCord {
      get { return HasBarCord ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("Q09SRA=="), 0, 4); }
      set {
        bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        barCase_ = BarOneofCase.BarCord;
      }
    }
    /// <summary>Gets whether the "bar_cord" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarCord {
      get { return barCase_ == BarOneofCase.BarCord; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_cord" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarCord() {
      if (HasBarCord) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "bar_string_piece" field.</summary>
    public const int BarStringPieceFieldNumber = 15;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string BarStringPiece {
      get { return HasBarStringPiece ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("U1BJRUNF"), 0, 6); }
      set {
        bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        barCase_ = BarOneofCase.BarStringPiece;
      }
    }
    /// <summary>Gets whether the "bar_string_piece" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarStringPiece {
      get { return barCase_ == BarOneofCase.BarStringPiece; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_string_piece" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarStringPiece() {
      if (HasBarStringPiece) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "bar_bytes" field.</summary>
    public const int BarBytesFieldNumber = 16;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString BarBytes {
      get { return HasBarBytes ? (pb::ByteString) bar_ : pb::ByteString.FromBase64("QllURVM="); }
      set {
        bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        barCase_ = BarOneofCase.BarBytes;
      }
    }
    /// <summary>Gets whether the "bar_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarBytes {
      get { return barCase_ == BarOneofCase.BarBytes; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_bytes" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarBytes() {
      if (HasBarBytes) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "bar_enum" field.</summary>
    public const int BarEnumFieldNumber = 17;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum BarEnum {
      get { return HasBarEnum ? (global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum) bar_ : global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedEnum.Bar; }
      set {
        bar_ = value;
        barCase_ = BarOneofCase.BarEnum;
      }
    }
    /// <summary>Gets whether the "bar_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBarEnum {
      get { return barCase_ == BarOneofCase.BarEnum; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "bar_enum" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBarEnum() {
      if (HasBarEnum) {
        ClearBar();
      }
    }

    /// <summary>Field number for the "baz_int" field.</summary>
    public const int BazIntFieldNumber = 18;
    private readonly static int BazIntDefaultValue = 0;

    private int bazInt_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int BazInt {
      get { if ((_hasBits0 & 1) != 0) { return bazInt_; } else { return BazIntDefaultValue; } }
      set {
        _hasBits0 |= 1;
        bazInt_ = value;
      }
    }
    /// <summary>Gets whether the "baz_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBazInt {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "baz_int" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBazInt() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "baz_string" field.</summary>
    public const int BazStringFieldNumber = 19;
    private readonly static string BazStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("QkFa"), 0, 3);

    private string bazString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string BazString {
      get { return bazString_ ?? BazStringDefaultValue; }
      set {
        bazString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "baz_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBazString {
      get { return bazString_ != null; }
    }
    /// <summary>Clears the value of the "baz_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBazString() {
      bazString_ = null;
    }

    private object foo_;
    /// <summary>Enum of possible cases for the "foo" oneof.</summary>
    public enum FooOneofCase {
      None = 0,
      FooInt = 1,
      FooString = 2,
      FooCord = 3,
      FooStringPiece = 4,
      FooBytes = 5,
      FooEnum = 6,
      FooMessage = 7,
      FooGroup = 8,
      FooLazyMessage = 11,
    }
    private FooOneofCase fooCase_ = FooOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooOneofCase FooCase {
      get { return fooCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFoo() {
      fooCase_ = FooOneofCase.None;
      foo_ = null;
    }

    private object bar_;
    /// <summary>Enum of possible cases for the "bar" oneof.</summary>
    public enum BarOneofCase {
      None = 0,
      BarInt = 12,
      BarString = 13,
      BarCord = 14,
      BarStringPiece = 15,
      BarBytes = 16,
      BarEnum = 17,
    }
    private BarOneofCase barCase_ = BarOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarOneofCase BarCase {
      get { return barCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBar() {
      barCase_ = BarOneofCase.None;
      bar_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestOneof2);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestOneof2 other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FooInt != other.FooInt) return false;
      if (FooString != other.FooString) return false;
      if (FooCord != other.FooCord) return false;
      if (FooStringPiece != other.FooStringPiece) return false;
      if (FooBytes != other.FooBytes) return false;
      if (FooEnum != other.FooEnum) return false;
      if (!object.Equals(FooMessage, other.FooMessage)) return false;
      if (!object.Equals(FooGroup, other.FooGroup)) return false;
      if (!object.Equals(FooLazyMessage, other.FooLazyMessage)) return false;
      if (BarInt != other.BarInt) return false;
      if (BarString != other.BarString) return false;
      if (BarCord != other.BarCord) return false;
      if (BarStringPiece != other.BarStringPiece) return false;
      if (BarBytes != other.BarBytes) return false;
      if (BarEnum != other.BarEnum) return false;
      if (BazInt != other.BazInt) return false;
      if (BazString != other.BazString) return false;
      if (FooCase != other.FooCase) return false;
      if (BarCase != other.BarCase) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasFooInt) hash ^= FooInt.GetHashCode();
      if (HasFooString) hash ^= FooString.GetHashCode();
      if (HasFooCord) hash ^= FooCord.GetHashCode();
      if (HasFooStringPiece) hash ^= FooStringPiece.GetHashCode();
      if (HasFooBytes) hash ^= FooBytes.GetHashCode();
      if (HasFooEnum) hash ^= FooEnum.GetHashCode();
      if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode();
      if (HasFooGroup) hash ^= FooGroup.GetHashCode();
      if (fooCase_ == FooOneofCase.FooLazyMessage) hash ^= FooLazyMessage.GetHashCode();
      if (HasBarInt) hash ^= BarInt.GetHashCode();
      if (HasBarString) hash ^= BarString.GetHashCode();
      if (HasBarCord) hash ^= BarCord.GetHashCode();
      if (HasBarStringPiece) hash ^= BarStringPiece.GetHashCode();
      if (HasBarBytes) hash ^= BarBytes.GetHashCode();
      if (HasBarEnum) hash ^= BarEnum.GetHashCode();
      if (HasBazInt) hash ^= BazInt.GetHashCode();
      if (HasBazString) hash ^= BazString.GetHashCode();
      hash ^= (int) fooCase_;
      hash ^= (int) barCase_;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (HasFooCord) {
        output.WriteRawTag(26);
        output.WriteString(FooCord);
      }
      if (HasFooStringPiece) {
        output.WriteRawTag(34);
        output.WriteString(FooStringPiece);
      }
      if (HasFooBytes) {
        output.WriteRawTag(42);
        output.WriteBytes(FooBytes);
      }
      if (HasFooEnum) {
        output.WriteRawTag(48);
        output.WriteEnum((int) FooEnum);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(58);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(67);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(68);
      }
      if (fooCase_ == FooOneofCase.FooLazyMessage) {
        output.WriteRawTag(90);
        output.WriteMessage(FooLazyMessage);
      }
      if (HasBarInt) {
        output.WriteRawTag(96);
        output.WriteInt32(BarInt);
      }
      if (HasBarString) {
        output.WriteRawTag(106);
        output.WriteString(BarString);
      }
      if (HasBarCord) {
        output.WriteRawTag(114);
        output.WriteString(BarCord);
      }
      if (HasBarStringPiece) {
        output.WriteRawTag(122);
        output.WriteString(BarStringPiece);
      }
      if (HasBarBytes) {
        output.WriteRawTag(130, 1);
        output.WriteBytes(BarBytes);
      }
      if (HasBarEnum) {
        output.WriteRawTag(136, 1);
        output.WriteEnum((int) BarEnum);
      }
      if (HasBazInt) {
        output.WriteRawTag(144, 1);
        output.WriteInt32(BazInt);
      }
      if (HasBazString) {
        output.WriteRawTag(154, 1);
        output.WriteString(BazString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (HasFooCord) {
        output.WriteRawTag(26);
        output.WriteString(FooCord);
      }
      if (HasFooStringPiece) {
        output.WriteRawTag(34);
        output.WriteString(FooStringPiece);
      }
      if (HasFooBytes) {
        output.WriteRawTag(42);
        output.WriteBytes(FooBytes);
      }
      if (HasFooEnum) {
        output.WriteRawTag(48);
        output.WriteEnum((int) FooEnum);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(58);
        output.WriteMessage(FooMessage);
      }
      if (HasFooGroup) {
        output.WriteRawTag(67);
        output.WriteGroup(FooGroup);
        output.WriteRawTag(68);
      }
      if (fooCase_ == FooOneofCase.FooLazyMessage) {
        output.WriteRawTag(90);
        output.WriteMessage(FooLazyMessage);
      }
      if (HasBarInt) {
        output.WriteRawTag(96);
        output.WriteInt32(BarInt);
      }
      if (HasBarString) {
        output.WriteRawTag(106);
        output.WriteString(BarString);
      }
      if (HasBarCord) {
        output.WriteRawTag(114);
        output.WriteString(BarCord);
      }
      if (HasBarStringPiece) {
        output.WriteRawTag(122);
        output.WriteString(BarStringPiece);
      }
      if (HasBarBytes) {
        output.WriteRawTag(130, 1);
        output.WriteBytes(BarBytes);
      }
      if (HasBarEnum) {
        output.WriteRawTag(136, 1);
        output.WriteEnum((int) BarEnum);
      }
      if (HasBazInt) {
        output.WriteRawTag(144, 1);
        output.WriteInt32(BazInt);
      }
      if (HasBazString) {
        output.WriteRawTag(154, 1);
        output.WriteString(BazString);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasFooInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt);
      }
      if (HasFooString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString);
      }
      if (HasFooCord) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooCord);
      }
      if (HasFooStringPiece) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooStringPiece);
      }
      if (HasFooBytes) {
        size += 1 + pb::CodedOutputStream.ComputeBytesSize(FooBytes);
      }
      if (HasFooEnum) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) FooEnum);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage);
      }
      if (HasFooGroup) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(FooGroup);
      }
      if (fooCase_ == FooOneofCase.FooLazyMessage) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooLazyMessage);
      }
      if (HasBarInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(BarInt);
      }
      if (HasBarString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(BarString);
      }
      if (HasBarCord) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(BarCord);
      }
      if (HasBarStringPiece) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(BarStringPiece);
      }
      if (HasBarBytes) {
        size += 2 + pb::CodedOutputStream.ComputeBytesSize(BarBytes);
      }
      if (HasBarEnum) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) BarEnum);
      }
      if (HasBazInt) {
        size += 2 + pb::CodedOutputStream.ComputeInt32Size(BazInt);
      }
      if (HasBazString) {
        size += 2 + pb::CodedOutputStream.ComputeStringSize(BazString);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestOneof2 other) {
      if (other == null) {
        return;
      }
      if (other.HasBazInt) {
        BazInt = other.BazInt;
      }
      if (other.HasBazString) {
        BazString = other.BazString;
      }
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooCord:
          FooCord = other.FooCord;
          break;
        case FooOneofCase.FooStringPiece:
          FooStringPiece = other.FooStringPiece;
          break;
        case FooOneofCase.FooBytes:
          FooBytes = other.FooBytes;
          break;
        case FooOneofCase.FooEnum:
          FooEnum = other.FooEnum;
          break;
        case FooOneofCase.FooMessage:
          if (FooMessage == null) {
            FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
          }
          FooMessage.MergeFrom(other.FooMessage);
          break;
        case FooOneofCase.FooGroup:
          if (FooGroup == null) {
            FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup();
          }
          FooGroup.MergeFrom(other.FooGroup);
          break;
        case FooOneofCase.FooLazyMessage:
          if (FooLazyMessage == null) {
            FooLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
          }
          FooLazyMessage.MergeFrom(other.FooLazyMessage);
          break;
      }

      switch (other.BarCase) {
        case BarOneofCase.BarInt:
          BarInt = other.BarInt;
          break;
        case BarOneofCase.BarString:
          BarString = other.BarString;
          break;
        case BarOneofCase.BarCord:
          BarCord = other.BarCord;
          break;
        case BarOneofCase.BarStringPiece:
          BarStringPiece = other.BarStringPiece;
          break;
        case BarOneofCase.BarBytes:
          BarBytes = other.BarBytes;
          break;
        case BarOneofCase.BarEnum:
          BarEnum = other.BarEnum;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            FooCord = input.ReadString();
            break;
          }
          case 34: {
            FooStringPiece = input.ReadString();
            break;
          }
          case 42: {
            FooBytes = input.ReadBytes();
            break;
          }
          case 48: {
            foo_ = input.ReadEnum();
            fooCase_ = FooOneofCase.FooEnum;
            break;
          }
          case 58: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
          case 67: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup();
            if (HasFooGroup) {
              subBuilder.MergeFrom(FooGroup);
            }
            input.ReadGroup(subBuilder);
            FooGroup = subBuilder;
            break;
          }
          case 90: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooLazyMessage) {
              subBuilder.MergeFrom(FooLazyMessage);
            }
            input.ReadMessage(subBuilder);
            FooLazyMessage = subBuilder;
            break;
          }
          case 96: {
            BarInt = input.ReadInt32();
            break;
          }
          case 106: {
            BarString = input.ReadString();
            break;
          }
          case 114: {
            BarCord = input.ReadString();
            break;
          }
          case 122: {
            BarStringPiece = input.ReadString();
            break;
          }
          case 130: {
            BarBytes = input.ReadBytes();
            break;
          }
          case 136: {
            bar_ = input.ReadEnum();
            barCase_ = BarOneofCase.BarEnum;
            break;
          }
          case 144: {
            BazInt = input.ReadInt32();
            break;
          }
          case 154: {
            BazString = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            FooCord = input.ReadString();
            break;
          }
          case 34: {
            FooStringPiece = input.ReadString();
            break;
          }
          case 42: {
            FooBytes = input.ReadBytes();
            break;
          }
          case 48: {
            foo_ = input.ReadEnum();
            fooCase_ = FooOneofCase.FooEnum;
            break;
          }
          case 58: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
          case 67: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup();
            if (HasFooGroup) {
              subBuilder.MergeFrom(FooGroup);
            }
            input.ReadGroup(subBuilder);
            FooGroup = subBuilder;
            break;
          }
          case 90: {
            global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooLazyMessage) {
              subBuilder.MergeFrom(FooLazyMessage);
            }
            input.ReadMessage(subBuilder);
            FooLazyMessage = subBuilder;
            break;
          }
          case 96: {
            BarInt = input.ReadInt32();
            break;
          }
          case 106: {
            BarString = input.ReadString();
            break;
          }
          case 114: {
            BarCord = input.ReadString();
            break;
          }
          case 122: {
            BarStringPiece = input.ReadString();
            break;
          }
          case 130: {
            BarBytes = input.ReadBytes();
            break;
          }
          case 136: {
            bar_ = input.ReadEnum();
            barCase_ = BarOneofCase.BarEnum;
            break;
          }
          case 144: {
            BazInt = input.ReadInt32();
            break;
          }
          case 154: {
            BazString = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestOneof2 message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public enum NestedEnum {
        [pbr::OriginalName("FOO")] Foo = 1,
        [pbr::OriginalName("BAR")] Bar = 2,
        [pbr::OriginalName("BAZ")] Baz = 3,
      }

      public sealed partial class FooGroup : pb::IMessage<FooGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<FooGroup> _parser = new pb::MessageParser<FooGroup>(() => new FooGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<FooGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup(FooGroup other) : this() {
          _hasBits0 = other._hasBits0;
          a_ = other.a_;
          b_ = other.b_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public FooGroup Clone() {
          return new FooGroup(this);
        }

        /// <summary>Field number for the "a" field.</summary>
        public const int AFieldNumber = 9;
        private readonly static int ADefaultValue = 0;

        private int a_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int A {
          get { if ((_hasBits0 & 1) != 0) { return a_; } else { return ADefaultValue; } }
          set {
            _hasBits0 |= 1;
            a_ = value;
          }
        }
        /// <summary>Gets whether the "a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearA() {
          _hasBits0 &= ~1;
        }

        /// <summary>Field number for the "b" field.</summary>
        public const int BFieldNumber = 10;
        private readonly static string BDefaultValue = "";

        private string b_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public string B {
          get { return b_ ?? BDefaultValue; }
          set {
            b_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
          }
        }
        /// <summary>Gets whether the "b" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasB {
          get { return b_ != null; }
        }
        /// <summary>Clears the value of the "b" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearB() {
          b_ = null;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as FooGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(FooGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (A != other.A) return false;
          if (B != other.B) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasA) hash ^= A.GetHashCode();
          if (HasB) hash ^= B.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasA) {
            output.WriteRawTag(72);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(82);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasA) {
            output.WriteRawTag(72);
            output.WriteInt32(A);
          }
          if (HasB) {
            output.WriteRawTag(82);
            output.WriteString(B);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasA) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
          }
          if (HasB) {
            size += 1 + pb::CodedOutputStream.ComputeStringSize(B);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(FooGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasA) {
            A = other.A;
          }
          if (other.HasB) {
            B = other.B;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 68:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 72: {
                A = input.ReadInt32();
                break;
              }
              case 82: {
                B = input.ReadString();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 68:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 72: {
                A = input.ReadInt32();
                break;
              }
              case 82: {
                B = input.ReadString();
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          _hasBits0 = other._hasBits0;
          quxInt_ = other.quxInt_;
          corgeInt_ = other.corgeInt_.Clone();
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "qux_int" field.</summary>
        public const int QuxIntFieldNumber = 1;
        private readonly static long QuxIntDefaultValue = 0L;

        private long quxInt_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public long QuxInt {
          get { if ((_hasBits0 & 1) != 0) { return quxInt_; } else { return QuxIntDefaultValue; } }
          set {
            _hasBits0 |= 1;
            quxInt_ = value;
          }
        }
        /// <summary>Gets whether the "qux_int" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasQuxInt {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "qux_int" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearQuxInt() {
          _hasBits0 &= ~1;
        }

        /// <summary>Field number for the "corge_int" field.</summary>
        public const int CorgeIntFieldNumber = 2;
        private static readonly pb::FieldCodec<int> _repeated_corgeInt_codec
            = pb::FieldCodec.ForInt32(16);
        private readonly pbc::RepeatedField<int> corgeInt_ = new pbc::RepeatedField<int>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<int> CorgeInt {
          get { return corgeInt_; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (QuxInt != other.QuxInt) return false;
          if(!corgeInt_.Equals(other.corgeInt_)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasQuxInt) hash ^= QuxInt.GetHashCode();
          hash ^= corgeInt_.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasQuxInt) {
            output.WriteRawTag(8);
            output.WriteInt64(QuxInt);
          }
          corgeInt_.WriteTo(output, _repeated_corgeInt_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasQuxInt) {
            output.WriteRawTag(8);
            output.WriteInt64(QuxInt);
          }
          corgeInt_.WriteTo(ref output, _repeated_corgeInt_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasQuxInt) {
            size += 1 + pb::CodedOutputStream.ComputeInt64Size(QuxInt);
          }
          size += corgeInt_.CalculateSize(_repeated_corgeInt_codec);
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasQuxInt) {
            QuxInt = other.QuxInt;
          }
          corgeInt_.Add(other.corgeInt_);
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                QuxInt = input.ReadInt64();
                break;
              }
              case 18:
              case 16: {
                corgeInt_.AddEntriesFrom(input, _repeated_corgeInt_codec);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                QuxInt = input.ReadInt64();
                break;
              }
              case 18:
              case 16: {
                corgeInt_.AddEntriesFrom(ref input, _repeated_corgeInt_codec);
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestRequiredOneof : pb::IMessage<TestRequiredOneof>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRequiredOneof> _parser = new pb::MessageParser<TestRequiredOneof>(() => new TestRequiredOneof());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRequiredOneof> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[46]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredOneof() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredOneof(TestRequiredOneof other) : this() {
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooMessage:
          FooMessage = other.FooMessage.Clone();
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredOneof Clone() {
      return new TestRequiredOneof(this);
    }

    /// <summary>Field number for the "foo_int" field.</summary>
    public const int FooIntFieldNumber = 1;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FooInt {
      get { return HasFooInt ? (int) foo_ : 0; }
      set {
        foo_ = value;
        fooCase_ = FooOneofCase.FooInt;
      }
    }
    /// <summary>Gets whether the "foo_int" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooInt {
      get { return fooCase_ == FooOneofCase.FooInt; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_int" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooInt() {
      if (HasFooInt) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_string" field.</summary>
    public const int FooStringFieldNumber = 2;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string FooString {
      get { return HasFooString ? (string) foo_ : ""; }
      set {
        foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        fooCase_ = FooOneofCase.FooString;
      }
    }
    /// <summary>Gets whether the "foo_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFooString {
      get { return fooCase_ == FooOneofCase.FooString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "foo_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFooString() {
      if (HasFooString) {
        ClearFoo();
      }
    }

    /// <summary>Field number for the "foo_message" field.</summary>
    public const int FooMessageFieldNumber = 3;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage FooMessage {
      get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage) foo_ : null; }
      set {
        foo_ = value;
        fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage;
      }
    }

    private object foo_;
    /// <summary>Enum of possible cases for the "foo" oneof.</summary>
    public enum FooOneofCase {
      None = 0,
      FooInt = 1,
      FooString = 2,
      FooMessage = 3,
    }
    private FooOneofCase fooCase_ = FooOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooOneofCase FooCase {
      get { return fooCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFoo() {
      fooCase_ = FooOneofCase.None;
      foo_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRequiredOneof);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRequiredOneof other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FooInt != other.FooInt) return false;
      if (FooString != other.FooString) return false;
      if (!object.Equals(FooMessage, other.FooMessage)) return false;
      if (FooCase != other.FooCase) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasFooInt) hash ^= FooInt.GetHashCode();
      if (HasFooString) hash ^= FooString.GetHashCode();
      if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode();
      hash ^= (int) fooCase_;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasFooInt) {
        output.WriteRawTag(8);
        output.WriteInt32(FooInt);
      }
      if (HasFooString) {
        output.WriteRawTag(18);
        output.WriteString(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        output.WriteRawTag(26);
        output.WriteMessage(FooMessage);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasFooInt) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt);
      }
      if (HasFooString) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString);
      }
      if (fooCase_ == FooOneofCase.FooMessage) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRequiredOneof other) {
      if (other == null) {
        return;
      }
      switch (other.FooCase) {
        case FooOneofCase.FooInt:
          FooInt = other.FooInt;
          break;
        case FooOneofCase.FooString:
          FooString = other.FooString;
          break;
        case FooOneofCase.FooMessage:
          if (FooMessage == null) {
            FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage();
          }
          FooMessage.MergeFrom(other.FooMessage);
          break;
      }

      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FooInt = input.ReadInt32();
            break;
          }
          case 18: {
            FooString = input.ReadString();
            break;
          }
          case 26: {
            global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage();
            if (fooCase_ == FooOneofCase.FooMessage) {
              subBuilder.MergeFrom(FooMessage);
            }
            input.ReadMessage(subBuilder);
            FooMessage = subBuilder;
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestRequiredOneof message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          _hasBits0 = other._hasBits0;
          requiredDouble_ = other.requiredDouble_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "required_double" field.</summary>
        public const int RequiredDoubleFieldNumber = 1;
        private readonly static double RequiredDoubleDefaultValue = 0D;

        private double requiredDouble_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public double RequiredDouble {
          get { if ((_hasBits0 & 1) != 0) { return requiredDouble_; } else { return RequiredDoubleDefaultValue; } }
          set {
            _hasBits0 |= 1;
            requiredDouble_ = value;
          }
        }
        /// <summary>Gets whether the "required_double" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasRequiredDouble {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "required_double" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearRequiredDouble() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(RequiredDouble, other.RequiredDouble)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasRequiredDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(RequiredDouble);
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasRequiredDouble) {
            output.WriteRawTag(9);
            output.WriteDouble(RequiredDouble);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasRequiredDouble) {
            output.WriteRawTag(9);
            output.WriteDouble(RequiredDouble);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasRequiredDouble) {
            size += 1 + 8;
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasRequiredDouble) {
            RequiredDouble = other.RequiredDouble;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 9: {
                RequiredDouble = input.ReadDouble();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 9: {
                RequiredDouble = input.ReadDouble();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestRequiredMap : pb::IMessage<TestRequiredMap>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRequiredMap> _parser = new pb::MessageParser<TestRequiredMap>(() => new TestRequiredMap());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRequiredMap> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[47]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMap() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMap(TestRequiredMap other) : this() {
      foo_ = other.foo_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRequiredMap Clone() {
      return new TestRequiredMap(this);
    }

    /// <summary>Field number for the "foo" field.</summary>
    public const int FooFieldNumber = 1;
    private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage>.Codec _map_foo_codec
        = new pbc::MapField<int, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage>.Codec(pb::FieldCodec.ForInt32(8, 0), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage.Parser), 10);
    private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage> foo_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::MapField<int, global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Types.NestedMessage> Foo {
      get { return foo_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRequiredMap);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRequiredMap other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Foo.Equals(other.Foo)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= Foo.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      foo_.WriteTo(output, _map_foo_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      foo_.WriteTo(ref output, _map_foo_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += foo_.CalculateSize(_map_foo_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRequiredMap other) {
      if (other == null) {
        return;
      }
      foo_.MergeFrom(other.foo_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            foo_.AddEntriesFrom(input, _map_foo_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            foo_.AddEntriesFrom(ref input, _map_foo_codec);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestRequiredMap message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestRequiredMap.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage(NestedMessage other) : this() {
          _hasBits0 = other._hasBits0;
          requiredInt32_ = other.requiredInt32_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public NestedMessage Clone() {
          return new NestedMessage(this);
        }

        /// <summary>Field number for the "required_int32" field.</summary>
        public const int RequiredInt32FieldNumber = 1;
        private readonly static int RequiredInt32DefaultValue = 0;

        private int requiredInt32_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int RequiredInt32 {
          get { if ((_hasBits0 & 1) != 0) { return requiredInt32_; } else { return RequiredInt32DefaultValue; } }
          set {
            _hasBits0 |= 1;
            requiredInt32_ = value;
          }
        }
        /// <summary>Gets whether the "required_int32" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasRequiredInt32 {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "required_int32" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearRequiredInt32() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as NestedMessage);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(NestedMessage other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (RequiredInt32 != other.RequiredInt32) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasRequiredInt32) hash ^= RequiredInt32.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasRequiredInt32) {
            output.WriteRawTag(8);
            output.WriteInt32(RequiredInt32);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasRequiredInt32) {
            output.WriteRawTag(8);
            output.WriteInt32(RequiredInt32);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasRequiredInt32) {
            size += 1 + pb::CodedOutputStream.ComputeInt32Size(RequiredInt32);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(NestedMessage other) {
          if (other == null) {
            return;
          }
          if (other.HasRequiredInt32) {
            RequiredInt32 = other.RequiredInt32;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 8: {
                RequiredInt32 = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 8: {
                RequiredInt32 = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestPackedTypes : pb::IMessage<TestPackedTypes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestPackedTypes> _parser = new pb::MessageParser<TestPackedTypes>(() => new TestPackedTypes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestPackedTypes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[48]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedTypes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedTypes(TestPackedTypes other) : this() {
      packedInt32_ = other.packedInt32_.Clone();
      packedInt64_ = other.packedInt64_.Clone();
      packedUint32_ = other.packedUint32_.Clone();
      packedUint64_ = other.packedUint64_.Clone();
      packedSint32_ = other.packedSint32_.Clone();
      packedSint64_ = other.packedSint64_.Clone();
      packedFixed32_ = other.packedFixed32_.Clone();
      packedFixed64_ = other.packedFixed64_.Clone();
      packedSfixed32_ = other.packedSfixed32_.Clone();
      packedSfixed64_ = other.packedSfixed64_.Clone();
      packedFloat_ = other.packedFloat_.Clone();
      packedDouble_ = other.packedDouble_.Clone();
      packedBool_ = other.packedBool_.Clone();
      packedEnum_ = other.packedEnum_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedTypes Clone() {
      return new TestPackedTypes(this);
    }

    /// <summary>Field number for the "packed_int32" field.</summary>
    public const int PackedInt32FieldNumber = 90;
    private static readonly pb::FieldCodec<int> _repeated_packedInt32_codec
        = pb::FieldCodec.ForInt32(722);
    private readonly pbc::RepeatedField<int> packedInt32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> PackedInt32 {
      get { return packedInt32_; }
    }

    /// <summary>Field number for the "packed_int64" field.</summary>
    public const int PackedInt64FieldNumber = 91;
    private static readonly pb::FieldCodec<long> _repeated_packedInt64_codec
        = pb::FieldCodec.ForInt64(730);
    private readonly pbc::RepeatedField<long> packedInt64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> PackedInt64 {
      get { return packedInt64_; }
    }

    /// <summary>Field number for the "packed_uint32" field.</summary>
    public const int PackedUint32FieldNumber = 92;
    private static readonly pb::FieldCodec<uint> _repeated_packedUint32_codec
        = pb::FieldCodec.ForUInt32(738);
    private readonly pbc::RepeatedField<uint> packedUint32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> PackedUint32 {
      get { return packedUint32_; }
    }

    /// <summary>Field number for the "packed_uint64" field.</summary>
    public const int PackedUint64FieldNumber = 93;
    private static readonly pb::FieldCodec<ulong> _repeated_packedUint64_codec
        = pb::FieldCodec.ForUInt64(746);
    private readonly pbc::RepeatedField<ulong> packedUint64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> PackedUint64 {
      get { return packedUint64_; }
    }

    /// <summary>Field number for the "packed_sint32" field.</summary>
    public const int PackedSint32FieldNumber = 94;
    private static readonly pb::FieldCodec<int> _repeated_packedSint32_codec
        = pb::FieldCodec.ForSInt32(754);
    private readonly pbc::RepeatedField<int> packedSint32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> PackedSint32 {
      get { return packedSint32_; }
    }

    /// <summary>Field number for the "packed_sint64" field.</summary>
    public const int PackedSint64FieldNumber = 95;
    private static readonly pb::FieldCodec<long> _repeated_packedSint64_codec
        = pb::FieldCodec.ForSInt64(762);
    private readonly pbc::RepeatedField<long> packedSint64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> PackedSint64 {
      get { return packedSint64_; }
    }

    /// <summary>Field number for the "packed_fixed32" field.</summary>
    public const int PackedFixed32FieldNumber = 96;
    private static readonly pb::FieldCodec<uint> _repeated_packedFixed32_codec
        = pb::FieldCodec.ForFixed32(770);
    private readonly pbc::RepeatedField<uint> packedFixed32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> PackedFixed32 {
      get { return packedFixed32_; }
    }

    /// <summary>Field number for the "packed_fixed64" field.</summary>
    public const int PackedFixed64FieldNumber = 97;
    private static readonly pb::FieldCodec<ulong> _repeated_packedFixed64_codec
        = pb::FieldCodec.ForFixed64(778);
    private readonly pbc::RepeatedField<ulong> packedFixed64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> PackedFixed64 {
      get { return packedFixed64_; }
    }

    /// <summary>Field number for the "packed_sfixed32" field.</summary>
    public const int PackedSfixed32FieldNumber = 98;
    private static readonly pb::FieldCodec<int> _repeated_packedSfixed32_codec
        = pb::FieldCodec.ForSFixed32(786);
    private readonly pbc::RepeatedField<int> packedSfixed32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> PackedSfixed32 {
      get { return packedSfixed32_; }
    }

    /// <summary>Field number for the "packed_sfixed64" field.</summary>
    public const int PackedSfixed64FieldNumber = 99;
    private static readonly pb::FieldCodec<long> _repeated_packedSfixed64_codec
        = pb::FieldCodec.ForSFixed64(794);
    private readonly pbc::RepeatedField<long> packedSfixed64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> PackedSfixed64 {
      get { return packedSfixed64_; }
    }

    /// <summary>Field number for the "packed_float" field.</summary>
    public const int PackedFloatFieldNumber = 100;
    private static readonly pb::FieldCodec<float> _repeated_packedFloat_codec
        = pb::FieldCodec.ForFloat(802);
    private readonly pbc::RepeatedField<float> packedFloat_ = new pbc::RepeatedField<float>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<float> PackedFloat {
      get { return packedFloat_; }
    }

    /// <summary>Field number for the "packed_double" field.</summary>
    public const int PackedDoubleFieldNumber = 101;
    private static readonly pb::FieldCodec<double> _repeated_packedDouble_codec
        = pb::FieldCodec.ForDouble(810);
    private readonly pbc::RepeatedField<double> packedDouble_ = new pbc::RepeatedField<double>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<double> PackedDouble {
      get { return packedDouble_; }
    }

    /// <summary>Field number for the "packed_bool" field.</summary>
    public const int PackedBoolFieldNumber = 102;
    private static readonly pb::FieldCodec<bool> _repeated_packedBool_codec
        = pb::FieldCodec.ForBool(818);
    private readonly pbc::RepeatedField<bool> packedBool_ = new pbc::RepeatedField<bool>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<bool> PackedBool {
      get { return packedBool_; }
    }

    /// <summary>Field number for the "packed_enum" field.</summary>
    public const int PackedEnumFieldNumber = 103;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> _repeated_packedEnum_codec
        = pb::FieldCodec.ForEnum(826, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> packedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> PackedEnum {
      get { return packedEnum_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestPackedTypes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestPackedTypes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if(!packedInt32_.Equals(other.packedInt32_)) return false;
      if(!packedInt64_.Equals(other.packedInt64_)) return false;
      if(!packedUint32_.Equals(other.packedUint32_)) return false;
      if(!packedUint64_.Equals(other.packedUint64_)) return false;
      if(!packedSint32_.Equals(other.packedSint32_)) return false;
      if(!packedSint64_.Equals(other.packedSint64_)) return false;
      if(!packedFixed32_.Equals(other.packedFixed32_)) return false;
      if(!packedFixed64_.Equals(other.packedFixed64_)) return false;
      if(!packedSfixed32_.Equals(other.packedSfixed32_)) return false;
      if(!packedSfixed64_.Equals(other.packedSfixed64_)) return false;
      if(!packedFloat_.Equals(other.packedFloat_)) return false;
      if(!packedDouble_.Equals(other.packedDouble_)) return false;
      if(!packedBool_.Equals(other.packedBool_)) return false;
      if(!packedEnum_.Equals(other.packedEnum_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= packedInt32_.GetHashCode();
      hash ^= packedInt64_.GetHashCode();
      hash ^= packedUint32_.GetHashCode();
      hash ^= packedUint64_.GetHashCode();
      hash ^= packedSint32_.GetHashCode();
      hash ^= packedSint64_.GetHashCode();
      hash ^= packedFixed32_.GetHashCode();
      hash ^= packedFixed64_.GetHashCode();
      hash ^= packedSfixed32_.GetHashCode();
      hash ^= packedSfixed64_.GetHashCode();
      hash ^= packedFloat_.GetHashCode();
      hash ^= packedDouble_.GetHashCode();
      hash ^= packedBool_.GetHashCode();
      hash ^= packedEnum_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      packedInt32_.WriteTo(output, _repeated_packedInt32_codec);
      packedInt64_.WriteTo(output, _repeated_packedInt64_codec);
      packedUint32_.WriteTo(output, _repeated_packedUint32_codec);
      packedUint64_.WriteTo(output, _repeated_packedUint64_codec);
      packedSint32_.WriteTo(output, _repeated_packedSint32_codec);
      packedSint64_.WriteTo(output, _repeated_packedSint64_codec);
      packedFixed32_.WriteTo(output, _repeated_packedFixed32_codec);
      packedFixed64_.WriteTo(output, _repeated_packedFixed64_codec);
      packedSfixed32_.WriteTo(output, _repeated_packedSfixed32_codec);
      packedSfixed64_.WriteTo(output, _repeated_packedSfixed64_codec);
      packedFloat_.WriteTo(output, _repeated_packedFloat_codec);
      packedDouble_.WriteTo(output, _repeated_packedDouble_codec);
      packedBool_.WriteTo(output, _repeated_packedBool_codec);
      packedEnum_.WriteTo(output, _repeated_packedEnum_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec);
      packedInt64_.WriteTo(ref output, _repeated_packedInt64_codec);
      packedUint32_.WriteTo(ref output, _repeated_packedUint32_codec);
      packedUint64_.WriteTo(ref output, _repeated_packedUint64_codec);
      packedSint32_.WriteTo(ref output, _repeated_packedSint32_codec);
      packedSint64_.WriteTo(ref output, _repeated_packedSint64_codec);
      packedFixed32_.WriteTo(ref output, _repeated_packedFixed32_codec);
      packedFixed64_.WriteTo(ref output, _repeated_packedFixed64_codec);
      packedSfixed32_.WriteTo(ref output, _repeated_packedSfixed32_codec);
      packedSfixed64_.WriteTo(ref output, _repeated_packedSfixed64_codec);
      packedFloat_.WriteTo(ref output, _repeated_packedFloat_codec);
      packedDouble_.WriteTo(ref output, _repeated_packedDouble_codec);
      packedBool_.WriteTo(ref output, _repeated_packedBool_codec);
      packedEnum_.WriteTo(ref output, _repeated_packedEnum_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += packedInt32_.CalculateSize(_repeated_packedInt32_codec);
      size += packedInt64_.CalculateSize(_repeated_packedInt64_codec);
      size += packedUint32_.CalculateSize(_repeated_packedUint32_codec);
      size += packedUint64_.CalculateSize(_repeated_packedUint64_codec);
      size += packedSint32_.CalculateSize(_repeated_packedSint32_codec);
      size += packedSint64_.CalculateSize(_repeated_packedSint64_codec);
      size += packedFixed32_.CalculateSize(_repeated_packedFixed32_codec);
      size += packedFixed64_.CalculateSize(_repeated_packedFixed64_codec);
      size += packedSfixed32_.CalculateSize(_repeated_packedSfixed32_codec);
      size += packedSfixed64_.CalculateSize(_repeated_packedSfixed64_codec);
      size += packedFloat_.CalculateSize(_repeated_packedFloat_codec);
      size += packedDouble_.CalculateSize(_repeated_packedDouble_codec);
      size += packedBool_.CalculateSize(_repeated_packedBool_codec);
      size += packedEnum_.CalculateSize(_repeated_packedEnum_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestPackedTypes other) {
      if (other == null) {
        return;
      }
      packedInt32_.Add(other.packedInt32_);
      packedInt64_.Add(other.packedInt64_);
      packedUint32_.Add(other.packedUint32_);
      packedUint64_.Add(other.packedUint64_);
      packedSint32_.Add(other.packedSint32_);
      packedSint64_.Add(other.packedSint64_);
      packedFixed32_.Add(other.packedFixed32_);
      packedFixed64_.Add(other.packedFixed64_);
      packedSfixed32_.Add(other.packedSfixed32_);
      packedSfixed64_.Add(other.packedSfixed64_);
      packedFloat_.Add(other.packedFloat_);
      packedDouble_.Add(other.packedDouble_);
      packedBool_.Add(other.packedBool_);
      packedEnum_.Add(other.packedEnum_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 722:
          case 720: {
            packedInt32_.AddEntriesFrom(input, _repeated_packedInt32_codec);
            break;
          }
          case 730:
          case 728: {
            packedInt64_.AddEntriesFrom(input, _repeated_packedInt64_codec);
            break;
          }
          case 738:
          case 736: {
            packedUint32_.AddEntriesFrom(input, _repeated_packedUint32_codec);
            break;
          }
          case 746:
          case 744: {
            packedUint64_.AddEntriesFrom(input, _repeated_packedUint64_codec);
            break;
          }
          case 754:
          case 752: {
            packedSint32_.AddEntriesFrom(input, _repeated_packedSint32_codec);
            break;
          }
          case 762:
          case 760: {
            packedSint64_.AddEntriesFrom(input, _repeated_packedSint64_codec);
            break;
          }
          case 770:
          case 773: {
            packedFixed32_.AddEntriesFrom(input, _repeated_packedFixed32_codec);
            break;
          }
          case 778:
          case 777: {
            packedFixed64_.AddEntriesFrom(input, _repeated_packedFixed64_codec);
            break;
          }
          case 786:
          case 789: {
            packedSfixed32_.AddEntriesFrom(input, _repeated_packedSfixed32_codec);
            break;
          }
          case 794:
          case 793: {
            packedSfixed64_.AddEntriesFrom(input, _repeated_packedSfixed64_codec);
            break;
          }
          case 802:
          case 805: {
            packedFloat_.AddEntriesFrom(input, _repeated_packedFloat_codec);
            break;
          }
          case 810:
          case 809: {
            packedDouble_.AddEntriesFrom(input, _repeated_packedDouble_codec);
            break;
          }
          case 818:
          case 816: {
            packedBool_.AddEntriesFrom(input, _repeated_packedBool_codec);
            break;
          }
          case 826:
          case 824: {
            packedEnum_.AddEntriesFrom(input, _repeated_packedEnum_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 722:
          case 720: {
            packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec);
            break;
          }
          case 730:
          case 728: {
            packedInt64_.AddEntriesFrom(ref input, _repeated_packedInt64_codec);
            break;
          }
          case 738:
          case 736: {
            packedUint32_.AddEntriesFrom(ref input, _repeated_packedUint32_codec);
            break;
          }
          case 746:
          case 744: {
            packedUint64_.AddEntriesFrom(ref input, _repeated_packedUint64_codec);
            break;
          }
          case 754:
          case 752: {
            packedSint32_.AddEntriesFrom(ref input, _repeated_packedSint32_codec);
            break;
          }
          case 762:
          case 760: {
            packedSint64_.AddEntriesFrom(ref input, _repeated_packedSint64_codec);
            break;
          }
          case 770:
          case 773: {
            packedFixed32_.AddEntriesFrom(ref input, _repeated_packedFixed32_codec);
            break;
          }
          case 778:
          case 777: {
            packedFixed64_.AddEntriesFrom(ref input, _repeated_packedFixed64_codec);
            break;
          }
          case 786:
          case 789: {
            packedSfixed32_.AddEntriesFrom(ref input, _repeated_packedSfixed32_codec);
            break;
          }
          case 794:
          case 793: {
            packedSfixed64_.AddEntriesFrom(ref input, _repeated_packedSfixed64_codec);
            break;
          }
          case 802:
          case 805: {
            packedFloat_.AddEntriesFrom(ref input, _repeated_packedFloat_codec);
            break;
          }
          case 810:
          case 809: {
            packedDouble_.AddEntriesFrom(ref input, _repeated_packedDouble_codec);
            break;
          }
          case 818:
          case 816: {
            packedBool_.AddEntriesFrom(ref input, _repeated_packedBool_codec);
            break;
          }
          case 826:
          case 824: {
            packedEnum_.AddEntriesFrom(ref input, _repeated_packedEnum_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// A message with the same fields as TestPackedTypes, but without packing. Used
  /// to test packed &lt;-> unpacked wire compatibility.
  /// </summary>
  public sealed partial class TestUnpackedTypes : pb::IMessage<TestUnpackedTypes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestUnpackedTypes> _parser = new pb::MessageParser<TestUnpackedTypes>(() => new TestUnpackedTypes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestUnpackedTypes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[49]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedTypes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedTypes(TestUnpackedTypes other) : this() {
      unpackedInt32_ = other.unpackedInt32_.Clone();
      unpackedInt64_ = other.unpackedInt64_.Clone();
      unpackedUint32_ = other.unpackedUint32_.Clone();
      unpackedUint64_ = other.unpackedUint64_.Clone();
      unpackedSint32_ = other.unpackedSint32_.Clone();
      unpackedSint64_ = other.unpackedSint64_.Clone();
      unpackedFixed32_ = other.unpackedFixed32_.Clone();
      unpackedFixed64_ = other.unpackedFixed64_.Clone();
      unpackedSfixed32_ = other.unpackedSfixed32_.Clone();
      unpackedSfixed64_ = other.unpackedSfixed64_.Clone();
      unpackedFloat_ = other.unpackedFloat_.Clone();
      unpackedDouble_ = other.unpackedDouble_.Clone();
      unpackedBool_ = other.unpackedBool_.Clone();
      unpackedEnum_ = other.unpackedEnum_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedTypes Clone() {
      return new TestUnpackedTypes(this);
    }

    /// <summary>Field number for the "unpacked_int32" field.</summary>
    public const int UnpackedInt32FieldNumber = 90;
    private static readonly pb::FieldCodec<int> _repeated_unpackedInt32_codec
        = pb::FieldCodec.ForInt32(720);
    private readonly pbc::RepeatedField<int> unpackedInt32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> UnpackedInt32 {
      get { return unpackedInt32_; }
    }

    /// <summary>Field number for the "unpacked_int64" field.</summary>
    public const int UnpackedInt64FieldNumber = 91;
    private static readonly pb::FieldCodec<long> _repeated_unpackedInt64_codec
        = pb::FieldCodec.ForInt64(728);
    private readonly pbc::RepeatedField<long> unpackedInt64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> UnpackedInt64 {
      get { return unpackedInt64_; }
    }

    /// <summary>Field number for the "unpacked_uint32" field.</summary>
    public const int UnpackedUint32FieldNumber = 92;
    private static readonly pb::FieldCodec<uint> _repeated_unpackedUint32_codec
        = pb::FieldCodec.ForUInt32(736);
    private readonly pbc::RepeatedField<uint> unpackedUint32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> UnpackedUint32 {
      get { return unpackedUint32_; }
    }

    /// <summary>Field number for the "unpacked_uint64" field.</summary>
    public const int UnpackedUint64FieldNumber = 93;
    private static readonly pb::FieldCodec<ulong> _repeated_unpackedUint64_codec
        = pb::FieldCodec.ForUInt64(744);
    private readonly pbc::RepeatedField<ulong> unpackedUint64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> UnpackedUint64 {
      get { return unpackedUint64_; }
    }

    /// <summary>Field number for the "unpacked_sint32" field.</summary>
    public const int UnpackedSint32FieldNumber = 94;
    private static readonly pb::FieldCodec<int> _repeated_unpackedSint32_codec
        = pb::FieldCodec.ForSInt32(752);
    private readonly pbc::RepeatedField<int> unpackedSint32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> UnpackedSint32 {
      get { return unpackedSint32_; }
    }

    /// <summary>Field number for the "unpacked_sint64" field.</summary>
    public const int UnpackedSint64FieldNumber = 95;
    private static readonly pb::FieldCodec<long> _repeated_unpackedSint64_codec
        = pb::FieldCodec.ForSInt64(760);
    private readonly pbc::RepeatedField<long> unpackedSint64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> UnpackedSint64 {
      get { return unpackedSint64_; }
    }

    /// <summary>Field number for the "unpacked_fixed32" field.</summary>
    public const int UnpackedFixed32FieldNumber = 96;
    private static readonly pb::FieldCodec<uint> _repeated_unpackedFixed32_codec
        = pb::FieldCodec.ForFixed32(773);
    private readonly pbc::RepeatedField<uint> unpackedFixed32_ = new pbc::RepeatedField<uint>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> UnpackedFixed32 {
      get { return unpackedFixed32_; }
    }

    /// <summary>Field number for the "unpacked_fixed64" field.</summary>
    public const int UnpackedFixed64FieldNumber = 97;
    private static readonly pb::FieldCodec<ulong> _repeated_unpackedFixed64_codec
        = pb::FieldCodec.ForFixed64(777);
    private readonly pbc::RepeatedField<ulong> unpackedFixed64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> UnpackedFixed64 {
      get { return unpackedFixed64_; }
    }

    /// <summary>Field number for the "unpacked_sfixed32" field.</summary>
    public const int UnpackedSfixed32FieldNumber = 98;
    private static readonly pb::FieldCodec<int> _repeated_unpackedSfixed32_codec
        = pb::FieldCodec.ForSFixed32(789);
    private readonly pbc::RepeatedField<int> unpackedSfixed32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> UnpackedSfixed32 {
      get { return unpackedSfixed32_; }
    }

    /// <summary>Field number for the "unpacked_sfixed64" field.</summary>
    public const int UnpackedSfixed64FieldNumber = 99;
    private static readonly pb::FieldCodec<long> _repeated_unpackedSfixed64_codec
        = pb::FieldCodec.ForSFixed64(793);
    private readonly pbc::RepeatedField<long> unpackedSfixed64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> UnpackedSfixed64 {
      get { return unpackedSfixed64_; }
    }

    /// <summary>Field number for the "unpacked_float" field.</summary>
    public const int UnpackedFloatFieldNumber = 100;
    private static readonly pb::FieldCodec<float> _repeated_unpackedFloat_codec
        = pb::FieldCodec.ForFloat(805);
    private readonly pbc::RepeatedField<float> unpackedFloat_ = new pbc::RepeatedField<float>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<float> UnpackedFloat {
      get { return unpackedFloat_; }
    }

    /// <summary>Field number for the "unpacked_double" field.</summary>
    public const int UnpackedDoubleFieldNumber = 101;
    private static readonly pb::FieldCodec<double> _repeated_unpackedDouble_codec
        = pb::FieldCodec.ForDouble(809);
    private readonly pbc::RepeatedField<double> unpackedDouble_ = new pbc::RepeatedField<double>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<double> UnpackedDouble {
      get { return unpackedDouble_; }
    }

    /// <summary>Field number for the "unpacked_bool" field.</summary>
    public const int UnpackedBoolFieldNumber = 102;
    private static readonly pb::FieldCodec<bool> _repeated_unpackedBool_codec
        = pb::FieldCodec.ForBool(816);
    private readonly pbc::RepeatedField<bool> unpackedBool_ = new pbc::RepeatedField<bool>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<bool> UnpackedBool {
      get { return unpackedBool_; }
    }

    /// <summary>Field number for the "unpacked_enum" field.</summary>
    public const int UnpackedEnumFieldNumber = 103;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> _repeated_unpackedEnum_codec
        = pb::FieldCodec.ForEnum(824, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) x);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> unpackedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.ForeignEnum> UnpackedEnum {
      get { return unpackedEnum_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestUnpackedTypes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestUnpackedTypes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if(!unpackedInt32_.Equals(other.unpackedInt32_)) return false;
      if(!unpackedInt64_.Equals(other.unpackedInt64_)) return false;
      if(!unpackedUint32_.Equals(other.unpackedUint32_)) return false;
      if(!unpackedUint64_.Equals(other.unpackedUint64_)) return false;
      if(!unpackedSint32_.Equals(other.unpackedSint32_)) return false;
      if(!unpackedSint64_.Equals(other.unpackedSint64_)) return false;
      if(!unpackedFixed32_.Equals(other.unpackedFixed32_)) return false;
      if(!unpackedFixed64_.Equals(other.unpackedFixed64_)) return false;
      if(!unpackedSfixed32_.Equals(other.unpackedSfixed32_)) return false;
      if(!unpackedSfixed64_.Equals(other.unpackedSfixed64_)) return false;
      if(!unpackedFloat_.Equals(other.unpackedFloat_)) return false;
      if(!unpackedDouble_.Equals(other.unpackedDouble_)) return false;
      if(!unpackedBool_.Equals(other.unpackedBool_)) return false;
      if(!unpackedEnum_.Equals(other.unpackedEnum_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= unpackedInt32_.GetHashCode();
      hash ^= unpackedInt64_.GetHashCode();
      hash ^= unpackedUint32_.GetHashCode();
      hash ^= unpackedUint64_.GetHashCode();
      hash ^= unpackedSint32_.GetHashCode();
      hash ^= unpackedSint64_.GetHashCode();
      hash ^= unpackedFixed32_.GetHashCode();
      hash ^= unpackedFixed64_.GetHashCode();
      hash ^= unpackedSfixed32_.GetHashCode();
      hash ^= unpackedSfixed64_.GetHashCode();
      hash ^= unpackedFloat_.GetHashCode();
      hash ^= unpackedDouble_.GetHashCode();
      hash ^= unpackedBool_.GetHashCode();
      hash ^= unpackedEnum_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      unpackedInt32_.WriteTo(output, _repeated_unpackedInt32_codec);
      unpackedInt64_.WriteTo(output, _repeated_unpackedInt64_codec);
      unpackedUint32_.WriteTo(output, _repeated_unpackedUint32_codec);
      unpackedUint64_.WriteTo(output, _repeated_unpackedUint64_codec);
      unpackedSint32_.WriteTo(output, _repeated_unpackedSint32_codec);
      unpackedSint64_.WriteTo(output, _repeated_unpackedSint64_codec);
      unpackedFixed32_.WriteTo(output, _repeated_unpackedFixed32_codec);
      unpackedFixed64_.WriteTo(output, _repeated_unpackedFixed64_codec);
      unpackedSfixed32_.WriteTo(output, _repeated_unpackedSfixed32_codec);
      unpackedSfixed64_.WriteTo(output, _repeated_unpackedSfixed64_codec);
      unpackedFloat_.WriteTo(output, _repeated_unpackedFloat_codec);
      unpackedDouble_.WriteTo(output, _repeated_unpackedDouble_codec);
      unpackedBool_.WriteTo(output, _repeated_unpackedBool_codec);
      unpackedEnum_.WriteTo(output, _repeated_unpackedEnum_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      unpackedInt32_.WriteTo(ref output, _repeated_unpackedInt32_codec);
      unpackedInt64_.WriteTo(ref output, _repeated_unpackedInt64_codec);
      unpackedUint32_.WriteTo(ref output, _repeated_unpackedUint32_codec);
      unpackedUint64_.WriteTo(ref output, _repeated_unpackedUint64_codec);
      unpackedSint32_.WriteTo(ref output, _repeated_unpackedSint32_codec);
      unpackedSint64_.WriteTo(ref output, _repeated_unpackedSint64_codec);
      unpackedFixed32_.WriteTo(ref output, _repeated_unpackedFixed32_codec);
      unpackedFixed64_.WriteTo(ref output, _repeated_unpackedFixed64_codec);
      unpackedSfixed32_.WriteTo(ref output, _repeated_unpackedSfixed32_codec);
      unpackedSfixed64_.WriteTo(ref output, _repeated_unpackedSfixed64_codec);
      unpackedFloat_.WriteTo(ref output, _repeated_unpackedFloat_codec);
      unpackedDouble_.WriteTo(ref output, _repeated_unpackedDouble_codec);
      unpackedBool_.WriteTo(ref output, _repeated_unpackedBool_codec);
      unpackedEnum_.WriteTo(ref output, _repeated_unpackedEnum_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += unpackedInt32_.CalculateSize(_repeated_unpackedInt32_codec);
      size += unpackedInt64_.CalculateSize(_repeated_unpackedInt64_codec);
      size += unpackedUint32_.CalculateSize(_repeated_unpackedUint32_codec);
      size += unpackedUint64_.CalculateSize(_repeated_unpackedUint64_codec);
      size += unpackedSint32_.CalculateSize(_repeated_unpackedSint32_codec);
      size += unpackedSint64_.CalculateSize(_repeated_unpackedSint64_codec);
      size += unpackedFixed32_.CalculateSize(_repeated_unpackedFixed32_codec);
      size += unpackedFixed64_.CalculateSize(_repeated_unpackedFixed64_codec);
      size += unpackedSfixed32_.CalculateSize(_repeated_unpackedSfixed32_codec);
      size += unpackedSfixed64_.CalculateSize(_repeated_unpackedSfixed64_codec);
      size += unpackedFloat_.CalculateSize(_repeated_unpackedFloat_codec);
      size += unpackedDouble_.CalculateSize(_repeated_unpackedDouble_codec);
      size += unpackedBool_.CalculateSize(_repeated_unpackedBool_codec);
      size += unpackedEnum_.CalculateSize(_repeated_unpackedEnum_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestUnpackedTypes other) {
      if (other == null) {
        return;
      }
      unpackedInt32_.Add(other.unpackedInt32_);
      unpackedInt64_.Add(other.unpackedInt64_);
      unpackedUint32_.Add(other.unpackedUint32_);
      unpackedUint64_.Add(other.unpackedUint64_);
      unpackedSint32_.Add(other.unpackedSint32_);
      unpackedSint64_.Add(other.unpackedSint64_);
      unpackedFixed32_.Add(other.unpackedFixed32_);
      unpackedFixed64_.Add(other.unpackedFixed64_);
      unpackedSfixed32_.Add(other.unpackedSfixed32_);
      unpackedSfixed64_.Add(other.unpackedSfixed64_);
      unpackedFloat_.Add(other.unpackedFloat_);
      unpackedDouble_.Add(other.unpackedDouble_);
      unpackedBool_.Add(other.unpackedBool_);
      unpackedEnum_.Add(other.unpackedEnum_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 722:
          case 720: {
            unpackedInt32_.AddEntriesFrom(input, _repeated_unpackedInt32_codec);
            break;
          }
          case 730:
          case 728: {
            unpackedInt64_.AddEntriesFrom(input, _repeated_unpackedInt64_codec);
            break;
          }
          case 738:
          case 736: {
            unpackedUint32_.AddEntriesFrom(input, _repeated_unpackedUint32_codec);
            break;
          }
          case 746:
          case 744: {
            unpackedUint64_.AddEntriesFrom(input, _repeated_unpackedUint64_codec);
            break;
          }
          case 754:
          case 752: {
            unpackedSint32_.AddEntriesFrom(input, _repeated_unpackedSint32_codec);
            break;
          }
          case 762:
          case 760: {
            unpackedSint64_.AddEntriesFrom(input, _repeated_unpackedSint64_codec);
            break;
          }
          case 770:
          case 773: {
            unpackedFixed32_.AddEntriesFrom(input, _repeated_unpackedFixed32_codec);
            break;
          }
          case 778:
          case 777: {
            unpackedFixed64_.AddEntriesFrom(input, _repeated_unpackedFixed64_codec);
            break;
          }
          case 786:
          case 789: {
            unpackedSfixed32_.AddEntriesFrom(input, _repeated_unpackedSfixed32_codec);
            break;
          }
          case 794:
          case 793: {
            unpackedSfixed64_.AddEntriesFrom(input, _repeated_unpackedSfixed64_codec);
            break;
          }
          case 802:
          case 805: {
            unpackedFloat_.AddEntriesFrom(input, _repeated_unpackedFloat_codec);
            break;
          }
          case 810:
          case 809: {
            unpackedDouble_.AddEntriesFrom(input, _repeated_unpackedDouble_codec);
            break;
          }
          case 818:
          case 816: {
            unpackedBool_.AddEntriesFrom(input, _repeated_unpackedBool_codec);
            break;
          }
          case 826:
          case 824: {
            unpackedEnum_.AddEntriesFrom(input, _repeated_unpackedEnum_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 722:
          case 720: {
            unpackedInt32_.AddEntriesFrom(ref input, _repeated_unpackedInt32_codec);
            break;
          }
          case 730:
          case 728: {
            unpackedInt64_.AddEntriesFrom(ref input, _repeated_unpackedInt64_codec);
            break;
          }
          case 738:
          case 736: {
            unpackedUint32_.AddEntriesFrom(ref input, _repeated_unpackedUint32_codec);
            break;
          }
          case 746:
          case 744: {
            unpackedUint64_.AddEntriesFrom(ref input, _repeated_unpackedUint64_codec);
            break;
          }
          case 754:
          case 752: {
            unpackedSint32_.AddEntriesFrom(ref input, _repeated_unpackedSint32_codec);
            break;
          }
          case 762:
          case 760: {
            unpackedSint64_.AddEntriesFrom(ref input, _repeated_unpackedSint64_codec);
            break;
          }
          case 770:
          case 773: {
            unpackedFixed32_.AddEntriesFrom(ref input, _repeated_unpackedFixed32_codec);
            break;
          }
          case 778:
          case 777: {
            unpackedFixed64_.AddEntriesFrom(ref input, _repeated_unpackedFixed64_codec);
            break;
          }
          case 786:
          case 789: {
            unpackedSfixed32_.AddEntriesFrom(ref input, _repeated_unpackedSfixed32_codec);
            break;
          }
          case 794:
          case 793: {
            unpackedSfixed64_.AddEntriesFrom(ref input, _repeated_unpackedSfixed64_codec);
            break;
          }
          case 802:
          case 805: {
            unpackedFloat_.AddEntriesFrom(ref input, _repeated_unpackedFloat_codec);
            break;
          }
          case 810:
          case 809: {
            unpackedDouble_.AddEntriesFrom(ref input, _repeated_unpackedDouble_codec);
            break;
          }
          case 818:
          case 816: {
            unpackedBool_.AddEntriesFrom(ref input, _repeated_unpackedBool_codec);
            break;
          }
          case 826:
          case 824: {
            unpackedEnum_.AddEntriesFrom(ref input, _repeated_unpackedEnum_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestPackedExtensions : pb::IExtendableMessage<TestPackedExtensions>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestPackedExtensions> _parser = new pb::MessageParser<TestPackedExtensions>(() => new TestPackedExtensions());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestPackedExtensions> _extensions;
    private pb::ExtensionSet<TestPackedExtensions> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestPackedExtensions> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[50]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedExtensions() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedExtensions(TestPackedExtensions other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestPackedExtensions Clone() {
      return new TestPackedExtensions(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestPackedExtensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestPackedExtensions other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestPackedExtensions other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestPackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestPackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestPackedExtensions, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestPackedExtensions, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestPackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestPackedExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestPackedExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  public sealed partial class TestUnpackedExtensions : pb::IExtendableMessage<TestUnpackedExtensions>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestUnpackedExtensions> _parser = new pb::MessageParser<TestUnpackedExtensions>(() => new TestUnpackedExtensions());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestUnpackedExtensions> _extensions;
    private pb::ExtensionSet<TestUnpackedExtensions> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestUnpackedExtensions> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[51]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedExtensions() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedExtensions(TestUnpackedExtensions other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestUnpackedExtensions Clone() {
      return new TestUnpackedExtensions(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestUnpackedExtensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestUnpackedExtensions other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestUnpackedExtensions other) {
      if (other == null) {
        return;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestUnpackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestUnpackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestUnpackedExtensions, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestUnpackedExtensions, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestUnpackedExtensions, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestUnpackedExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestUnpackedExtensions, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  /// <summary>
  /// Used by ExtensionSetTest/DynamicExtensions.  The test actually builds
  /// a set of extensions to TestAllExtensions dynamically, based on the fields
  /// of this message type.
  /// </summary>
  public sealed partial class TestDynamicExtensions : pb::IMessage<TestDynamicExtensions>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestDynamicExtensions> _parser = new pb::MessageParser<TestDynamicExtensions>(() => new TestDynamicExtensions());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestDynamicExtensions> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[52]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDynamicExtensions() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDynamicExtensions(TestDynamicExtensions other) : this() {
      _hasBits0 = other._hasBits0;
      scalarExtension_ = other.scalarExtension_;
      enumExtension_ = other.enumExtension_;
      dynamicEnumExtension_ = other.dynamicEnumExtension_;
      messageExtension_ = other.messageExtension_ != null ? other.messageExtension_.Clone() : null;
      dynamicMessageExtension_ = other.dynamicMessageExtension_ != null ? other.dynamicMessageExtension_.Clone() : null;
      repeatedExtension_ = other.repeatedExtension_.Clone();
      packedExtension_ = other.packedExtension_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestDynamicExtensions Clone() {
      return new TestDynamicExtensions(this);
    }

    /// <summary>Field number for the "scalar_extension" field.</summary>
    public const int ScalarExtensionFieldNumber = 2000;
    private readonly static uint ScalarExtensionDefaultValue = 0;

    private uint scalarExtension_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint ScalarExtension {
      get { if ((_hasBits0 & 1) != 0) { return scalarExtension_; } else { return ScalarExtensionDefaultValue; } }
      set {
        _hasBits0 |= 1;
        scalarExtension_ = value;
      }
    }
    /// <summary>Gets whether the "scalar_extension" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasScalarExtension {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "scalar_extension" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearScalarExtension() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "enum_extension" field.</summary>
    public const int EnumExtensionFieldNumber = 2001;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum EnumExtensionDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum enumExtension_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum EnumExtension {
      get { if ((_hasBits0 & 2) != 0) { return enumExtension_; } else { return EnumExtensionDefaultValue; } }
      set {
        _hasBits0 |= 2;
        enumExtension_ = value;
      }
    }
    /// <summary>Gets whether the "enum_extension" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasEnumExtension {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "enum_extension" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearEnumExtension() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "dynamic_enum_extension" field.</summary>
    public const int DynamicEnumExtensionFieldNumber = 2002;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType DynamicEnumExtensionDefaultValue = global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType.DynamicFoo;

    private global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType dynamicEnumExtension_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType DynamicEnumExtension {
      get { if ((_hasBits0 & 4) != 0) { return dynamicEnumExtension_; } else { return DynamicEnumExtensionDefaultValue; } }
      set {
        _hasBits0 |= 4;
        dynamicEnumExtension_ = value;
      }
    }
    /// <summary>Gets whether the "dynamic_enum_extension" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasDynamicEnumExtension {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "dynamic_enum_extension" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearDynamicEnumExtension() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "message_extension" field.</summary>
    public const int MessageExtensionFieldNumber = 2003;
    private global::Google.Protobuf.TestProtos.Proto2.ForeignMessage messageExtension_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignMessage MessageExtension {
      get { return messageExtension_; }
      set {
        messageExtension_ = value;
      }
    }

    /// <summary>Field number for the "dynamic_message_extension" field.</summary>
    public const int DynamicMessageExtensionFieldNumber = 2004;
    private global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType dynamicMessageExtension_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType DynamicMessageExtension {
      get { return dynamicMessageExtension_; }
      set {
        dynamicMessageExtension_ = value;
      }
    }

    /// <summary>Field number for the "repeated_extension" field.</summary>
    public const int RepeatedExtensionFieldNumber = 2005;
    private static readonly pb::FieldCodec<string> _repeated_repeatedExtension_codec
        = pb::FieldCodec.ForString(16042);
    private readonly pbc::RepeatedField<string> repeatedExtension_ = new pbc::RepeatedField<string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<string> RepeatedExtension {
      get { return repeatedExtension_; }
    }

    /// <summary>Field number for the "packed_extension" field.</summary>
    public const int PackedExtensionFieldNumber = 2006;
    private static readonly pb::FieldCodec<int> _repeated_packedExtension_codec
        = pb::FieldCodec.ForSInt32(16050);
    private readonly pbc::RepeatedField<int> packedExtension_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> PackedExtension {
      get { return packedExtension_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestDynamicExtensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestDynamicExtensions other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (ScalarExtension != other.ScalarExtension) return false;
      if (EnumExtension != other.EnumExtension) return false;
      if (DynamicEnumExtension != other.DynamicEnumExtension) return false;
      if (!object.Equals(MessageExtension, other.MessageExtension)) return false;
      if (!object.Equals(DynamicMessageExtension, other.DynamicMessageExtension)) return false;
      if(!repeatedExtension_.Equals(other.repeatedExtension_)) return false;
      if(!packedExtension_.Equals(other.packedExtension_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasScalarExtension) hash ^= ScalarExtension.GetHashCode();
      if (HasEnumExtension) hash ^= EnumExtension.GetHashCode();
      if (HasDynamicEnumExtension) hash ^= DynamicEnumExtension.GetHashCode();
      if (messageExtension_ != null) hash ^= MessageExtension.GetHashCode();
      if (dynamicMessageExtension_ != null) hash ^= DynamicMessageExtension.GetHashCode();
      hash ^= repeatedExtension_.GetHashCode();
      hash ^= packedExtension_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasScalarExtension) {
        output.WriteRawTag(133, 125);
        output.WriteFixed32(ScalarExtension);
      }
      if (HasEnumExtension) {
        output.WriteRawTag(136, 125);
        output.WriteEnum((int) EnumExtension);
      }
      if (HasDynamicEnumExtension) {
        output.WriteRawTag(144, 125);
        output.WriteEnum((int) DynamicEnumExtension);
      }
      if (messageExtension_ != null) {
        output.WriteRawTag(154, 125);
        output.WriteMessage(MessageExtension);
      }
      if (dynamicMessageExtension_ != null) {
        output.WriteRawTag(162, 125);
        output.WriteMessage(DynamicMessageExtension);
      }
      repeatedExtension_.WriteTo(output, _repeated_repeatedExtension_codec);
      packedExtension_.WriteTo(output, _repeated_packedExtension_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasScalarExtension) {
        output.WriteRawTag(133, 125);
        output.WriteFixed32(ScalarExtension);
      }
      if (HasEnumExtension) {
        output.WriteRawTag(136, 125);
        output.WriteEnum((int) EnumExtension);
      }
      if (HasDynamicEnumExtension) {
        output.WriteRawTag(144, 125);
        output.WriteEnum((int) DynamicEnumExtension);
      }
      if (messageExtension_ != null) {
        output.WriteRawTag(154, 125);
        output.WriteMessage(MessageExtension);
      }
      if (dynamicMessageExtension_ != null) {
        output.WriteRawTag(162, 125);
        output.WriteMessage(DynamicMessageExtension);
      }
      repeatedExtension_.WriteTo(ref output, _repeated_repeatedExtension_codec);
      packedExtension_.WriteTo(ref output, _repeated_packedExtension_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasScalarExtension) {
        size += 2 + 4;
      }
      if (HasEnumExtension) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) EnumExtension);
      }
      if (HasDynamicEnumExtension) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) DynamicEnumExtension);
      }
      if (messageExtension_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(MessageExtension);
      }
      if (dynamicMessageExtension_ != null) {
        size += 2 + pb::CodedOutputStream.ComputeMessageSize(DynamicMessageExtension);
      }
      size += repeatedExtension_.CalculateSize(_repeated_repeatedExtension_codec);
      size += packedExtension_.CalculateSize(_repeated_packedExtension_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestDynamicExtensions other) {
      if (other == null) {
        return;
      }
      if (other.HasScalarExtension) {
        ScalarExtension = other.ScalarExtension;
      }
      if (other.HasEnumExtension) {
        EnumExtension = other.EnumExtension;
      }
      if (other.HasDynamicEnumExtension) {
        DynamicEnumExtension = other.DynamicEnumExtension;
      }
      if (other.messageExtension_ != null) {
        if (messageExtension_ == null) {
          MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
        }
        MessageExtension.MergeFrom(other.MessageExtension);
      }
      if (other.dynamicMessageExtension_ != null) {
        if (dynamicMessageExtension_ == null) {
          DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType();
        }
        DynamicMessageExtension.MergeFrom(other.DynamicMessageExtension);
      }
      repeatedExtension_.Add(other.repeatedExtension_);
      packedExtension_.Add(other.packedExtension_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 16005: {
            ScalarExtension = input.ReadFixed32();
            break;
          }
          case 16008: {
            EnumExtension = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 16016: {
            DynamicEnumExtension = (global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType) input.ReadEnum();
            break;
          }
          case 16026: {
            if (messageExtension_ == null) {
              MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(MessageExtension);
            break;
          }
          case 16034: {
            if (dynamicMessageExtension_ == null) {
              DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType();
            }
            input.ReadMessage(DynamicMessageExtension);
            break;
          }
          case 16042: {
            repeatedExtension_.AddEntriesFrom(input, _repeated_repeatedExtension_codec);
            break;
          }
          case 16050:
          case 16048: {
            packedExtension_.AddEntriesFrom(input, _repeated_packedExtension_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 16005: {
            ScalarExtension = input.ReadFixed32();
            break;
          }
          case 16008: {
            EnumExtension = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 16016: {
            DynamicEnumExtension = (global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType) input.ReadEnum();
            break;
          }
          case 16026: {
            if (messageExtension_ == null) {
              MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(MessageExtension);
            break;
          }
          case 16034: {
            if (dynamicMessageExtension_ == null) {
              DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType();
            }
            input.ReadMessage(DynamicMessageExtension);
            break;
          }
          case 16042: {
            repeatedExtension_.AddEntriesFrom(ref input, _repeated_repeatedExtension_codec);
            break;
          }
          case 16050:
          case 16048: {
            packedExtension_.AddEntriesFrom(ref input, _repeated_packedExtension_codec);
            break;
          }
        }
      }
    }
    #endif

    #region Nested types
    /// <summary>Container for nested types declared in the TestDynamicExtensions message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public enum DynamicEnumType {
        [pbr::OriginalName("DYNAMIC_FOO")] DynamicFoo = 2200,
        [pbr::OriginalName("DYNAMIC_BAR")] DynamicBar = 2201,
        [pbr::OriginalName("DYNAMIC_BAZ")] DynamicBaz = 2202,
      }

      public sealed partial class DynamicMessageType : pb::IMessage<DynamicMessageType>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<DynamicMessageType> _parser = new pb::MessageParser<DynamicMessageType>(() => new DynamicMessageType());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<DynamicMessageType> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public DynamicMessageType() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public DynamicMessageType(DynamicMessageType other) : this() {
          _hasBits0 = other._hasBits0;
          dynamicField_ = other.dynamicField_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public DynamicMessageType Clone() {
          return new DynamicMessageType(this);
        }

        /// <summary>Field number for the "dynamic_field" field.</summary>
        public const int DynamicFieldFieldNumber = 2100;
        private readonly static int DynamicFieldDefaultValue = 0;

        private int dynamicField_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int DynamicField {
          get { if ((_hasBits0 & 1) != 0) { return dynamicField_; } else { return DynamicFieldDefaultValue; } }
          set {
            _hasBits0 |= 1;
            dynamicField_ = value;
          }
        }
        /// <summary>Gets whether the "dynamic_field" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasDynamicField {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "dynamic_field" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearDynamicField() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as DynamicMessageType);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(DynamicMessageType other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (DynamicField != other.DynamicField) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasDynamicField) hash ^= DynamicField.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasDynamicField) {
            output.WriteRawTag(160, 131, 1);
            output.WriteInt32(DynamicField);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasDynamicField) {
            output.WriteRawTag(160, 131, 1);
            output.WriteInt32(DynamicField);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasDynamicField) {
            size += 3 + pb::CodedOutputStream.ComputeInt32Size(DynamicField);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(DynamicMessageType other) {
          if (other == null) {
            return;
          }
          if (other.HasDynamicField) {
            DynamicField = other.DynamicField;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 16800: {
                DynamicField = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 16800: {
                DynamicField = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage<TestRepeatedScalarDifferentTagSizes>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestRepeatedScalarDifferentTagSizes> _parser = new pb::MessageParser<TestRepeatedScalarDifferentTagSizes>(() => new TestRepeatedScalarDifferentTagSizes());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestRepeatedScalarDifferentTagSizes> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[53]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRepeatedScalarDifferentTagSizes() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRepeatedScalarDifferentTagSizes(TestRepeatedScalarDifferentTagSizes other) : this() {
      repeatedFixed32_ = other.repeatedFixed32_.Clone();
      repeatedInt32_ = other.repeatedInt32_.Clone();
      repeatedFixed64_ = other.repeatedFixed64_.Clone();
      repeatedInt64_ = other.repeatedInt64_.Clone();
      repeatedFloat_ = other.repeatedFloat_.Clone();
      repeatedUint64_ = other.repeatedUint64_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestRepeatedScalarDifferentTagSizes Clone() {
      return new TestRepeatedScalarDifferentTagSizes(this);
    }

    /// <summary>Field number for the "repeated_fixed32" field.</summary>
    public const int RepeatedFixed32FieldNumber = 12;
    private static readonly pb::FieldCodec<uint> _repeated_repeatedFixed32_codec
        = pb::FieldCodec.ForFixed32(101);
    private readonly pbc::RepeatedField<uint> repeatedFixed32_ = new pbc::RepeatedField<uint>();
    /// <summary>
    /// Parsing repeated fixed size values used to fail. This message needs to be
    /// used in order to get a tag of the right size; all of the repeated fields
    /// in TestAllTypes didn't trigger the check.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<uint> RepeatedFixed32 {
      get { return repeatedFixed32_; }
    }

    /// <summary>Field number for the "repeated_int32" field.</summary>
    public const int RepeatedInt32FieldNumber = 13;
    private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
        = pb::FieldCodec.ForInt32(104);
    private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
    /// <summary>
    /// Check for a varint type, just for good measure.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedInt32 {
      get { return repeatedInt32_; }
    }

    /// <summary>Field number for the "repeated_fixed64" field.</summary>
    public const int RepeatedFixed64FieldNumber = 2046;
    private static readonly pb::FieldCodec<ulong> _repeated_repeatedFixed64_codec
        = pb::FieldCodec.ForFixed64(16369);
    private readonly pbc::RepeatedField<ulong> repeatedFixed64_ = new pbc::RepeatedField<ulong>();
    /// <summary>
    /// These have two-byte tags.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> RepeatedFixed64 {
      get { return repeatedFixed64_; }
    }

    /// <summary>Field number for the "repeated_int64" field.</summary>
    public const int RepeatedInt64FieldNumber = 2047;
    private static readonly pb::FieldCodec<long> _repeated_repeatedInt64_codec
        = pb::FieldCodec.ForInt64(16376);
    private readonly pbc::RepeatedField<long> repeatedInt64_ = new pbc::RepeatedField<long>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<long> RepeatedInt64 {
      get { return repeatedInt64_; }
    }

    /// <summary>Field number for the "repeated_float" field.</summary>
    public const int RepeatedFloatFieldNumber = 262142;
    private static readonly pb::FieldCodec<float> _repeated_repeatedFloat_codec
        = pb::FieldCodec.ForFloat(2097141);
    private readonly pbc::RepeatedField<float> repeatedFloat_ = new pbc::RepeatedField<float>();
    /// <summary>
    /// Three byte tags.
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<float> RepeatedFloat {
      get { return repeatedFloat_; }
    }

    /// <summary>Field number for the "repeated_uint64" field.</summary>
    public const int RepeatedUint64FieldNumber = 262143;
    private static readonly pb::FieldCodec<ulong> _repeated_repeatedUint64_codec
        = pb::FieldCodec.ForUInt64(2097144);
    private readonly pbc::RepeatedField<ulong> repeatedUint64_ = new pbc::RepeatedField<ulong>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<ulong> RepeatedUint64 {
      get { return repeatedUint64_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestRepeatedScalarDifferentTagSizes);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestRepeatedScalarDifferentTagSizes other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if(!repeatedFixed32_.Equals(other.repeatedFixed32_)) return false;
      if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
      if(!repeatedFixed64_.Equals(other.repeatedFixed64_)) return false;
      if(!repeatedInt64_.Equals(other.repeatedInt64_)) return false;
      if(!repeatedFloat_.Equals(other.repeatedFloat_)) return false;
      if(!repeatedUint64_.Equals(other.repeatedUint64_)) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      hash ^= repeatedFixed32_.GetHashCode();
      hash ^= repeatedInt32_.GetHashCode();
      hash ^= repeatedFixed64_.GetHashCode();
      hash ^= repeatedInt64_.GetHashCode();
      hash ^= repeatedFloat_.GetHashCode();
      hash ^= repeatedUint64_.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
      repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
      repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
      repeatedInt64_.WriteTo(output, _repeated_repeatedInt64_codec);
      repeatedFloat_.WriteTo(output, _repeated_repeatedFloat_codec);
      repeatedUint64_.WriteTo(output, _repeated_repeatedUint64_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec);
      repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec);
      repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec);
      repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec);
      repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec);
      repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec);
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      size += repeatedFixed32_.CalculateSize(_repeated_repeatedFixed32_codec);
      size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
      size += repeatedFixed64_.CalculateSize(_repeated_repeatedFixed64_codec);
      size += repeatedInt64_.CalculateSize(_repeated_repeatedInt64_codec);
      size += repeatedFloat_.CalculateSize(_repeated_repeatedFloat_codec);
      size += repeatedUint64_.CalculateSize(_repeated_repeatedUint64_codec);
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestRepeatedScalarDifferentTagSizes other) {
      if (other == null) {
        return;
      }
      repeatedFixed32_.Add(other.repeatedFixed32_);
      repeatedInt32_.Add(other.repeatedInt32_);
      repeatedFixed64_.Add(other.repeatedFixed64_);
      repeatedInt64_.Add(other.repeatedInt64_);
      repeatedFloat_.Add(other.repeatedFloat_);
      repeatedUint64_.Add(other.repeatedUint64_);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 98:
          case 101: {
            repeatedFixed32_.AddEntriesFrom(input, _repeated_repeatedFixed32_codec);
            break;
          }
          case 106:
          case 104: {
            repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
            break;
          }
          case 16370:
          case 16369: {
            repeatedFixed64_.AddEntriesFrom(input, _repeated_repeatedFixed64_codec);
            break;
          }
          case 16378:
          case 16376: {
            repeatedInt64_.AddEntriesFrom(input, _repeated_repeatedInt64_codec);
            break;
          }
          case 2097138:
          case 2097141: {
            repeatedFloat_.AddEntriesFrom(input, _repeated_repeatedFloat_codec);
            break;
          }
          case 2097146:
          case 2097144: {
            repeatedUint64_.AddEntriesFrom(input, _repeated_repeatedUint64_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 98:
          case 101: {
            repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec);
            break;
          }
          case 106:
          case 104: {
            repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec);
            break;
          }
          case 16370:
          case 16369: {
            repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec);
            break;
          }
          case 16378:
          case 16376: {
            repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec);
            break;
          }
          case 2097138:
          case 2097141: {
            repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec);
            break;
          }
          case 2097146:
          case 2097144: {
            repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec);
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test that if an optional or required message/group field appears multiple
  /// times in the input, they need to be merged.
  /// </summary>
  public sealed partial class TestParsingMerge : pb::IExtendableMessage<TestParsingMerge>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestParsingMerge> _parser = new pb::MessageParser<TestParsingMerge>(() => new TestParsingMerge());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestParsingMerge> _extensions;
    private pb::ExtensionSet<TestParsingMerge> _Extensions { get { return _extensions; } }
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestParsingMerge> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[54]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestParsingMerge() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestParsingMerge(TestParsingMerge other) : this() {
      requiredAllTypes_ = other.requiredAllTypes_ != null ? other.requiredAllTypes_.Clone() : null;
      optionalAllTypes_ = other.optionalAllTypes_ != null ? other.optionalAllTypes_.Clone() : null;
      repeatedAllTypes_ = other.repeatedAllTypes_.Clone();
      optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null;
      repeatedGroup_ = other.repeatedGroup_.Clone();
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestParsingMerge Clone() {
      return new TestParsingMerge(this);
    }

    /// <summary>Field number for the "required_all_types" field.</summary>
    public const int RequiredAllTypesFieldNumber = 1;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes requiredAllTypes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes RequiredAllTypes {
      get { return requiredAllTypes_; }
      set {
        requiredAllTypes_ = value;
      }
    }

    /// <summary>Field number for the "optional_all_types" field.</summary>
    public const int OptionalAllTypesFieldNumber = 2;
    private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes optionalAllTypes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes OptionalAllTypes {
      get { return optionalAllTypes_; }
      set {
        optionalAllTypes_ = value;
      }
    }

    /// <summary>Field number for the "repeated_all_types" field.</summary>
    public const int RepeatedAllTypesFieldNumber = 3;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_repeatedAllTypes_codec
        = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> repeatedAllTypes_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> RepeatedAllTypes {
      get { return repeatedAllTypes_; }
    }

    /// <summary>Field number for the "optionalgroup" field.</summary>
    public const int OptionalGroupFieldNumber = 10;
    private global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup optionalGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup OptionalGroup {
      get { return optionalGroup_; }
      set {
        optionalGroup_ = value;
      }
    }
    /// <summary>Gets whether the optionalgroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalGroup {
      get { return optionalGroup_ != null; }
    }
    /// <summary>Clears the value of the optionalgroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalGroup() {
      optionalGroup_ = null;
    }

    /// <summary>Field number for the "repeatedgroup" field.</summary>
    public const int RepeatedGroupFieldNumber = 20;
    private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup> _repeated_repeatedGroup_codec
        = pb::FieldCodec.ForGroup(163, 164, global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup.Parser);
    private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup> repeatedGroup_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedGroup> RepeatedGroup {
      get { return repeatedGroup_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestParsingMerge);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestParsingMerge other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (!object.Equals(RequiredAllTypes, other.RequiredAllTypes)) return false;
      if (!object.Equals(OptionalAllTypes, other.OptionalAllTypes)) return false;
      if(!repeatedAllTypes_.Equals(other.repeatedAllTypes_)) return false;
      if (!object.Equals(OptionalGroup, other.OptionalGroup)) return false;
      if(!repeatedGroup_.Equals(other.repeatedGroup_)) return false;
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (requiredAllTypes_ != null) hash ^= RequiredAllTypes.GetHashCode();
      if (optionalAllTypes_ != null) hash ^= OptionalAllTypes.GetHashCode();
      hash ^= repeatedAllTypes_.GetHashCode();
      if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode();
      hash ^= repeatedGroup_.GetHashCode();
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (requiredAllTypes_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(RequiredAllTypes);
      }
      if (optionalAllTypes_ != null) {
        output.WriteRawTag(18);
        output.WriteMessage(OptionalAllTypes);
      }
      repeatedAllTypes_.WriteTo(output, _repeated_repeatedAllTypes_codec);
      if (HasOptionalGroup) {
        output.WriteRawTag(83);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(84);
      }
      repeatedGroup_.WriteTo(output, _repeated_repeatedGroup_codec);
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (requiredAllTypes_ != null) {
        output.WriteRawTag(10);
        output.WriteMessage(RequiredAllTypes);
      }
      if (optionalAllTypes_ != null) {
        output.WriteRawTag(18);
        output.WriteMessage(OptionalAllTypes);
      }
      repeatedAllTypes_.WriteTo(ref output, _repeated_repeatedAllTypes_codec);
      if (HasOptionalGroup) {
        output.WriteRawTag(83);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(84);
      }
      repeatedGroup_.WriteTo(ref output, _repeated_repeatedGroup_codec);
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (requiredAllTypes_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(RequiredAllTypes);
      }
      if (optionalAllTypes_ != null) {
        size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalAllTypes);
      }
      size += repeatedAllTypes_.CalculateSize(_repeated_repeatedAllTypes_codec);
      if (HasOptionalGroup) {
        size += 2 + pb::CodedOutputStream.ComputeGroupSize(OptionalGroup);
      }
      size += repeatedGroup_.CalculateSize(_repeated_repeatedGroup_codec);
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestParsingMerge other) {
      if (other == null) {
        return;
      }
      if (other.requiredAllTypes_ != null) {
        if (requiredAllTypes_ == null) {
          RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        RequiredAllTypes.MergeFrom(other.RequiredAllTypes);
      }
      if (other.optionalAllTypes_ != null) {
        if (optionalAllTypes_ == null) {
          OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
        }
        OptionalAllTypes.MergeFrom(other.OptionalAllTypes);
      }
      repeatedAllTypes_.Add(other.repeatedAllTypes_);
      if (other.HasOptionalGroup) {
        if (!HasOptionalGroup) {
          OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup();
        }
        OptionalGroup.MergeFrom(other.OptionalGroup);
      }
      repeatedGroup_.Add(other.repeatedGroup_);
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
          case 10: {
            if (requiredAllTypes_ == null) {
              RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(RequiredAllTypes);
            break;
          }
          case 18: {
            if (optionalAllTypes_ == null) {
              OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(OptionalAllTypes);
            break;
          }
          case 26: {
            repeatedAllTypes_.AddEntriesFrom(input, _repeated_repeatedAllTypes_codec);
            break;
          }
          case 83: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 163: {
            repeatedGroup_.AddEntriesFrom(input, _repeated_repeatedGroup_codec);
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
          case 10: {
            if (requiredAllTypes_ == null) {
              RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(RequiredAllTypes);
            break;
          }
          case 18: {
            if (optionalAllTypes_ == null) {
              OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            input.ReadMessage(OptionalAllTypes);
            break;
          }
          case 26: {
            repeatedAllTypes_.AddEntriesFrom(ref input, _repeated_repeatedAllTypes_codec);
            break;
          }
          case 83: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 163: {
            repeatedGroup_.AddEntriesFrom(ref input, _repeated_repeatedGroup_codec);
            break;
          }
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestParsingMerge, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestParsingMerge, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestParsingMerge, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestParsingMerge, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestParsingMerge, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestParsingMerge, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestParsingMerge, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

    #region Nested types
    /// <summary>Container for nested types declared in the TestParsingMerge message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      /// <summary>
      /// RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
      /// except that all fields are repeated. In the tests, we will serialize the
      /// RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
      /// Repeated fields in RepeatedFieldsGenerator are expected to be merged into
      /// the corresponding required/optional fields in TestParsingMerge.
      /// </summary>
      public sealed partial class RepeatedFieldsGenerator : pb::IMessage<RepeatedFieldsGenerator>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<RepeatedFieldsGenerator> _parser = new pb::MessageParser<RepeatedFieldsGenerator>(() => new RepeatedFieldsGenerator());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<RepeatedFieldsGenerator> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedFieldsGenerator() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedFieldsGenerator(RepeatedFieldsGenerator other) : this() {
          field1_ = other.field1_.Clone();
          field2_ = other.field2_.Clone();
          field3_ = other.field3_.Clone();
          group1_ = other.group1_.Clone();
          group2_ = other.group2_.Clone();
          ext1_ = other.ext1_.Clone();
          ext2_ = other.ext2_.Clone();
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedFieldsGenerator Clone() {
          return new RepeatedFieldsGenerator(this);
        }

        /// <summary>Field number for the "field1" field.</summary>
        public const int Field1FieldNumber = 1;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_field1_codec
            = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> field1_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> Field1 {
          get { return field1_; }
        }

        /// <summary>Field number for the "field2" field.</summary>
        public const int Field2FieldNumber = 2;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_field2_codec
            = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> field2_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> Field2 {
          get { return field2_; }
        }

        /// <summary>Field number for the "field3" field.</summary>
        public const int Field3FieldNumber = 3;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_field3_codec
            = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> field3_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> Field3 {
          get { return field3_; }
        }

        /// <summary>Field number for the "group1" field.</summary>
        public const int Group1FieldNumber = 10;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1> _repeated_group1_codec
            = pb::FieldCodec.ForGroup(83, 84, global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1> group1_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group1> Group1 {
          get { return group1_; }
        }

        /// <summary>Field number for the "group2" field.</summary>
        public const int Group2FieldNumber = 20;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2> _repeated_group2_codec
            = pb::FieldCodec.ForGroup(163, 164, global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2> group2_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Types.Group2> Group2 {
          get { return group2_; }
        }

        /// <summary>Field number for the "ext1" field.</summary>
        public const int Ext1FieldNumber = 1000;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_ext1_codec
            = pb::FieldCodec.ForMessage(8002, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> ext1_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> Ext1 {
          get { return ext1_; }
        }

        /// <summary>Field number for the "ext2" field.</summary>
        public const int Ext2FieldNumber = 1001;
        private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> _repeated_ext2_codec
            = pb::FieldCodec.ForMessage(8010, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser);
        private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> ext2_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>();
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public pbc::RepeatedField<global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> Ext2 {
          get { return ext2_; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as RepeatedFieldsGenerator);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(RepeatedFieldsGenerator other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if(!field1_.Equals(other.field1_)) return false;
          if(!field2_.Equals(other.field2_)) return false;
          if(!field3_.Equals(other.field3_)) return false;
          if(!group1_.Equals(other.group1_)) return false;
          if(!group2_.Equals(other.group2_)) return false;
          if(!ext1_.Equals(other.ext1_)) return false;
          if(!ext2_.Equals(other.ext2_)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          hash ^= field1_.GetHashCode();
          hash ^= field2_.GetHashCode();
          hash ^= field3_.GetHashCode();
          hash ^= group1_.GetHashCode();
          hash ^= group2_.GetHashCode();
          hash ^= ext1_.GetHashCode();
          hash ^= ext2_.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          field1_.WriteTo(output, _repeated_field1_codec);
          field2_.WriteTo(output, _repeated_field2_codec);
          field3_.WriteTo(output, _repeated_field3_codec);
          group1_.WriteTo(output, _repeated_group1_codec);
          group2_.WriteTo(output, _repeated_group2_codec);
          ext1_.WriteTo(output, _repeated_ext1_codec);
          ext2_.WriteTo(output, _repeated_ext2_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          field1_.WriteTo(ref output, _repeated_field1_codec);
          field2_.WriteTo(ref output, _repeated_field2_codec);
          field3_.WriteTo(ref output, _repeated_field3_codec);
          group1_.WriteTo(ref output, _repeated_group1_codec);
          group2_.WriteTo(ref output, _repeated_group2_codec);
          ext1_.WriteTo(ref output, _repeated_ext1_codec);
          ext2_.WriteTo(ref output, _repeated_ext2_codec);
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          size += field1_.CalculateSize(_repeated_field1_codec);
          size += field2_.CalculateSize(_repeated_field2_codec);
          size += field3_.CalculateSize(_repeated_field3_codec);
          size += group1_.CalculateSize(_repeated_group1_codec);
          size += group2_.CalculateSize(_repeated_group2_codec);
          size += ext1_.CalculateSize(_repeated_ext1_codec);
          size += ext2_.CalculateSize(_repeated_ext2_codec);
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(RepeatedFieldsGenerator other) {
          if (other == null) {
            return;
          }
          field1_.Add(other.field1_);
          field2_.Add(other.field2_);
          field3_.Add(other.field3_);
          group1_.Add(other.group1_);
          group2_.Add(other.group2_);
          ext1_.Add(other.ext1_);
          ext2_.Add(other.ext2_);
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 10: {
                field1_.AddEntriesFrom(input, _repeated_field1_codec);
                break;
              }
              case 18: {
                field2_.AddEntriesFrom(input, _repeated_field2_codec);
                break;
              }
              case 26: {
                field3_.AddEntriesFrom(input, _repeated_field3_codec);
                break;
              }
              case 83: {
                group1_.AddEntriesFrom(input, _repeated_group1_codec);
                break;
              }
              case 163: {
                group2_.AddEntriesFrom(input, _repeated_group2_codec);
                break;
              }
              case 8002: {
                ext1_.AddEntriesFrom(input, _repeated_ext1_codec);
                break;
              }
              case 8010: {
                ext2_.AddEntriesFrom(input, _repeated_ext2_codec);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 10: {
                field1_.AddEntriesFrom(ref input, _repeated_field1_codec);
                break;
              }
              case 18: {
                field2_.AddEntriesFrom(ref input, _repeated_field2_codec);
                break;
              }
              case 26: {
                field3_.AddEntriesFrom(ref input, _repeated_field3_codec);
                break;
              }
              case 83: {
                group1_.AddEntriesFrom(ref input, _repeated_group1_codec);
                break;
              }
              case 163: {
                group2_.AddEntriesFrom(ref input, _repeated_group2_codec);
                break;
              }
              case 8002: {
                ext1_.AddEntriesFrom(ref input, _repeated_ext1_codec);
                break;
              }
              case 8010: {
                ext2_.AddEntriesFrom(ref input, _repeated_ext2_codec);
                break;
              }
            }
          }
        }
        #endif

        #region Nested types
        /// <summary>Container for nested types declared in the RepeatedFieldsGenerator message type.</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static partial class Types {
          public sealed partial class Group1 : pb::IMessage<Group1>
          #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              , pb::IBufferMessage
          #endif
          {
            private static readonly pb::MessageParser<Group1> _parser = new pb::MessageParser<Group1>(() => new Group1());
            private pb::UnknownFieldSet _unknownFields;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pb::MessageParser<Group1> Parser { get { return _parser; } }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pbr::MessageDescriptor Descriptor {
              get { return global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Descriptor.NestedTypes[0]; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            pbr::MessageDescriptor pb::IMessage.Descriptor {
              get { return Descriptor; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group1() {
              OnConstruction();
            }

            partial void OnConstruction();

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group1(Group1 other) : this() {
              field1_ = other.field1_ != null ? other.field1_.Clone() : null;
              _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group1 Clone() {
              return new Group1(this);
            }

            /// <summary>Field number for the "field1" field.</summary>
            public const int Field1FieldNumber = 11;
            private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes field1_;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes Field1 {
              get { return field1_; }
              set {
                field1_ = value;
              }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override bool Equals(object other) {
              return Equals(other as Group1);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public bool Equals(Group1 other) {
              if (ReferenceEquals(other, null)) {
                return false;
              }
              if (ReferenceEquals(other, this)) {
                return true;
              }
              if (!object.Equals(Field1, other.Field1)) return false;
              return Equals(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override int GetHashCode() {
              int hash = 1;
              if (field1_ != null) hash ^= Field1.GetHashCode();
              if (_unknownFields != null) {
                hash ^= _unknownFields.GetHashCode();
              }
              return hash;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override string ToString() {
              return pb::JsonFormatter.ToDiagnosticString(this);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void WriteTo(pb::CodedOutputStream output) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              output.WriteRawMessage(this);
            #else
              if (field1_ != null) {
                output.WriteRawTag(90);
                output.WriteMessage(Field1);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(output);
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
              if (field1_ != null) {
                output.WriteRawTag(90);
                output.WriteMessage(Field1);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(ref output);
              }
            }
            #endif

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public int CalculateSize() {
              int size = 0;
              if (field1_ != null) {
                size += 1 + pb::CodedOutputStream.ComputeMessageSize(Field1);
              }
              if (_unknownFields != null) {
                size += _unknownFields.CalculateSize();
              }
              return size;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(Group1 other) {
              if (other == null) {
                return;
              }
              if (other.field1_ != null) {
                if (field1_ == null) {
                  Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                Field1.MergeFrom(other.Field1);
              }
              _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(pb::CodedInputStream input) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              input.ReadRawMessage(this);
            #else
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 84:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;
                  case 90: {
                    if (field1_ == null) {
                      Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                    }
                    input.ReadMessage(Field1);
                    break;
                  }
                }
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 84:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                    break;
                  case 90: {
                    if (field1_ == null) {
                      Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                    }
                    input.ReadMessage(Field1);
                    break;
                  }
                }
              }
            }
            #endif

          }

          public sealed partial class Group2 : pb::IMessage<Group2>
          #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              , pb::IBufferMessage
          #endif
          {
            private static readonly pb::MessageParser<Group2> _parser = new pb::MessageParser<Group2>(() => new Group2());
            private pb::UnknownFieldSet _unknownFields;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pb::MessageParser<Group2> Parser { get { return _parser; } }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public static pbr::MessageDescriptor Descriptor {
              get { return global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.RepeatedFieldsGenerator.Descriptor.NestedTypes[1]; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            pbr::MessageDescriptor pb::IMessage.Descriptor {
              get { return Descriptor; }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group2() {
              OnConstruction();
            }

            partial void OnConstruction();

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group2(Group2 other) : this() {
              field1_ = other.field1_ != null ? other.field1_.Clone() : null;
              _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public Group2 Clone() {
              return new Group2(this);
            }

            /// <summary>Field number for the "field1" field.</summary>
            public const int Field1FieldNumber = 21;
            private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes field1_;
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes Field1 {
              get { return field1_; }
              set {
                field1_ = value;
              }
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override bool Equals(object other) {
              return Equals(other as Group2);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public bool Equals(Group2 other) {
              if (ReferenceEquals(other, null)) {
                return false;
              }
              if (ReferenceEquals(other, this)) {
                return true;
              }
              if (!object.Equals(Field1, other.Field1)) return false;
              return Equals(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override int GetHashCode() {
              int hash = 1;
              if (field1_ != null) hash ^= Field1.GetHashCode();
              if (_unknownFields != null) {
                hash ^= _unknownFields.GetHashCode();
              }
              return hash;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public override string ToString() {
              return pb::JsonFormatter.ToDiagnosticString(this);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void WriteTo(pb::CodedOutputStream output) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              output.WriteRawMessage(this);
            #else
              if (field1_ != null) {
                output.WriteRawTag(170, 1);
                output.WriteMessage(Field1);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(output);
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
              if (field1_ != null) {
                output.WriteRawTag(170, 1);
                output.WriteMessage(Field1);
              }
              if (_unknownFields != null) {
                _unknownFields.WriteTo(ref output);
              }
            }
            #endif

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public int CalculateSize() {
              int size = 0;
              if (field1_ != null) {
                size += 2 + pb::CodedOutputStream.ComputeMessageSize(Field1);
              }
              if (_unknownFields != null) {
                size += _unknownFields.CalculateSize();
              }
              return size;
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(Group2 other) {
              if (other == null) {
                return;
              }
              if (other.field1_ != null) {
                if (field1_ == null) {
                  Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                Field1.MergeFrom(other.Field1);
              }
              _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
            }

            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            public void MergeFrom(pb::CodedInputStream input) {
            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
              input.ReadRawMessage(this);
            #else
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 164:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;
                  case 170: {
                    if (field1_ == null) {
                      Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                    }
                    input.ReadMessage(Field1);
                    break;
                  }
                }
              }
            #endif
            }

            #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
            [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
            void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
              uint tag;
              while ((tag = input.ReadTag()) != 0) {
                switch(tag) {
                  case 164:
                    return;
                  default:
                    _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                    break;
                  case 170: {
                    if (field1_ == null) {
                      Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                    }
                    input.ReadMessage(Field1);
                    break;
                  }
                }
              }
            }
            #endif

          }

        }
        #endregion

      }

      public sealed partial class OptionalGroup : pb::IMessage<OptionalGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<OptionalGroup> _parser = new pb::MessageParser<OptionalGroup>(() => new OptionalGroup());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<OptionalGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Descriptor.NestedTypes[1]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup(OptionalGroup other) : this() {
          optionalGroupAllTypes_ = other.optionalGroupAllTypes_ != null ? other.optionalGroupAllTypes_.Clone() : null;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup Clone() {
          return new OptionalGroup(this);
        }

        /// <summary>Field number for the "optional_group_all_types" field.</summary>
        public const int OptionalGroupAllTypesFieldNumber = 11;
        private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes optionalGroupAllTypes_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes OptionalGroupAllTypes {
          get { return optionalGroupAllTypes_; }
          set {
            optionalGroupAllTypes_ = value;
          }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as OptionalGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(OptionalGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!object.Equals(OptionalGroupAllTypes, other.OptionalGroupAllTypes)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (optionalGroupAllTypes_ != null) hash ^= OptionalGroupAllTypes.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (optionalGroupAllTypes_ != null) {
            output.WriteRawTag(90);
            output.WriteMessage(OptionalGroupAllTypes);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (optionalGroupAllTypes_ != null) {
            output.WriteRawTag(90);
            output.WriteMessage(OptionalGroupAllTypes);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (optionalGroupAllTypes_ != null) {
            size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalGroupAllTypes);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(OptionalGroup other) {
          if (other == null) {
            return;
          }
          if (other.optionalGroupAllTypes_ != null) {
            if (optionalGroupAllTypes_ == null) {
              OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            OptionalGroupAllTypes.MergeFrom(other.OptionalGroupAllTypes);
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 84:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 90: {
                if (optionalGroupAllTypes_ == null) {
                  OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(OptionalGroupAllTypes);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 84:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 90: {
                if (optionalGroupAllTypes_ == null) {
                  OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(OptionalGroupAllTypes);
                break;
              }
            }
          }
        }
        #endif

      }

      public sealed partial class RepeatedGroup : pb::IMessage<RepeatedGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<RepeatedGroup> _parser = new pb::MessageParser<RepeatedGroup>(() => new RepeatedGroup());
        private pb::UnknownFieldSet _unknownFields;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<RepeatedGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Descriptor.NestedTypes[2]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup(RepeatedGroup other) : this() {
          repeatedGroupAllTypes_ = other.repeatedGroupAllTypes_ != null ? other.repeatedGroupAllTypes_.Clone() : null;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public RepeatedGroup Clone() {
          return new RepeatedGroup(this);
        }

        /// <summary>Field number for the "repeated_group_all_types" field.</summary>
        public const int RepeatedGroupAllTypesFieldNumber = 21;
        private global::Google.Protobuf.TestProtos.Proto2.TestAllTypes repeatedGroupAllTypes_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes RepeatedGroupAllTypes {
          get { return repeatedGroupAllTypes_; }
          set {
            repeatedGroupAllTypes_ = value;
          }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as RepeatedGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(RepeatedGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (!object.Equals(RepeatedGroupAllTypes, other.RepeatedGroupAllTypes)) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (repeatedGroupAllTypes_ != null) hash ^= RepeatedGroupAllTypes.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (repeatedGroupAllTypes_ != null) {
            output.WriteRawTag(170, 1);
            output.WriteMessage(RepeatedGroupAllTypes);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (repeatedGroupAllTypes_ != null) {
            output.WriteRawTag(170, 1);
            output.WriteMessage(RepeatedGroupAllTypes);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (repeatedGroupAllTypes_ != null) {
            size += 2 + pb::CodedOutputStream.ComputeMessageSize(RepeatedGroupAllTypes);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(RepeatedGroup other) {
          if (other == null) {
            return;
          }
          if (other.repeatedGroupAllTypes_ != null) {
            if (repeatedGroupAllTypes_ == null) {
              RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            }
            RepeatedGroupAllTypes.MergeFrom(other.RepeatedGroupAllTypes);
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 164:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 170: {
                if (repeatedGroupAllTypes_ == null) {
                  RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(RepeatedGroupAllTypes);
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 164:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 170: {
                if (repeatedGroupAllTypes_ == null) {
                  RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
                }
                input.ReadMessage(RepeatedGroupAllTypes);
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestParsingMerge message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Extensions {
      public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> OptionalExt =
        new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>(1000, pb::FieldCodec.ForMessage(8002, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser));
      public static readonly pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes> RepeatedExt =
        new pb::RepeatedExtension<global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes>(1001, pb::FieldCodec.ForMessage(8010, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Parser));
    }
    #endregion

  }

  public sealed partial class TestCommentInjectionMessage : pb::IMessage<TestCommentInjectionMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestCommentInjectionMessage> _parser = new pb::MessageParser<TestCommentInjectionMessage>(() => new TestCommentInjectionMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestCommentInjectionMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[55]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCommentInjectionMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCommentInjectionMessage(TestCommentInjectionMessage other) : this() {
      a_ = other.a_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestCommentInjectionMessage Clone() {
      return new TestCommentInjectionMessage(this);
    }

    /// <summary>Field number for the "a" field.</summary>
    public const int AFieldNumber = 1;
    private readonly static string ADefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("Ki8gPC0gTmVpdGhlciBzaG91bGQgdGhpcy4="), 0, 26);

    private string a_;
    /// <summary>
    /// */ &lt;- This should not close the generated doc comment
    /// </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string A {
      get { return a_ ?? ADefaultValue; }
      set {
        a_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "a" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasA {
      get { return a_ != null; }
    }
    /// <summary>Clears the value of the "a" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearA() {
      a_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestCommentInjectionMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestCommentInjectionMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (A != other.A) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasA) hash ^= A.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasA) {
        output.WriteRawTag(10);
        output.WriteString(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasA) {
        output.WriteRawTag(10);
        output.WriteString(A);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasA) {
        size += 1 + pb::CodedOutputStream.ComputeStringSize(A);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestCommentInjectionMessage other) {
      if (other == null) {
        return;
      }
      if (other.HasA) {
        A = other.A;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 10: {
            A = input.ReadString();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 10: {
            A = input.ReadString();
            break;
          }
        }
      }
    }
    #endif

  }

  /// <summary>
  /// Test that RPC services work.
  /// </summary>
  public sealed partial class FooRequest : pb::IMessage<FooRequest>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<FooRequest> _parser = new pb::MessageParser<FooRequest>(() => new FooRequest());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<FooRequest> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[56]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooRequest() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooRequest(FooRequest other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooRequest Clone() {
      return new FooRequest(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as FooRequest);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(FooRequest other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(FooRequest other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class FooResponse : pb::IMessage<FooResponse>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<FooResponse> _parser = new pb::MessageParser<FooResponse>(() => new FooResponse());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<FooResponse> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[57]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooResponse() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooResponse(FooResponse other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooResponse Clone() {
      return new FooResponse(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as FooResponse);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(FooResponse other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(FooResponse other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class FooClientMessage : pb::IMessage<FooClientMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<FooClientMessage> _parser = new pb::MessageParser<FooClientMessage>(() => new FooClientMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<FooClientMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[58]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooClientMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooClientMessage(FooClientMessage other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooClientMessage Clone() {
      return new FooClientMessage(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as FooClientMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(FooClientMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(FooClientMessage other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class FooServerMessage : pb::IMessage<FooServerMessage>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<FooServerMessage> _parser = new pb::MessageParser<FooServerMessage>(() => new FooServerMessage());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<FooServerMessage> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[59]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooServerMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooServerMessage(FooServerMessage other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public FooServerMessage Clone() {
      return new FooServerMessage(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as FooServerMessage);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(FooServerMessage other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(FooServerMessage other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class BarRequest : pb::IMessage<BarRequest>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<BarRequest> _parser = new pb::MessageParser<BarRequest>(() => new BarRequest());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<BarRequest> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[60]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarRequest() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarRequest(BarRequest other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarRequest Clone() {
      return new BarRequest(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as BarRequest);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(BarRequest other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(BarRequest other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class BarResponse : pb::IMessage<BarResponse>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<BarResponse> _parser = new pb::MessageParser<BarResponse>(() => new BarResponse());
    private pb::UnknownFieldSet _unknownFields;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<BarResponse> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[61]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarResponse() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarResponse(BarResponse other) : this() {
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public BarResponse Clone() {
      return new BarResponse(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as BarResponse);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(BarResponse other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(BarResponse other) {
      if (other == null) {
        return;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

  }

  public sealed partial class TestJsonName : pb::IMessage<TestJsonName>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestJsonName> _parser = new pb::MessageParser<TestJsonName>(() => new TestJsonName());
    private pb::UnknownFieldSet _unknownFields;
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestJsonName> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[62]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestJsonName() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestJsonName(TestJsonName other) : this() {
      _hasBits0 = other._hasBits0;
      fieldName1_ = other.fieldName1_;
      fieldName2_ = other.fieldName2_;
      fieldName3_ = other.fieldName3_;
      FieldName4_ = other.FieldName4_;
      fIELDNAME5_ = other.fIELDNAME5_;
      fieldName6_ = other.fieldName6_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestJsonName Clone() {
      return new TestJsonName(this);
    }

    /// <summary>Field number for the "field_name1" field.</summary>
    public const int FieldName1FieldNumber = 1;
    private readonly static int FieldName1DefaultValue = 0;

    private int fieldName1_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FieldName1 {
      get { if ((_hasBits0 & 1) != 0) { return fieldName1_; } else { return FieldName1DefaultValue; } }
      set {
        _hasBits0 |= 1;
        fieldName1_ = value;
      }
    }
    /// <summary>Gets whether the "field_name1" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldName1 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "field_name1" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldName1() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "fieldName2" field.</summary>
    public const int FieldName2FieldNumber = 2;
    private readonly static int FieldName2DefaultValue = 0;

    private int fieldName2_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FieldName2 {
      get { if ((_hasBits0 & 2) != 0) { return fieldName2_; } else { return FieldName2DefaultValue; } }
      set {
        _hasBits0 |= 2;
        fieldName2_ = value;
      }
    }
    /// <summary>Gets whether the "fieldName2" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldName2 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "fieldName2" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldName2() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "FieldName3" field.</summary>
    public const int FieldName3FieldNumber = 3;
    private readonly static int FieldName3DefaultValue = 0;

    private int fieldName3_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FieldName3 {
      get { if ((_hasBits0 & 4) != 0) { return fieldName3_; } else { return FieldName3DefaultValue; } }
      set {
        _hasBits0 |= 4;
        fieldName3_ = value;
      }
    }
    /// <summary>Gets whether the "FieldName3" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldName3 {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "FieldName3" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldName3() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "_field_name4" field.</summary>
    public const int FieldName4FieldNumber = 4;
    private readonly static int FieldName4DefaultValue = 0;

    private int FieldName4_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FieldName4 {
      get { if ((_hasBits0 & 8) != 0) { return FieldName4_; } else { return FieldName4DefaultValue; } }
      set {
        _hasBits0 |= 8;
        FieldName4_ = value;
      }
    }
    /// <summary>Gets whether the "_field_name4" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldName4 {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "_field_name4" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldName4() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "FIELD_NAME5" field.</summary>
    public const int FIELDNAME5FieldNumber = 5;
    private readonly static int FIELDNAME5DefaultValue = 0;

    private int fIELDNAME5_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FIELDNAME5 {
      get { if ((_hasBits0 & 16) != 0) { return fIELDNAME5_; } else { return FIELDNAME5DefaultValue; } }
      set {
        _hasBits0 |= 16;
        fIELDNAME5_ = value;
      }
    }
    /// <summary>Gets whether the "FIELD_NAME5" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFIELDNAME5 {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "FIELD_NAME5" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFIELDNAME5() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "field_name6" field.</summary>
    public const int FieldName6FieldNumber = 6;
    private readonly static int FieldName6DefaultValue = 0;

    private int fieldName6_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int FieldName6 {
      get { if ((_hasBits0 & 32) != 0) { return fieldName6_; } else { return FieldName6DefaultValue; } }
      set {
        _hasBits0 |= 32;
        fieldName6_ = value;
      }
    }
    /// <summary>Gets whether the "field_name6" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldName6 {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "field_name6" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldName6() {
      _hasBits0 &= ~32;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestJsonName);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestJsonName other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FieldName1 != other.FieldName1) return false;
      if (FieldName2 != other.FieldName2) return false;
      if (FieldName3 != other.FieldName3) return false;
      if (FieldName4 != other.FieldName4) return false;
      if (FIELDNAME5 != other.FIELDNAME5) return false;
      if (FieldName6 != other.FieldName6) return false;
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasFieldName1) hash ^= FieldName1.GetHashCode();
      if (HasFieldName2) hash ^= FieldName2.GetHashCode();
      if (HasFieldName3) hash ^= FieldName3.GetHashCode();
      if (HasFieldName4) hash ^= FieldName4.GetHashCode();
      if (HasFIELDNAME5) hash ^= FIELDNAME5.GetHashCode();
      if (HasFieldName6) hash ^= FieldName6.GetHashCode();
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasFieldName1) {
        output.WriteRawTag(8);
        output.WriteInt32(FieldName1);
      }
      if (HasFieldName2) {
        output.WriteRawTag(16);
        output.WriteInt32(FieldName2);
      }
      if (HasFieldName3) {
        output.WriteRawTag(24);
        output.WriteInt32(FieldName3);
      }
      if (HasFieldName4) {
        output.WriteRawTag(32);
        output.WriteInt32(FieldName4);
      }
      if (HasFIELDNAME5) {
        output.WriteRawTag(40);
        output.WriteInt32(FIELDNAME5);
      }
      if (HasFieldName6) {
        output.WriteRawTag(48);
        output.WriteInt32(FieldName6);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasFieldName1) {
        output.WriteRawTag(8);
        output.WriteInt32(FieldName1);
      }
      if (HasFieldName2) {
        output.WriteRawTag(16);
        output.WriteInt32(FieldName2);
      }
      if (HasFieldName3) {
        output.WriteRawTag(24);
        output.WriteInt32(FieldName3);
      }
      if (HasFieldName4) {
        output.WriteRawTag(32);
        output.WriteInt32(FieldName4);
      }
      if (HasFIELDNAME5) {
        output.WriteRawTag(40);
        output.WriteInt32(FIELDNAME5);
      }
      if (HasFieldName6) {
        output.WriteRawTag(48);
        output.WriteInt32(FieldName6);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasFieldName1) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FieldName1);
      }
      if (HasFieldName2) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FieldName2);
      }
      if (HasFieldName3) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FieldName3);
      }
      if (HasFieldName4) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FieldName4);
      }
      if (HasFIELDNAME5) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FIELDNAME5);
      }
      if (HasFieldName6) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(FieldName6);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestJsonName other) {
      if (other == null) {
        return;
      }
      if (other.HasFieldName1) {
        FieldName1 = other.FieldName1;
      }
      if (other.HasFieldName2) {
        FieldName2 = other.FieldName2;
      }
      if (other.HasFieldName3) {
        FieldName3 = other.FieldName3;
      }
      if (other.HasFieldName4) {
        FieldName4 = other.FieldName4;
      }
      if (other.HasFIELDNAME5) {
        FIELDNAME5 = other.FIELDNAME5;
      }
      if (other.HasFieldName6) {
        FieldName6 = other.FieldName6;
      }
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FieldName1 = input.ReadInt32();
            break;
          }
          case 16: {
            FieldName2 = input.ReadInt32();
            break;
          }
          case 24: {
            FieldName3 = input.ReadInt32();
            break;
          }
          case 32: {
            FieldName4 = input.ReadInt32();
            break;
          }
          case 40: {
            FIELDNAME5 = input.ReadInt32();
            break;
          }
          case 48: {
            FieldName6 = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FieldName1 = input.ReadInt32();
            break;
          }
          case 16: {
            FieldName2 = input.ReadInt32();
            break;
          }
          case 24: {
            FieldName3 = input.ReadInt32();
            break;
          }
          case 32: {
            FieldName4 = input.ReadInt32();
            break;
          }
          case 40: {
            FIELDNAME5 = input.ReadInt32();
            break;
          }
          case 48: {
            FieldName6 = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

  }

  public sealed partial class TestHugeFieldNumbers : pb::IExtendableMessage<TestHugeFieldNumbers>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestHugeFieldNumbers> _parser = new pb::MessageParser<TestHugeFieldNumbers>(() => new TestHugeFieldNumbers());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestHugeFieldNumbers> _extensions;
    private pb::ExtensionSet<TestHugeFieldNumbers> _Extensions { get { return _extensions; } }
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestHugeFieldNumbers> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[63]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestHugeFieldNumbers() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestHugeFieldNumbers(TestHugeFieldNumbers other) : this() {
      _hasBits0 = other._hasBits0;
      optionalInt32_ = other.optionalInt32_;
      fixed32_ = other.fixed32_;
      repeatedInt32_ = other.repeatedInt32_.Clone();
      packedInt32_ = other.packedInt32_.Clone();
      optionalEnum_ = other.optionalEnum_;
      optionalString_ = other.optionalString_;
      optionalBytes_ = other.optionalBytes_;
      optionalMessage_ = other.optionalMessage_ != null ? other.optionalMessage_.Clone() : null;
      optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null;
      stringStringMap_ = other.stringStringMap_.Clone();
      switch (other.OneofFieldCase) {
        case OneofFieldOneofCase.OneofUint32:
          OneofUint32 = other.OneofUint32;
          break;
        case OneofFieldOneofCase.OneofTestAllTypes:
          OneofTestAllTypes = other.OneofTestAllTypes.Clone();
          break;
        case OneofFieldOneofCase.OneofString:
          OneofString = other.OneofString;
          break;
        case OneofFieldOneofCase.OneofBytes:
          OneofBytes = other.OneofBytes;
          break;
      }

      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestHugeFieldNumbers Clone() {
      return new TestHugeFieldNumbers(this);
    }

    /// <summary>Field number for the "optional_int32" field.</summary>
    public const int OptionalInt32FieldNumber = 536870000;
    private readonly static int OptionalInt32DefaultValue = 0;

    private int optionalInt32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int OptionalInt32 {
      get { if ((_hasBits0 & 1) != 0) { return optionalInt32_; } else { return OptionalInt32DefaultValue; } }
      set {
        _hasBits0 |= 1;
        optionalInt32_ = value;
      }
    }
    /// <summary>Gets whether the "optional_int32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalInt32 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "optional_int32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalInt32() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "fixed_32" field.</summary>
    public const int Fixed32FieldNumber = 536870001;
    private readonly static int Fixed32DefaultValue = 0;

    private int fixed32_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Fixed32 {
      get { if ((_hasBits0 & 2) != 0) { return fixed32_; } else { return Fixed32DefaultValue; } }
      set {
        _hasBits0 |= 2;
        fixed32_ = value;
      }
    }
    /// <summary>Gets whether the "fixed_32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFixed32 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "fixed_32" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFixed32() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "repeated_int32" field.</summary>
    public const int RepeatedInt32FieldNumber = 536870002;
    private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
        = pb::FieldCodec.ForInt32(4294960016);
    private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> RepeatedInt32 {
      get { return repeatedInt32_; }
    }

    /// <summary>Field number for the "packed_int32" field.</summary>
    public const int PackedInt32FieldNumber = 536870003;
    private static readonly pb::FieldCodec<int> _repeated_packedInt32_codec
        = pb::FieldCodec.ForInt32(4294960026);
    private readonly pbc::RepeatedField<int> packedInt32_ = new pbc::RepeatedField<int>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::RepeatedField<int> PackedInt32 {
      get { return packedInt32_; }
    }

    /// <summary>Field number for the "optional_enum" field.</summary>
    public const int OptionalEnumFieldNumber = 536870004;
    private readonly static global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalEnumDefaultValue = global::Google.Protobuf.TestProtos.Proto2.ForeignEnum.ForeignFoo;

    private global::Google.Protobuf.TestProtos.Proto2.ForeignEnum optionalEnum_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignEnum OptionalEnum {
      get { if ((_hasBits0 & 4) != 0) { return optionalEnum_; } else { return OptionalEnumDefaultValue; } }
      set {
        _hasBits0 |= 4;
        optionalEnum_ = value;
      }
    }
    /// <summary>Gets whether the "optional_enum" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalEnum {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "optional_enum" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalEnum() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "optional_string" field.</summary>
    public const int OptionalStringFieldNumber = 536870005;
    private readonly static string OptionalStringDefaultValue = "";

    private string optionalString_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OptionalString {
      get { return optionalString_ ?? OptionalStringDefaultValue; }
      set {
        optionalString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalString {
      get { return optionalString_ != null; }
    }
    /// <summary>Clears the value of the "optional_string" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalString() {
      optionalString_ = null;
    }

    /// <summary>Field number for the "optional_bytes" field.</summary>
    public const int OptionalBytesFieldNumber = 536870006;
    private readonly static pb::ByteString OptionalBytesDefaultValue = pb::ByteString.Empty;

    private pb::ByteString optionalBytes_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString OptionalBytes {
      get { return optionalBytes_ ?? OptionalBytesDefaultValue; }
      set {
        optionalBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
      }
    }
    /// <summary>Gets whether the "optional_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalBytes {
      get { return optionalBytes_ != null; }
    }
    /// <summary>Clears the value of the "optional_bytes" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalBytes() {
      optionalBytes_ = null;
    }

    /// <summary>Field number for the "optional_message" field.</summary>
    public const int OptionalMessageFieldNumber = 536870007;
    private global::Google.Protobuf.TestProtos.Proto2.ForeignMessage optionalMessage_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.ForeignMessage OptionalMessage {
      get { return optionalMessage_; }
      set {
        optionalMessage_ = value;
      }
    }

    /// <summary>Field number for the "optionalgroup" field.</summary>
    public const int OptionalGroupFieldNumber = 536870008;
    private global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup optionalGroup_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup OptionalGroup {
      get { return optionalGroup_; }
      set {
        optionalGroup_ = value;
      }
    }
    /// <summary>Gets whether the optionalgroup field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOptionalGroup {
      get { return optionalGroup_ != null; }
    }
    /// <summary>Clears the value of the optionalgroup field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOptionalGroup() {
      optionalGroup_ = null;
    }

    /// <summary>Field number for the "string_string_map" field.</summary>
    public const int StringStringMapFieldNumber = 536870010;
    private static readonly pbc::MapField<string, string>.Codec _map_stringStringMap_codec
        = new pbc::MapField<string, string>.Codec(pb::FieldCodec.ForString(10, ""), pb::FieldCodec.ForString(18, ""), 4294960082);
    private readonly pbc::MapField<string, string> stringStringMap_ = new pbc::MapField<string, string>();
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pbc::MapField<string, string> StringStringMap {
      get { return stringStringMap_; }
    }

    /// <summary>Field number for the "oneof_uint32" field.</summary>
    public const int OneofUint32FieldNumber = 536870011;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public uint OneofUint32 {
      get { return HasOneofUint32 ? (uint) oneofField_ : 0; }
      set {
        oneofField_ = value;
        oneofFieldCase_ = OneofFieldOneofCase.OneofUint32;
      }
    }
    /// <summary>Gets whether the "oneof_uint32" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofUint32 {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_uint32" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofUint32() {
      if (HasOneofUint32) {
        ClearOneofField();
      }
    }

    /// <summary>Field number for the "oneof_test_all_types" field.</summary>
    public const int OneofTestAllTypesFieldNumber = 536870012;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Google.Protobuf.TestProtos.Proto2.TestAllTypes OneofTestAllTypes {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes ? (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes) oneofField_ : null; }
      set {
        oneofField_ = value;
        oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofTestAllTypes;
      }
    }

    /// <summary>Field number for the "oneof_string" field.</summary>
    public const int OneofStringFieldNumber = 536870013;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public string OneofString {
      get { return HasOneofString ? (string) oneofField_ : ""; }
      set {
        oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        oneofFieldCase_ = OneofFieldOneofCase.OneofString;
      }
    }
    /// <summary>Gets whether the "oneof_string" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofString {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_string" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofString() {
      if (HasOneofString) {
        ClearOneofField();
      }
    }

    /// <summary>Field number for the "oneof_bytes" field.</summary>
    public const int OneofBytesFieldNumber = 536870014;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public pb::ByteString OneofBytes {
      get { return HasOneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; }
      set {
        oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
        oneofFieldCase_ = OneofFieldOneofCase.OneofBytes;
      }
    }
    /// <summary>Gets whether the "oneof_bytes" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofBytes {
      get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes; }
    }
    /// <summary> Clears the value of the oneof if it's currently set to "oneof_bytes" </summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofBytes() {
      if (HasOneofBytes) {
        ClearOneofField();
      }
    }

    private object oneofField_;
    /// <summary>Enum of possible cases for the "oneof_field" oneof.</summary>
    public enum OneofFieldOneofCase {
      None = 0,
      OneofUint32 = 536870011,
      OneofTestAllTypes = 536870012,
      OneofString = 536870013,
      OneofBytes = 536870014,
    }
    private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public OneofFieldOneofCase OneofFieldCase {
      get { return oneofFieldCase_; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofField() {
      oneofFieldCase_ = OneofFieldOneofCase.None;
      oneofField_ = null;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestHugeFieldNumbers);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestHugeFieldNumbers other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (OptionalInt32 != other.OptionalInt32) return false;
      if (Fixed32 != other.Fixed32) return false;
      if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
      if(!packedInt32_.Equals(other.packedInt32_)) return false;
      if (OptionalEnum != other.OptionalEnum) return false;
      if (OptionalString != other.OptionalString) return false;
      if (OptionalBytes != other.OptionalBytes) return false;
      if (!object.Equals(OptionalMessage, other.OptionalMessage)) return false;
      if (!object.Equals(OptionalGroup, other.OptionalGroup)) return false;
      if (!StringStringMap.Equals(other.StringStringMap)) return false;
      if (OneofUint32 != other.OneofUint32) return false;
      if (!object.Equals(OneofTestAllTypes, other.OneofTestAllTypes)) return false;
      if (OneofString != other.OneofString) return false;
      if (OneofBytes != other.OneofBytes) return false;
      if (OneofFieldCase != other.OneofFieldCase) return false;
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode();
      if (HasFixed32) hash ^= Fixed32.GetHashCode();
      hash ^= repeatedInt32_.GetHashCode();
      hash ^= packedInt32_.GetHashCode();
      if (HasOptionalEnum) hash ^= OptionalEnum.GetHashCode();
      if (HasOptionalString) hash ^= OptionalString.GetHashCode();
      if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode();
      if (optionalMessage_ != null) hash ^= OptionalMessage.GetHashCode();
      if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode();
      hash ^= StringStringMap.GetHashCode();
      if (HasOneofUint32) hash ^= OneofUint32.GetHashCode();
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) hash ^= OneofTestAllTypes.GetHashCode();
      if (HasOneofString) hash ^= OneofString.GetHashCode();
      if (HasOneofBytes) hash ^= OneofBytes.GetHashCode();
      hash ^= (int) oneofFieldCase_;
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasOptionalInt32) {
        output.WriteRawTag(128, 199, 255, 255, 15);
        output.WriteInt32(OptionalInt32);
      }
      if (HasFixed32) {
        output.WriteRawTag(136, 199, 255, 255, 15);
        output.WriteInt32(Fixed32);
      }
      repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
      packedInt32_.WriteTo(output, _repeated_packedInt32_codec);
      if (HasOptionalEnum) {
        output.WriteRawTag(160, 199, 255, 255, 15);
        output.WriteEnum((int) OptionalEnum);
      }
      if (HasOptionalString) {
        output.WriteRawTag(170, 199, 255, 255, 15);
        output.WriteString(OptionalString);
      }
      if (HasOptionalBytes) {
        output.WriteRawTag(178, 199, 255, 255, 15);
        output.WriteBytes(OptionalBytes);
      }
      if (optionalMessage_ != null) {
        output.WriteRawTag(186, 199, 255, 255, 15);
        output.WriteMessage(OptionalMessage);
      }
      if (HasOptionalGroup) {
        output.WriteRawTag(195, 199, 255, 255, 15);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(196, 199, 255, 255, 15);
      }
      stringStringMap_.WriteTo(output, _map_stringStringMap_codec);
      if (HasOneofUint32) {
        output.WriteRawTag(216, 199, 255, 255, 15);
        output.WriteUInt32(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
        output.WriteRawTag(226, 199, 255, 255, 15);
        output.WriteMessage(OneofTestAllTypes);
      }
      if (HasOneofString) {
        output.WriteRawTag(234, 199, 255, 255, 15);
        output.WriteString(OneofString);
      }
      if (HasOneofBytes) {
        output.WriteRawTag(242, 199, 255, 255, 15);
        output.WriteBytes(OneofBytes);
      }
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasOptionalInt32) {
        output.WriteRawTag(128, 199, 255, 255, 15);
        output.WriteInt32(OptionalInt32);
      }
      if (HasFixed32) {
        output.WriteRawTag(136, 199, 255, 255, 15);
        output.WriteInt32(Fixed32);
      }
      repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec);
      packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec);
      if (HasOptionalEnum) {
        output.WriteRawTag(160, 199, 255, 255, 15);
        output.WriteEnum((int) OptionalEnum);
      }
      if (HasOptionalString) {
        output.WriteRawTag(170, 199, 255, 255, 15);
        output.WriteString(OptionalString);
      }
      if (HasOptionalBytes) {
        output.WriteRawTag(178, 199, 255, 255, 15);
        output.WriteBytes(OptionalBytes);
      }
      if (optionalMessage_ != null) {
        output.WriteRawTag(186, 199, 255, 255, 15);
        output.WriteMessage(OptionalMessage);
      }
      if (HasOptionalGroup) {
        output.WriteRawTag(195, 199, 255, 255, 15);
        output.WriteGroup(OptionalGroup);
        output.WriteRawTag(196, 199, 255, 255, 15);
      }
      stringStringMap_.WriteTo(ref output, _map_stringStringMap_codec);
      if (HasOneofUint32) {
        output.WriteRawTag(216, 199, 255, 255, 15);
        output.WriteUInt32(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
        output.WriteRawTag(226, 199, 255, 255, 15);
        output.WriteMessage(OneofTestAllTypes);
      }
      if (HasOneofString) {
        output.WriteRawTag(234, 199, 255, 255, 15);
        output.WriteString(OneofString);
      }
      if (HasOneofBytes) {
        output.WriteRawTag(242, 199, 255, 255, 15);
        output.WriteBytes(OneofBytes);
      }
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasOptionalInt32) {
        size += 5 + pb::CodedOutputStream.ComputeInt32Size(OptionalInt32);
      }
      if (HasFixed32) {
        size += 5 + pb::CodedOutputStream.ComputeInt32Size(Fixed32);
      }
      size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
      size += packedInt32_.CalculateSize(_repeated_packedInt32_codec);
      if (HasOptionalEnum) {
        size += 5 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalEnum);
      }
      if (HasOptionalString) {
        size += 5 + pb::CodedOutputStream.ComputeStringSize(OptionalString);
      }
      if (HasOptionalBytes) {
        size += 5 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes);
      }
      if (optionalMessage_ != null) {
        size += 5 + pb::CodedOutputStream.ComputeMessageSize(OptionalMessage);
      }
      if (HasOptionalGroup) {
        size += 10 + pb::CodedOutputStream.ComputeGroupSize(OptionalGroup);
      }
      size += stringStringMap_.CalculateSize(_map_stringStringMap_codec);
      if (HasOneofUint32) {
        size += 5 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32);
      }
      if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
        size += 5 + pb::CodedOutputStream.ComputeMessageSize(OneofTestAllTypes);
      }
      if (HasOneofString) {
        size += 5 + pb::CodedOutputStream.ComputeStringSize(OneofString);
      }
      if (HasOneofBytes) {
        size += 5 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes);
      }
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestHugeFieldNumbers other) {
      if (other == null) {
        return;
      }
      if (other.HasOptionalInt32) {
        OptionalInt32 = other.OptionalInt32;
      }
      if (other.HasFixed32) {
        Fixed32 = other.Fixed32;
      }
      repeatedInt32_.Add(other.repeatedInt32_);
      packedInt32_.Add(other.packedInt32_);
      if (other.HasOptionalEnum) {
        OptionalEnum = other.OptionalEnum;
      }
      if (other.HasOptionalString) {
        OptionalString = other.OptionalString;
      }
      if (other.HasOptionalBytes) {
        OptionalBytes = other.OptionalBytes;
      }
      if (other.optionalMessage_ != null) {
        if (optionalMessage_ == null) {
          OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
        }
        OptionalMessage.MergeFrom(other.OptionalMessage);
      }
      if (other.HasOptionalGroup) {
        if (!HasOptionalGroup) {
          OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup();
        }
        OptionalGroup.MergeFrom(other.OptionalGroup);
      }
      stringStringMap_.MergeFrom(other.stringStringMap_);
      switch (other.OneofFieldCase) {
        case OneofFieldOneofCase.OneofUint32:
          OneofUint32 = other.OneofUint32;
          break;
        case OneofFieldOneofCase.OneofTestAllTypes:
          if (OneofTestAllTypes == null) {
            OneofTestAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
          }
          OneofTestAllTypes.MergeFrom(other.OneofTestAllTypes);
          break;
        case OneofFieldOneofCase.OneofString:
          OneofString = other.OneofString;
          break;
        case OneofFieldOneofCase.OneofBytes:
          OneofBytes = other.OneofBytes;
          break;
      }

      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
          case 4294960000: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
          case 4294960008: {
            Fixed32 = input.ReadInt32();
            break;
          }
          case 4294960018:
          case 4294960016: {
            repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
            break;
          }
          case 4294960026:
          case 4294960024: {
            packedInt32_.AddEntriesFrom(input, _repeated_packedInt32_codec);
            break;
          }
          case 4294960032: {
            OptionalEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 4294960042: {
            OptionalString = input.ReadString();
            break;
          }
          case 4294960050: {
            OptionalBytes = input.ReadBytes();
            break;
          }
          case 4294960058: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 4294960067: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 4294960082: {
            stringStringMap_.AddEntriesFrom(input, _map_stringStringMap_codec);
            break;
          }
          case 4294960088: {
            OneofUint32 = input.ReadUInt32();
            break;
          }
          case 4294960098: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
              subBuilder.MergeFrom(OneofTestAllTypes);
            }
            input.ReadMessage(subBuilder);
            OneofTestAllTypes = subBuilder;
            break;
          }
          case 4294960106: {
            OneofString = input.ReadString();
            break;
          }
          case 4294960114: {
            OneofBytes = input.ReadBytes();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
          case 4294960000: {
            OptionalInt32 = input.ReadInt32();
            break;
          }
          case 4294960008: {
            Fixed32 = input.ReadInt32();
            break;
          }
          case 4294960018:
          case 4294960016: {
            repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec);
            break;
          }
          case 4294960026:
          case 4294960024: {
            packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec);
            break;
          }
          case 4294960032: {
            OptionalEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum();
            break;
          }
          case 4294960042: {
            OptionalString = input.ReadString();
            break;
          }
          case 4294960050: {
            OptionalBytes = input.ReadBytes();
            break;
          }
          case 4294960058: {
            if (optionalMessage_ == null) {
              OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage();
            }
            input.ReadMessage(OptionalMessage);
            break;
          }
          case 4294960067: {
            if (!HasOptionalGroup) {
              OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup();
            }
            input.ReadGroup(OptionalGroup);
            break;
          }
          case 4294960082: {
            stringStringMap_.AddEntriesFrom(ref input, _map_stringStringMap_codec);
            break;
          }
          case 4294960088: {
            OneofUint32 = input.ReadUInt32();
            break;
          }
          case 4294960098: {
            global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes();
            if (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
              subBuilder.MergeFrom(OneofTestAllTypes);
            }
            input.ReadMessage(subBuilder);
            OneofTestAllTypes = subBuilder;
            break;
          }
          case 4294960106: {
            OneofString = input.ReadString();
            break;
          }
          case 4294960114: {
            OneofBytes = input.ReadBytes();
            break;
          }
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestHugeFieldNumbers, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestHugeFieldNumbers, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestHugeFieldNumbers, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestHugeFieldNumbers, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestHugeFieldNumbers, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestHugeFieldNumbers, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestHugeFieldNumbers, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

    #region Nested types
    /// <summary>Container for nested types declared in the TestHugeFieldNumbers message type.</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static partial class Types {
      public sealed partial class OptionalGroup : pb::IMessage<OptionalGroup>
      #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          , pb::IBufferMessage
      #endif
      {
        private static readonly pb::MessageParser<OptionalGroup> _parser = new pb::MessageParser<OptionalGroup>(() => new OptionalGroup());
        private pb::UnknownFieldSet _unknownFields;
        private int _hasBits0;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pb::MessageParser<OptionalGroup> Parser { get { return _parser; } }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Descriptor.NestedTypes[0]; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        pbr::MessageDescriptor pb::IMessage.Descriptor {
          get { return Descriptor; }
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup() {
          OnConstruction();
        }

        partial void OnConstruction();

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup(OptionalGroup other) : this() {
          _hasBits0 = other._hasBits0;
          groupA_ = other.groupA_;
          _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public OptionalGroup Clone() {
          return new OptionalGroup(this);
        }

        /// <summary>Field number for the "group_a" field.</summary>
        public const int GroupAFieldNumber = 536870009;
        private readonly static int GroupADefaultValue = 0;

        private int groupA_;
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int GroupA {
          get { if ((_hasBits0 & 1) != 0) { return groupA_; } else { return GroupADefaultValue; } }
          set {
            _hasBits0 |= 1;
            groupA_ = value;
          }
        }
        /// <summary>Gets whether the "group_a" field is set</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool HasGroupA {
          get { return (_hasBits0 & 1) != 0; }
        }
        /// <summary>Clears the value of the "group_a" field</summary>
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void ClearGroupA() {
          _hasBits0 &= ~1;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override bool Equals(object other) {
          return Equals(other as OptionalGroup);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(OptionalGroup other) {
          if (ReferenceEquals(other, null)) {
            return false;
          }
          if (ReferenceEquals(other, this)) {
            return true;
          }
          if (GroupA != other.GroupA) return false;
          return Equals(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override int GetHashCode() {
          int hash = 1;
          if (HasGroupA) hash ^= GroupA.GetHashCode();
          if (_unknownFields != null) {
            hash ^= _unknownFields.GetHashCode();
          }
          return hash;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public override string ToString() {
          return pb::JsonFormatter.ToDiagnosticString(this);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void WriteTo(pb::CodedOutputStream output) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          output.WriteRawMessage(this);
        #else
          if (HasGroupA) {
            output.WriteRawTag(200, 199, 255, 255, 15);
            output.WriteInt32(GroupA);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(output);
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
          if (HasGroupA) {
            output.WriteRawTag(200, 199, 255, 255, 15);
            output.WriteInt32(GroupA);
          }
          if (_unknownFields != null) {
            _unknownFields.WriteTo(ref output);
          }
        }
        #endif

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public int CalculateSize() {
          int size = 0;
          if (HasGroupA) {
            size += 5 + pb::CodedOutputStream.ComputeInt32Size(GroupA);
          }
          if (_unknownFields != null) {
            size += _unknownFields.CalculateSize();
          }
          return size;
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(OptionalGroup other) {
          if (other == null) {
            return;
          }
          if (other.HasGroupA) {
            GroupA = other.GroupA;
          }
          _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public void MergeFrom(pb::CodedInputStream input) {
        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
          input.ReadRawMessage(this);
        #else
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 4294960068:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                break;
              case 4294960072: {
                GroupA = input.ReadInt32();
                break;
              }
            }
          }
        #endif
        }

        #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
          uint tag;
          while ((tag = input.ReadTag()) != 0) {
            switch(tag) {
              case 4294960068:
                return;
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
              case 4294960072: {
                GroupA = input.ReadInt32();
                break;
              }
            }
          }
        }
        #endif

      }

    }
    #endregion

  }

  public sealed partial class TestExtensionInsideTable : pb::IExtendableMessage<TestExtensionInsideTable>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    private static readonly pb::MessageParser<TestExtensionInsideTable> _parser = new pb::MessageParser<TestExtensionInsideTable>(() => new TestExtensionInsideTable());
    private pb::UnknownFieldSet _unknownFields;
    private pb::ExtensionSet<TestExtensionInsideTable> _extensions;
    private pb::ExtensionSet<TestExtensionInsideTable> _Extensions { get { return _extensions; } }
    private int _hasBits0;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pb::MessageParser<TestExtensionInsideTable> Parser { get { return _parser; } }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Google.Protobuf.TestProtos.Proto2.UnittestReflection.Descriptor.MessageTypes[64]; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    pbr::MessageDescriptor pb::IMessage.Descriptor {
      get { return Descriptor; }
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionInsideTable() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionInsideTable(TestExtensionInsideTable other) : this() {
      _hasBits0 = other._hasBits0;
      field1_ = other.field1_;
      field2_ = other.field2_;
      field3_ = other.field3_;
      field4_ = other.field4_;
      field6_ = other.field6_;
      field7_ = other.field7_;
      field8_ = other.field8_;
      field9_ = other.field9_;
      field10_ = other.field10_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
      _extensions = pb::ExtensionSet.Clone(other._extensions);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestExtensionInsideTable Clone() {
      return new TestExtensionInsideTable(this);
    }

    /// <summary>Field number for the "field1" field.</summary>
    public const int Field1FieldNumber = 1;
    private readonly static int Field1DefaultValue = 0;

    private int field1_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field1 {
      get { if ((_hasBits0 & 1) != 0) { return field1_; } else { return Field1DefaultValue; } }
      set {
        _hasBits0 |= 1;
        field1_ = value;
      }
    }
    /// <summary>Gets whether the "field1" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField1 {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "field1" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField1() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "field2" field.</summary>
    public const int Field2FieldNumber = 2;
    private readonly static int Field2DefaultValue = 0;

    private int field2_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field2 {
      get { if ((_hasBits0 & 2) != 0) { return field2_; } else { return Field2DefaultValue; } }
      set {
        _hasBits0 |= 2;
        field2_ = value;
      }
    }
    /// <summary>Gets whether the "field2" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField2 {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "field2" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField2() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "field3" field.</summary>
    public const int Field3FieldNumber = 3;
    private readonly static int Field3DefaultValue = 0;

    private int field3_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field3 {
      get { if ((_hasBits0 & 4) != 0) { return field3_; } else { return Field3DefaultValue; } }
      set {
        _hasBits0 |= 4;
        field3_ = value;
      }
    }
    /// <summary>Gets whether the "field3" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField3 {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "field3" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField3() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "field4" field.</summary>
    public const int Field4FieldNumber = 4;
    private readonly static int Field4DefaultValue = 0;

    private int field4_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field4 {
      get { if ((_hasBits0 & 8) != 0) { return field4_; } else { return Field4DefaultValue; } }
      set {
        _hasBits0 |= 8;
        field4_ = value;
      }
    }
    /// <summary>Gets whether the "field4" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField4 {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "field4" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField4() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "field6" field.</summary>
    public const int Field6FieldNumber = 6;
    private readonly static int Field6DefaultValue = 0;

    private int field6_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field6 {
      get { if ((_hasBits0 & 16) != 0) { return field6_; } else { return Field6DefaultValue; } }
      set {
        _hasBits0 |= 16;
        field6_ = value;
      }
    }
    /// <summary>Gets whether the "field6" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField6 {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "field6" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField6() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "field7" field.</summary>
    public const int Field7FieldNumber = 7;
    private readonly static int Field7DefaultValue = 0;

    private int field7_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field7 {
      get { if ((_hasBits0 & 32) != 0) { return field7_; } else { return Field7DefaultValue; } }
      set {
        _hasBits0 |= 32;
        field7_ = value;
      }
    }
    /// <summary>Gets whether the "field7" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField7 {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "field7" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField7() {
      _hasBits0 &= ~32;
    }

    /// <summary>Field number for the "field8" field.</summary>
    public const int Field8FieldNumber = 8;
    private readonly static int Field8DefaultValue = 0;

    private int field8_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field8 {
      get { if ((_hasBits0 & 64) != 0) { return field8_; } else { return Field8DefaultValue; } }
      set {
        _hasBits0 |= 64;
        field8_ = value;
      }
    }
    /// <summary>Gets whether the "field8" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField8 {
      get { return (_hasBits0 & 64) != 0; }
    }
    /// <summary>Clears the value of the "field8" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField8() {
      _hasBits0 &= ~64;
    }

    /// <summary>Field number for the "field9" field.</summary>
    public const int Field9FieldNumber = 9;
    private readonly static int Field9DefaultValue = 0;

    private int field9_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field9 {
      get { if ((_hasBits0 & 128) != 0) { return field9_; } else { return Field9DefaultValue; } }
      set {
        _hasBits0 |= 128;
        field9_ = value;
      }
    }
    /// <summary>Gets whether the "field9" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField9 {
      get { return (_hasBits0 & 128) != 0; }
    }
    /// <summary>Clears the value of the "field9" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField9() {
      _hasBits0 &= ~128;
    }

    /// <summary>Field number for the "field10" field.</summary>
    public const int Field10FieldNumber = 10;
    private readonly static int Field10DefaultValue = 0;

    private int field10_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int Field10 {
      get { if ((_hasBits0 & 256) != 0) { return field10_; } else { return Field10DefaultValue; } }
      set {
        _hasBits0 |= 256;
        field10_ = value;
      }
    }
    /// <summary>Gets whether the "field10" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasField10 {
      get { return (_hasBits0 & 256) != 0; }
    }
    /// <summary>Clears the value of the "field10" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearField10() {
      _hasBits0 &= ~256;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override bool Equals(object other) {
      return Equals(other as TestExtensionInsideTable);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestExtensionInsideTable other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (Field1 != other.Field1) return false;
      if (Field2 != other.Field2) return false;
      if (Field3 != other.Field3) return false;
      if (Field4 != other.Field4) return false;
      if (Field6 != other.Field6) return false;
      if (Field7 != other.Field7) return false;
      if (Field8 != other.Field8) return false;
      if (Field9 != other.Field9) return false;
      if (Field10 != other.Field10) return false;
      if (!Equals(_extensions, other._extensions)) {
        return false;
      }
      return Equals(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override int GetHashCode() {
      int hash = 1;
      if (HasField1) hash ^= Field1.GetHashCode();
      if (HasField2) hash ^= Field2.GetHashCode();
      if (HasField3) hash ^= Field3.GetHashCode();
      if (HasField4) hash ^= Field4.GetHashCode();
      if (HasField6) hash ^= Field6.GetHashCode();
      if (HasField7) hash ^= Field7.GetHashCode();
      if (HasField8) hash ^= Field8.GetHashCode();
      if (HasField9) hash ^= Field9.GetHashCode();
      if (HasField10) hash ^= Field10.GetHashCode();
      if (_extensions != null) {
        hash ^= _extensions.GetHashCode();
      }
      if (_unknownFields != null) {
        hash ^= _unknownFields.GetHashCode();
      }
      return hash;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public override string ToString() {
      return pb::JsonFormatter.ToDiagnosticString(this);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void WriteTo(pb::CodedOutputStream output) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      output.WriteRawMessage(this);
    #else
      if (HasField1) {
        output.WriteRawTag(8);
        output.WriteInt32(Field1);
      }
      if (HasField2) {
        output.WriteRawTag(16);
        output.WriteInt32(Field2);
      }
      if (HasField3) {
        output.WriteRawTag(24);
        output.WriteInt32(Field3);
      }
      if (HasField4) {
        output.WriteRawTag(32);
        output.WriteInt32(Field4);
      }
      if (HasField6) {
        output.WriteRawTag(48);
        output.WriteInt32(Field6);
      }
      if (HasField7) {
        output.WriteRawTag(56);
        output.WriteInt32(Field7);
      }
      if (HasField8) {
        output.WriteRawTag(64);
        output.WriteInt32(Field8);
      }
      if (HasField9) {
        output.WriteRawTag(72);
        output.WriteInt32(Field9);
      }
      if (HasField10) {
        output.WriteRawTag(80);
        output.WriteInt32(Field10);
      }
      if (_extensions != null) {
        _extensions.WriteTo(output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(output);
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
      if (HasField1) {
        output.WriteRawTag(8);
        output.WriteInt32(Field1);
      }
      if (HasField2) {
        output.WriteRawTag(16);
        output.WriteInt32(Field2);
      }
      if (HasField3) {
        output.WriteRawTag(24);
        output.WriteInt32(Field3);
      }
      if (HasField4) {
        output.WriteRawTag(32);
        output.WriteInt32(Field4);
      }
      if (HasField6) {
        output.WriteRawTag(48);
        output.WriteInt32(Field6);
      }
      if (HasField7) {
        output.WriteRawTag(56);
        output.WriteInt32(Field7);
      }
      if (HasField8) {
        output.WriteRawTag(64);
        output.WriteInt32(Field8);
      }
      if (HasField9) {
        output.WriteRawTag(72);
        output.WriteInt32(Field9);
      }
      if (HasField10) {
        output.WriteRawTag(80);
        output.WriteInt32(Field10);
      }
      if (_extensions != null) {
        _extensions.WriteTo(ref output);
      }
      if (_unknownFields != null) {
        _unknownFields.WriteTo(ref output);
      }
    }
    #endif

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public int CalculateSize() {
      int size = 0;
      if (HasField1) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field1);
      }
      if (HasField2) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field2);
      }
      if (HasField3) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field3);
      }
      if (HasField4) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field4);
      }
      if (HasField6) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field6);
      }
      if (HasField7) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field7);
      }
      if (HasField8) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field8);
      }
      if (HasField9) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field9);
      }
      if (HasField10) {
        size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field10);
      }
      if (_extensions != null) {
        size += _extensions.CalculateSize();
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestExtensionInsideTable other) {
      if (other == null) {
        return;
      }
      if (other.HasField1) {
        Field1 = other.Field1;
      }
      if (other.HasField2) {
        Field2 = other.Field2;
      }
      if (other.HasField3) {
        Field3 = other.Field3;
      }
      if (other.HasField4) {
        Field4 = other.Field4;
      }
      if (other.HasField6) {
        Field6 = other.Field6;
      }
      if (other.HasField7) {
        Field7 = other.Field7;
      }
      if (other.HasField8) {
        Field8 = other.Field8;
      }
      if (other.HasField9) {
        Field9 = other.Field9;
      }
      if (other.HasField10) {
        Field10 = other.Field10;
      }
      pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);
      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(pb::CodedInputStream input) {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      input.ReadRawMessage(this);
    #else
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            }
            break;
          case 8: {
            Field1 = input.ReadInt32();
            break;
          }
          case 16: {
            Field2 = input.ReadInt32();
            break;
          }
          case 24: {
            Field3 = input.ReadInt32();
            break;
          }
          case 32: {
            Field4 = input.ReadInt32();
            break;
          }
          case 48: {
            Field6 = input.ReadInt32();
            break;
          }
          case 56: {
            Field7 = input.ReadInt32();
            break;
          }
          case 64: {
            Field8 = input.ReadInt32();
            break;
          }
          case 72: {
            Field9 = input.ReadInt32();
            break;
          }
          case 80: {
            Field10 = input.ReadInt32();
            break;
          }
        }
      }
    #endif
    }

    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
      uint tag;
      while ((tag = input.ReadTag()) != 0) {
        switch(tag) {
          default:
            if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {
              _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            }
            break;
          case 8: {
            Field1 = input.ReadInt32();
            break;
          }
          case 16: {
            Field2 = input.ReadInt32();
            break;
          }
          case 24: {
            Field3 = input.ReadInt32();
            break;
          }
          case 32: {
            Field4 = input.ReadInt32();
            break;
          }
          case 48: {
            Field6 = input.ReadInt32();
            break;
          }
          case 56: {
            Field7 = input.ReadInt32();
            break;
          }
          case 64: {
            Field8 = input.ReadInt32();
            break;
          }
          case 72: {
            Field9 = input.ReadInt32();
            break;
          }
          case 80: {
            Field10 = input.ReadInt32();
            break;
          }
        }
      }
    }
    #endif

    public TValue GetExtension<TValue>(pb::Extension<TestExtensionInsideTable, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetExtension<TValue>(pb::RepeatedExtension<TestExtensionInsideTable, TValue> extension) {
      return pb::ExtensionSet.Get(ref _extensions, extension);
    }
    public pbc::RepeatedField<TValue> GetOrInitializeExtension<TValue>(pb::RepeatedExtension<TestExtensionInsideTable, TValue> extension) {
      return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension);
    }
    public void SetExtension<TValue>(pb::Extension<TestExtensionInsideTable, TValue> extension, TValue value) {
      pb::ExtensionSet.Set(ref _extensions, extension, value);
    }
    public bool HasExtension<TValue>(pb::Extension<TestExtensionInsideTable, TValue> extension) {
      return pb::ExtensionSet.Has(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::Extension<TestExtensionInsideTable, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }
    public void ClearExtension<TValue>(pb::RepeatedExtension<TestExtensionInsideTable, TValue> extension) {
      pb::ExtensionSet.Clear(ref _extensions, extension);
    }

  }

  #endregion

}

#endregion Designer generated code
