// <auto-generated>
//     Generated by the protocol buffer compiler.  DO NOT EDIT!
//     source: google/protobuf/unittest_features.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 Pb {

  /// <summary>Holder for reflection information generated from google/protobuf/unittest_features.proto</summary>
  public static partial class UnittestFeaturesReflection {

    #region Descriptor
    /// <summary>File descriptor for google/protobuf/unittest_features.proto</summary>
    public static pbr::FileDescriptor Descriptor {
      get { return descriptor; }
    }
    private static pbr::FileDescriptor descriptor;

    static UnittestFeaturesReflection() {
      byte[] descriptorData = global::System.Convert.FromBase64String(
          string.Concat(
            "Cidnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfZmVhdHVyZXMucHJvdG8SAnBi",
            "GiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90byKiAQoLVGVzdE1l",
            "c3NhZ2UaTQoGTmVzdGVkMkMKC3Rlc3RfbmVzdGVkEhsuZ29vZ2xlLnByb3Rv",
            "YnVmLkZlYXR1cmVTZXQYjU4gASgLMhAucGIuVGVzdEZlYXR1cmVzMkQKDHRl",
            "c3RfbWVzc2FnZRIbLmdvb2dsZS5wcm90b2J1Zi5GZWF0dXJlU2V0GI5OIAEo",
            "CzIQLnBiLlRlc3RGZWF0dXJlcyKsDAoMVGVzdEZlYXR1cmVzEnsKDGZpbGVf",
            "ZmVhdHVyZRgBIAEoDjIPLnBiLkVudW1GZWF0dXJlQlSIAQGYAQGiAQsSBlZB",
            "TFVFMRiEB6IBCxIGVkFMVUUyGOcHogELEgZWQUxVRTMY6AeiAQwSBlZBTFVF",
            "NBidjQaiAQwSBlZBTFVFNRiejQayAQMI6AcSTAoXZXh0ZW5zaW9uX3Jhbmdl",
            "X2ZlYXR1cmUYAiABKA4yDy5wYi5FbnVtRmVhdHVyZUIaiAEBmAECogELEgZW",
            "QUxVRTEYhAeyAQMI6AcSRAoPbWVzc2FnZV9mZWF0dXJlGAMgASgOMg8ucGIu",
            "RW51bUZlYXR1cmVCGogBAZgBA6IBCxIGVkFMVUUxGIQHsgEDCOgHEkIKDWZp",
            "ZWxkX2ZlYXR1cmUYBCABKA4yDy5wYi5FbnVtRmVhdHVyZUIaiAEBmAEEogEL",
            "EgZWQUxVRTEYhAeyAQMI6AcSQgoNb25lb2ZfZmVhdHVyZRgFIAEoDjIPLnBi",
            "LkVudW1GZWF0dXJlQhqIAQGYAQWiAQsSBlZBTFVFMRiEB7IBAwjoBxJBCgxl",
            "bnVtX2ZlYXR1cmUYBiABKA4yDy5wYi5FbnVtRmVhdHVyZUIaiAEBmAEGogEL",
            "EgZWQUxVRTEYhAeyAQMI6AcSRwoSZW51bV9lbnRyeV9mZWF0dXJlGAcgASgO",
            "Mg8ucGIuRW51bUZlYXR1cmVCGogBAZgBB6IBCxIGVkFMVUUxGIQHsgEDCOgH",
            "EkQKD3NlcnZpY2VfZmVhdHVyZRgIIAEoDjIPLnBiLkVudW1GZWF0dXJlQhqI",
            "AQGYAQiiAQsSBlZBTFVFMRiEB7IBAwjoBxJDCg5tZXRob2RfZmVhdHVyZRgJ",
            "IAEoDjIPLnBiLkVudW1GZWF0dXJlQhqIAQGYAQmiAQsSBlZBTFVFMRiEB7IB",
            "AwjoBxJdChBtdWx0aXBsZV9mZWF0dXJlGAogASgOMg8ucGIuRW51bUZlYXR1",
            "cmVCMogBAZgBAZgBBJgBA5gBBpgBB5gBCJgBCZgBBZgBAqIBCxIGVkFMVUUx",
            "GIQHsgEDCOgHEkIKEmJvb2xfZmllbGRfZmVhdHVyZRgLIAEoCEImiAEBmAEE",
            "ogEKEgVmYWxzZRiEB6IBChIEdHJ1ZRidjQayAQMI6AcSWwoOc291cmNlX2Zl",
            "YXR1cmUYDyABKA4yDy5wYi5FbnVtRmVhdHVyZUIyiAECmAEBmAEEmAEDmAEG",
            "mAEHmAEImAEJmAEFmAECogELEgZWQUxVRTEYhAeyAQMI6AcSXAoPc291cmNl",
            "X2ZlYXR1cmUyGBAgASgOMg8ucGIuRW51bUZlYXR1cmVCMogBApgBAZgBBJgB",
            "A5gBBpgBB5gBCJgBCZgBBZgBAqIBCxIGVkFMVUUxGIQHsgEDCOgHEo0BCg9y",
            "ZW1vdmVkX2ZlYXR1cmUYESABKA4yDy5wYi5FbnVtRmVhdHVyZUJjiAEBmAEB",
            "mAEEogELEgZWQUxVRTEYhAeiAQsSBlZBTFVFMhjoB6IBCxIGVkFMVUUzGOkH",
            "sgEtCOgHEOgHGiJDdXN0b20gZmVhdHVyZSBkZXByZWNhdGlvbiB3YXJuaW5n",
            "IOkHElQKDmZ1dHVyZV9mZWF0dXJlGBIgASgOMg8ucGIuRW51bUZlYXR1cmVC",
            "K4gBAZgBAZgBBKIBCxIGVkFMVUUxGIQHogELEgZWQUxVRTIY6QeyAQMI6QcS",
            "VwoObGVnYWN5X2ZlYXR1cmUYEyABKA4yDy5wYi5FbnVtRmVhdHVyZUIuiAEB",
            "mAEBmAEEogELEgZWQUxVRTEYhAeiAQsSBlZBTFVFMhjoB7IBBgjnByDoBxLO",
            "AQoWdmFsdWVfbGlmZXRpbWVfZmVhdHVyZRgUIAEoDjIYLnBiLlZhbHVlTGlm",
            "ZXRpbWVGZWF0dXJlQpMBiAEBmAEBogEdEhhWQUxVRV9MSUZFVElNRV9JTkhF",
            "UklURUQYhAeiARoSFVZBTFVFX0xJRkVUSU1FX0ZVVFVSRRjoB6IBGxIVVkFM",
            "VUVfTElGRVRJTUVfRlVUVVJFGJ+NBrIBLwjoBxCejQYaIkN1c3RvbSBmZWF0",
            "dXJlIGRlcHJlY2F0aW9uIHdhcm5pbmcgn40GKuYBCgtFbnVtRmVhdHVyZRId",
            "ChlURVNUX0VOVU1fRkVBVFVSRV9VTktOT1dOEAASCgoGVkFMVUUxEAESCgoG",
            "VkFMVUUyEAISCgoGVkFMVUUzEAMSCgoGVkFMVUU0EAQSCgoGVkFMVUU1EAUS",
            "CgoGVkFMVUU2EAYSCgoGVkFMVUU3EAcSCgoGVkFMVUU4EAgSCgoGVkFMVUU5",
            "EAkSCwoHVkFMVUUxMBAKEgsKB1ZBTFVFMTEQCxILCgdWQUxVRTEyEAwSCwoH",
            "VkFMVUUxMxANEgsKB1ZBTFVFMTQQDhILCgdWQUxVRTE1EA8q4AIKFFZhbHVl",
            "TGlmZXRpbWVGZWF0dXJlEh8KG1RFU1RfVkFMVUVfTElGRVRJTUVfVU5LTk9X",
            "ThAAEhwKGFZBTFVFX0xJRkVUSU1FX0lOSEVSSVRFRBABEk4KFlZBTFVFX0xJ",
            "RkVUSU1FX1NVUFBPUlQQAhoyIjAInY0GEJ6NBhoiQ3VzdG9tIGZlYXR1cmUg",
            "ZGVwcmVjYXRpb24gd2FybmluZyCfjQYSJAocVkFMVUVfTElGRVRJTUVfRU1Q",
            "VFlfU1VQUE9SVBADGgIiABIhChVWQUxVRV9MSUZFVElNRV9GVVRVUkUQBBoG",
            "IgQInY0GEkkKGVZBTFVFX0xJRkVUSU1FX0RFUFJFQ0FURUQQBRoqIigQnY0G",
            "GiJDdXN0b20gZmVhdHVyZSBkZXByZWNhdGlvbiB3YXJuaW5nEiUKFlZBTFVF",
            "X0xJRkVUSU1FX1JFTU9WRUQQBhoJIgcQ6AcgnY0GOjwKBHRlc3QSGy5nb29n",
            "bGUucHJvdG9idWYuRmVhdHVyZVNldBiPTiABKAsyEC5wYi5UZXN0RmVhdHVy",
            "ZXNiCGVkaXRpb25zcOgH"));
      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor, },
          new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Pb.EnumFeature), typeof(global::Pb.ValueLifetimeFeature), }, new pb::Extension[] { UnittestFeaturesExtensions.Test }, new pbr::GeneratedClrTypeInfo[] {
            new pbr::GeneratedClrTypeInfo(typeof(global::Pb.TestMessage), global::Pb.TestMessage.Parser, null, null, null, new pb::Extension[] { global::Pb.TestMessage.Extensions.TestMessage }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Pb.TestMessage.Types.Nested), global::Pb.TestMessage.Types.Nested.Parser, null, null, null, new pb::Extension[] { global::Pb.TestMessage.Types.Nested.Extensions.TestNested }, null)}),
            new pbr::GeneratedClrTypeInfo(typeof(global::Pb.TestFeatures), global::Pb.TestFeatures.Parser, new[]{ "FileFeature", "ExtensionRangeFeature", "MessageFeature", "FieldFeature", "OneofFeature", "EnumFeature", "EnumEntryFeature", "ServiceFeature", "MethodFeature", "MultipleFeature", "BoolFieldFeature", "SourceFeature", "SourceFeature2", "RemovedFeature", "FutureFeature", "LegacyFeature", "ValueLifetimeFeature" }, null, null, null, null)
          }));
    }
    #endregion

  }
  /// <summary>Holder for extension identifiers generated from the top level of google/protobuf/unittest_features.proto</summary>
  public static partial class UnittestFeaturesExtensions {
    public static readonly pb::Extension<global::Google.Protobuf.Reflection.FeatureSet, global::Pb.TestFeatures> Test =
      new pb::Extension<global::Google.Protobuf.Reflection.FeatureSet, global::Pb.TestFeatures>(9999, pb::FieldCodec.ForMessage(79994, global::Pb.TestFeatures.Parser));
  }

  #region Enums
  public enum EnumFeature {
    [pbr::OriginalName("TEST_ENUM_FEATURE_UNKNOWN")] TestEnumFeatureUnknown = 0,
    [pbr::OriginalName("VALUE1")] Value1 = 1,
    [pbr::OriginalName("VALUE2")] Value2 = 2,
    [pbr::OriginalName("VALUE3")] Value3 = 3,
    [pbr::OriginalName("VALUE4")] Value4 = 4,
    [pbr::OriginalName("VALUE5")] Value5 = 5,
    [pbr::OriginalName("VALUE6")] Value6 = 6,
    [pbr::OriginalName("VALUE7")] Value7 = 7,
    [pbr::OriginalName("VALUE8")] Value8 = 8,
    [pbr::OriginalName("VALUE9")] Value9 = 9,
    [pbr::OriginalName("VALUE10")] Value10 = 10,
    [pbr::OriginalName("VALUE11")] Value11 = 11,
    [pbr::OriginalName("VALUE12")] Value12 = 12,
    [pbr::OriginalName("VALUE13")] Value13 = 13,
    [pbr::OriginalName("VALUE14")] Value14 = 14,
    [pbr::OriginalName("VALUE15")] Value15 = 15,
  }

  public enum ValueLifetimeFeature {
    [pbr::OriginalName("TEST_VALUE_LIFETIME_UNKNOWN")] TestValueLifetimeUnknown = 0,
    [pbr::OriginalName("VALUE_LIFETIME_INHERITED")] ValueLifetimeInherited = 1,
    [pbr::OriginalName("VALUE_LIFETIME_SUPPORT")] ValueLifetimeSupport = 2,
    [pbr::OriginalName("VALUE_LIFETIME_EMPTY_SUPPORT")] ValueLifetimeEmptySupport = 3,
    [pbr::OriginalName("VALUE_LIFETIME_FUTURE")] ValueLifetimeFuture = 4,
    [pbr::OriginalName("VALUE_LIFETIME_DEPRECATED")] ValueLifetimeDeprecated = 5,
    [pbr::OriginalName("VALUE_LIFETIME_REMOVED")] ValueLifetimeRemoved = 6,
  }

  #endregion

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

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Pb.UnittestFeaturesReflection.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 TestMessage() {
      OnConstruction();
    }

    partial void OnConstruction();

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

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

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

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestMessage 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(TestMessage 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) {
      if ((tag & 7) == 4) {
        // Abort on any end group tag.
        return;
      }
      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) {
      if ((tag & 7) == 4) {
        // Abort on any end group tag.
        return;
      }
      switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
        }
      }
    }
    #endif

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

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public static pbr::MessageDescriptor Descriptor {
          get { return global::Pb.TestMessage.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 Nested() {
          OnConstruction();
        }

        partial void OnConstruction();

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

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

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

        [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
        [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
        public bool Equals(Nested 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(Nested 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) {
          if ((tag & 7) == 4) {
            // Abort on any end group tag.
            return;
          }
          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) {
          if ((tag & 7) == 4) {
            // Abort on any end group tag.
            return;
          }
          switch(tag) {
              default:
                _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                break;
            }
          }
        }
        #endif

        #region Extensions
        /// <summary>Container for extensions for other messages declared in the Nested 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.Reflection.FeatureSet, global::Pb.TestFeatures> TestNested =
            new pb::Extension<global::Google.Protobuf.Reflection.FeatureSet, global::Pb.TestFeatures>(9997, pb::FieldCodec.ForMessage(79978, global::Pb.TestFeatures.Parser));
        }
        #endregion

      }

    }
    #endregion

    #region Extensions
    /// <summary>Container for extensions for other messages declared in the TestMessage 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.Reflection.FeatureSet, global::Pb.TestFeatures> TestMessage =
        new pb::Extension<global::Google.Protobuf.Reflection.FeatureSet, global::Pb.TestFeatures>(9998, pb::FieldCodec.ForMessage(79986, global::Pb.TestFeatures.Parser));
    }
    #endregion

  }

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

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public static pbr::MessageDescriptor Descriptor {
      get { return global::Pb.UnittestFeaturesReflection.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 TestFeatures() {
      OnConstruction();
    }

    partial void OnConstruction();

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public TestFeatures(TestFeatures other) : this() {
      _hasBits0 = other._hasBits0;
      fileFeature_ = other.fileFeature_;
      extensionRangeFeature_ = other.extensionRangeFeature_;
      messageFeature_ = other.messageFeature_;
      fieldFeature_ = other.fieldFeature_;
      oneofFeature_ = other.oneofFeature_;
      enumFeature_ = other.enumFeature_;
      enumEntryFeature_ = other.enumEntryFeature_;
      serviceFeature_ = other.serviceFeature_;
      methodFeature_ = other.methodFeature_;
      multipleFeature_ = other.multipleFeature_;
      boolFieldFeature_ = other.boolFieldFeature_;
      sourceFeature_ = other.sourceFeature_;
      sourceFeature2_ = other.sourceFeature2_;
      removedFeature_ = other.removedFeature_;
      futureFeature_ = other.futureFeature_;
      legacyFeature_ = other.legacyFeature_;
      valueLifetimeFeature_ = other.valueLifetimeFeature_;
      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
    }

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

    /// <summary>Field number for the "file_feature" field.</summary>
    public const int FileFeatureFieldNumber = 1;
    private readonly static global::Pb.EnumFeature FileFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature fileFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature FileFeature {
      get { if ((_hasBits0 & 1) != 0) { return fileFeature_; } else { return FileFeatureDefaultValue; } }
      set {
        _hasBits0 |= 1;
        fileFeature_ = value;
      }
    }
    /// <summary>Gets whether the "file_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFileFeature {
      get { return (_hasBits0 & 1) != 0; }
    }
    /// <summary>Clears the value of the "file_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFileFeature() {
      _hasBits0 &= ~1;
    }

    /// <summary>Field number for the "extension_range_feature" field.</summary>
    public const int ExtensionRangeFeatureFieldNumber = 2;
    private readonly static global::Pb.EnumFeature ExtensionRangeFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature extensionRangeFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature ExtensionRangeFeature {
      get { if ((_hasBits0 & 2) != 0) { return extensionRangeFeature_; } else { return ExtensionRangeFeatureDefaultValue; } }
      set {
        _hasBits0 |= 2;
        extensionRangeFeature_ = value;
      }
    }
    /// <summary>Gets whether the "extension_range_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasExtensionRangeFeature {
      get { return (_hasBits0 & 2) != 0; }
    }
    /// <summary>Clears the value of the "extension_range_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearExtensionRangeFeature() {
      _hasBits0 &= ~2;
    }

    /// <summary>Field number for the "message_feature" field.</summary>
    public const int MessageFeatureFieldNumber = 3;
    private readonly static global::Pb.EnumFeature MessageFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature messageFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature MessageFeature {
      get { if ((_hasBits0 & 4) != 0) { return messageFeature_; } else { return MessageFeatureDefaultValue; } }
      set {
        _hasBits0 |= 4;
        messageFeature_ = value;
      }
    }
    /// <summary>Gets whether the "message_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMessageFeature {
      get { return (_hasBits0 & 4) != 0; }
    }
    /// <summary>Clears the value of the "message_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMessageFeature() {
      _hasBits0 &= ~4;
    }

    /// <summary>Field number for the "field_feature" field.</summary>
    public const int FieldFeatureFieldNumber = 4;
    private readonly static global::Pb.EnumFeature FieldFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature fieldFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature FieldFeature {
      get { if ((_hasBits0 & 8) != 0) { return fieldFeature_; } else { return FieldFeatureDefaultValue; } }
      set {
        _hasBits0 |= 8;
        fieldFeature_ = value;
      }
    }
    /// <summary>Gets whether the "field_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFieldFeature {
      get { return (_hasBits0 & 8) != 0; }
    }
    /// <summary>Clears the value of the "field_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFieldFeature() {
      _hasBits0 &= ~8;
    }

    /// <summary>Field number for the "oneof_feature" field.</summary>
    public const int OneofFeatureFieldNumber = 5;
    private readonly static global::Pb.EnumFeature OneofFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature oneofFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature OneofFeature {
      get { if ((_hasBits0 & 16) != 0) { return oneofFeature_; } else { return OneofFeatureDefaultValue; } }
      set {
        _hasBits0 |= 16;
        oneofFeature_ = value;
      }
    }
    /// <summary>Gets whether the "oneof_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasOneofFeature {
      get { return (_hasBits0 & 16) != 0; }
    }
    /// <summary>Clears the value of the "oneof_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearOneofFeature() {
      _hasBits0 &= ~16;
    }

    /// <summary>Field number for the "enum_feature" field.</summary>
    public const int EnumFeatureFieldNumber = 6;
    private readonly static global::Pb.EnumFeature EnumFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature enumFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature EnumFeature {
      get { if ((_hasBits0 & 32) != 0) { return enumFeature_; } else { return EnumFeatureDefaultValue; } }
      set {
        _hasBits0 |= 32;
        enumFeature_ = value;
      }
    }
    /// <summary>Gets whether the "enum_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasEnumFeature {
      get { return (_hasBits0 & 32) != 0; }
    }
    /// <summary>Clears the value of the "enum_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearEnumFeature() {
      _hasBits0 &= ~32;
    }

    /// <summary>Field number for the "enum_entry_feature" field.</summary>
    public const int EnumEntryFeatureFieldNumber = 7;
    private readonly static global::Pb.EnumFeature EnumEntryFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature enumEntryFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature EnumEntryFeature {
      get { if ((_hasBits0 & 64) != 0) { return enumEntryFeature_; } else { return EnumEntryFeatureDefaultValue; } }
      set {
        _hasBits0 |= 64;
        enumEntryFeature_ = value;
      }
    }
    /// <summary>Gets whether the "enum_entry_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasEnumEntryFeature {
      get { return (_hasBits0 & 64) != 0; }
    }
    /// <summary>Clears the value of the "enum_entry_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearEnumEntryFeature() {
      _hasBits0 &= ~64;
    }

    /// <summary>Field number for the "service_feature" field.</summary>
    public const int ServiceFeatureFieldNumber = 8;
    private readonly static global::Pb.EnumFeature ServiceFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature serviceFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature ServiceFeature {
      get { if ((_hasBits0 & 128) != 0) { return serviceFeature_; } else { return ServiceFeatureDefaultValue; } }
      set {
        _hasBits0 |= 128;
        serviceFeature_ = value;
      }
    }
    /// <summary>Gets whether the "service_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasServiceFeature {
      get { return (_hasBits0 & 128) != 0; }
    }
    /// <summary>Clears the value of the "service_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearServiceFeature() {
      _hasBits0 &= ~128;
    }

    /// <summary>Field number for the "method_feature" field.</summary>
    public const int MethodFeatureFieldNumber = 9;
    private readonly static global::Pb.EnumFeature MethodFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature methodFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature MethodFeature {
      get { if ((_hasBits0 & 256) != 0) { return methodFeature_; } else { return MethodFeatureDefaultValue; } }
      set {
        _hasBits0 |= 256;
        methodFeature_ = value;
      }
    }
    /// <summary>Gets whether the "method_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMethodFeature {
      get { return (_hasBits0 & 256) != 0; }
    }
    /// <summary>Clears the value of the "method_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMethodFeature() {
      _hasBits0 &= ~256;
    }

    /// <summary>Field number for the "multiple_feature" field.</summary>
    public const int MultipleFeatureFieldNumber = 10;
    private readonly static global::Pb.EnumFeature MultipleFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature multipleFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature MultipleFeature {
      get { if ((_hasBits0 & 512) != 0) { return multipleFeature_; } else { return MultipleFeatureDefaultValue; } }
      set {
        _hasBits0 |= 512;
        multipleFeature_ = value;
      }
    }
    /// <summary>Gets whether the "multiple_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasMultipleFeature {
      get { return (_hasBits0 & 512) != 0; }
    }
    /// <summary>Clears the value of the "multiple_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearMultipleFeature() {
      _hasBits0 &= ~512;
    }

    /// <summary>Field number for the "bool_field_feature" field.</summary>
    public const int BoolFieldFeatureFieldNumber = 11;
    private readonly static bool BoolFieldFeatureDefaultValue = false;

    private bool boolFieldFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool BoolFieldFeature {
      get { if ((_hasBits0 & 1024) != 0) { return boolFieldFeature_; } else { return BoolFieldFeatureDefaultValue; } }
      set {
        _hasBits0 |= 1024;
        boolFieldFeature_ = value;
      }
    }
    /// <summary>Gets whether the "bool_field_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasBoolFieldFeature {
      get { return (_hasBits0 & 1024) != 0; }
    }
    /// <summary>Clears the value of the "bool_field_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearBoolFieldFeature() {
      _hasBits0 &= ~1024;
    }

    /// <summary>Field number for the "source_feature" field.</summary>
    public const int SourceFeatureFieldNumber = 15;
    private readonly static global::Pb.EnumFeature SourceFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature sourceFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature SourceFeature {
      get { if ((_hasBits0 & 2048) != 0) { return sourceFeature_; } else { return SourceFeatureDefaultValue; } }
      set {
        _hasBits0 |= 2048;
        sourceFeature_ = value;
      }
    }
    /// <summary>Gets whether the "source_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSourceFeature {
      get { return (_hasBits0 & 2048) != 0; }
    }
    /// <summary>Clears the value of the "source_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSourceFeature() {
      _hasBits0 &= ~2048;
    }

    /// <summary>Field number for the "source_feature2" field.</summary>
    public const int SourceFeature2FieldNumber = 16;
    private readonly static global::Pb.EnumFeature SourceFeature2DefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature sourceFeature2_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature SourceFeature2 {
      get { if ((_hasBits0 & 4096) != 0) { return sourceFeature2_; } else { return SourceFeature2DefaultValue; } }
      set {
        _hasBits0 |= 4096;
        sourceFeature2_ = value;
      }
    }
    /// <summary>Gets whether the "source_feature2" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasSourceFeature2 {
      get { return (_hasBits0 & 4096) != 0; }
    }
    /// <summary>Clears the value of the "source_feature2" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearSourceFeature2() {
      _hasBits0 &= ~4096;
    }

    /// <summary>Field number for the "removed_feature" field.</summary>
    public const int RemovedFeatureFieldNumber = 17;
    private readonly static global::Pb.EnumFeature RemovedFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature removedFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature RemovedFeature {
      get { if ((_hasBits0 & 8192) != 0) { return removedFeature_; } else { return RemovedFeatureDefaultValue; } }
      set {
        _hasBits0 |= 8192;
        removedFeature_ = value;
      }
    }
    /// <summary>Gets whether the "removed_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasRemovedFeature {
      get { return (_hasBits0 & 8192) != 0; }
    }
    /// <summary>Clears the value of the "removed_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearRemovedFeature() {
      _hasBits0 &= ~8192;
    }

    /// <summary>Field number for the "future_feature" field.</summary>
    public const int FutureFeatureFieldNumber = 18;
    private readonly static global::Pb.EnumFeature FutureFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature futureFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature FutureFeature {
      get { if ((_hasBits0 & 16384) != 0) { return futureFeature_; } else { return FutureFeatureDefaultValue; } }
      set {
        _hasBits0 |= 16384;
        futureFeature_ = value;
      }
    }
    /// <summary>Gets whether the "future_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasFutureFeature {
      get { return (_hasBits0 & 16384) != 0; }
    }
    /// <summary>Clears the value of the "future_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearFutureFeature() {
      _hasBits0 &= ~16384;
    }

    /// <summary>Field number for the "legacy_feature" field.</summary>
    public const int LegacyFeatureFieldNumber = 19;
    private readonly static global::Pb.EnumFeature LegacyFeatureDefaultValue = global::Pb.EnumFeature.TestEnumFeatureUnknown;

    private global::Pb.EnumFeature legacyFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.EnumFeature LegacyFeature {
      get { if ((_hasBits0 & 32768) != 0) { return legacyFeature_; } else { return LegacyFeatureDefaultValue; } }
      set {
        _hasBits0 |= 32768;
        legacyFeature_ = value;
      }
    }
    /// <summary>Gets whether the "legacy_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasLegacyFeature {
      get { return (_hasBits0 & 32768) != 0; }
    }
    /// <summary>Clears the value of the "legacy_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearLegacyFeature() {
      _hasBits0 &= ~32768;
    }

    /// <summary>Field number for the "value_lifetime_feature" field.</summary>
    public const int ValueLifetimeFeatureFieldNumber = 20;
    private readonly static global::Pb.ValueLifetimeFeature ValueLifetimeFeatureDefaultValue = global::Pb.ValueLifetimeFeature.TestValueLifetimeUnknown;

    private global::Pb.ValueLifetimeFeature valueLifetimeFeature_;
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public global::Pb.ValueLifetimeFeature ValueLifetimeFeature {
      get { if ((_hasBits0 & 65536) != 0) { return valueLifetimeFeature_; } else { return ValueLifetimeFeatureDefaultValue; } }
      set {
        _hasBits0 |= 65536;
        valueLifetimeFeature_ = value;
      }
    }
    /// <summary>Gets whether the "value_lifetime_feature" field is set</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool HasValueLifetimeFeature {
      get { return (_hasBits0 & 65536) != 0; }
    }
    /// <summary>Clears the value of the "value_lifetime_feature" field</summary>
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void ClearValueLifetimeFeature() {
      _hasBits0 &= ~65536;
    }

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

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public bool Equals(TestFeatures other) {
      if (ReferenceEquals(other, null)) {
        return false;
      }
      if (ReferenceEquals(other, this)) {
        return true;
      }
      if (FileFeature != other.FileFeature) return false;
      if (ExtensionRangeFeature != other.ExtensionRangeFeature) return false;
      if (MessageFeature != other.MessageFeature) return false;
      if (FieldFeature != other.FieldFeature) return false;
      if (OneofFeature != other.OneofFeature) return false;
      if (EnumFeature != other.EnumFeature) return false;
      if (EnumEntryFeature != other.EnumEntryFeature) return false;
      if (ServiceFeature != other.ServiceFeature) return false;
      if (MethodFeature != other.MethodFeature) return false;
      if (MultipleFeature != other.MultipleFeature) return false;
      if (BoolFieldFeature != other.BoolFieldFeature) return false;
      if (SourceFeature != other.SourceFeature) return false;
      if (SourceFeature2 != other.SourceFeature2) return false;
      if (RemovedFeature != other.RemovedFeature) return false;
      if (FutureFeature != other.FutureFeature) return false;
      if (LegacyFeature != other.LegacyFeature) return false;
      if (ValueLifetimeFeature != other.ValueLifetimeFeature) 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 (HasFileFeature) hash ^= FileFeature.GetHashCode();
      if (HasExtensionRangeFeature) hash ^= ExtensionRangeFeature.GetHashCode();
      if (HasMessageFeature) hash ^= MessageFeature.GetHashCode();
      if (HasFieldFeature) hash ^= FieldFeature.GetHashCode();
      if (HasOneofFeature) hash ^= OneofFeature.GetHashCode();
      if (HasEnumFeature) hash ^= EnumFeature.GetHashCode();
      if (HasEnumEntryFeature) hash ^= EnumEntryFeature.GetHashCode();
      if (HasServiceFeature) hash ^= ServiceFeature.GetHashCode();
      if (HasMethodFeature) hash ^= MethodFeature.GetHashCode();
      if (HasMultipleFeature) hash ^= MultipleFeature.GetHashCode();
      if (HasBoolFieldFeature) hash ^= BoolFieldFeature.GetHashCode();
      if (HasSourceFeature) hash ^= SourceFeature.GetHashCode();
      if (HasSourceFeature2) hash ^= SourceFeature2.GetHashCode();
      if (HasRemovedFeature) hash ^= RemovedFeature.GetHashCode();
      if (HasFutureFeature) hash ^= FutureFeature.GetHashCode();
      if (HasLegacyFeature) hash ^= LegacyFeature.GetHashCode();
      if (HasValueLifetimeFeature) hash ^= ValueLifetimeFeature.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 (HasFileFeature) {
        output.WriteRawTag(8);
        output.WriteEnum((int) FileFeature);
      }
      if (HasExtensionRangeFeature) {
        output.WriteRawTag(16);
        output.WriteEnum((int) ExtensionRangeFeature);
      }
      if (HasMessageFeature) {
        output.WriteRawTag(24);
        output.WriteEnum((int) MessageFeature);
      }
      if (HasFieldFeature) {
        output.WriteRawTag(32);
        output.WriteEnum((int) FieldFeature);
      }
      if (HasOneofFeature) {
        output.WriteRawTag(40);
        output.WriteEnum((int) OneofFeature);
      }
      if (HasEnumFeature) {
        output.WriteRawTag(48);
        output.WriteEnum((int) EnumFeature);
      }
      if (HasEnumEntryFeature) {
        output.WriteRawTag(56);
        output.WriteEnum((int) EnumEntryFeature);
      }
      if (HasServiceFeature) {
        output.WriteRawTag(64);
        output.WriteEnum((int) ServiceFeature);
      }
      if (HasMethodFeature) {
        output.WriteRawTag(72);
        output.WriteEnum((int) MethodFeature);
      }
      if (HasMultipleFeature) {
        output.WriteRawTag(80);
        output.WriteEnum((int) MultipleFeature);
      }
      if (HasBoolFieldFeature) {
        output.WriteRawTag(88);
        output.WriteBool(BoolFieldFeature);
      }
      if (HasSourceFeature) {
        output.WriteRawTag(120);
        output.WriteEnum((int) SourceFeature);
      }
      if (HasSourceFeature2) {
        output.WriteRawTag(128, 1);
        output.WriteEnum((int) SourceFeature2);
      }
      if (HasRemovedFeature) {
        output.WriteRawTag(136, 1);
        output.WriteEnum((int) RemovedFeature);
      }
      if (HasFutureFeature) {
        output.WriteRawTag(144, 1);
        output.WriteEnum((int) FutureFeature);
      }
      if (HasLegacyFeature) {
        output.WriteRawTag(152, 1);
        output.WriteEnum((int) LegacyFeature);
      }
      if (HasValueLifetimeFeature) {
        output.WriteRawTag(160, 1);
        output.WriteEnum((int) ValueLifetimeFeature);
      }
      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 (HasFileFeature) {
        output.WriteRawTag(8);
        output.WriteEnum((int) FileFeature);
      }
      if (HasExtensionRangeFeature) {
        output.WriteRawTag(16);
        output.WriteEnum((int) ExtensionRangeFeature);
      }
      if (HasMessageFeature) {
        output.WriteRawTag(24);
        output.WriteEnum((int) MessageFeature);
      }
      if (HasFieldFeature) {
        output.WriteRawTag(32);
        output.WriteEnum((int) FieldFeature);
      }
      if (HasOneofFeature) {
        output.WriteRawTag(40);
        output.WriteEnum((int) OneofFeature);
      }
      if (HasEnumFeature) {
        output.WriteRawTag(48);
        output.WriteEnum((int) EnumFeature);
      }
      if (HasEnumEntryFeature) {
        output.WriteRawTag(56);
        output.WriteEnum((int) EnumEntryFeature);
      }
      if (HasServiceFeature) {
        output.WriteRawTag(64);
        output.WriteEnum((int) ServiceFeature);
      }
      if (HasMethodFeature) {
        output.WriteRawTag(72);
        output.WriteEnum((int) MethodFeature);
      }
      if (HasMultipleFeature) {
        output.WriteRawTag(80);
        output.WriteEnum((int) MultipleFeature);
      }
      if (HasBoolFieldFeature) {
        output.WriteRawTag(88);
        output.WriteBool(BoolFieldFeature);
      }
      if (HasSourceFeature) {
        output.WriteRawTag(120);
        output.WriteEnum((int) SourceFeature);
      }
      if (HasSourceFeature2) {
        output.WriteRawTag(128, 1);
        output.WriteEnum((int) SourceFeature2);
      }
      if (HasRemovedFeature) {
        output.WriteRawTag(136, 1);
        output.WriteEnum((int) RemovedFeature);
      }
      if (HasFutureFeature) {
        output.WriteRawTag(144, 1);
        output.WriteEnum((int) FutureFeature);
      }
      if (HasLegacyFeature) {
        output.WriteRawTag(152, 1);
        output.WriteEnum((int) LegacyFeature);
      }
      if (HasValueLifetimeFeature) {
        output.WriteRawTag(160, 1);
        output.WriteEnum((int) ValueLifetimeFeature);
      }
      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 (HasFileFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) FileFeature);
      }
      if (HasExtensionRangeFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) ExtensionRangeFeature);
      }
      if (HasMessageFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) MessageFeature);
      }
      if (HasFieldFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) FieldFeature);
      }
      if (HasOneofFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) OneofFeature);
      }
      if (HasEnumFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumFeature);
      }
      if (HasEnumEntryFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumEntryFeature);
      }
      if (HasServiceFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) ServiceFeature);
      }
      if (HasMethodFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) MethodFeature);
      }
      if (HasMultipleFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) MultipleFeature);
      }
      if (HasBoolFieldFeature) {
        size += 1 + 1;
      }
      if (HasSourceFeature) {
        size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) SourceFeature);
      }
      if (HasSourceFeature2) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) SourceFeature2);
      }
      if (HasRemovedFeature) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) RemovedFeature);
      }
      if (HasFutureFeature) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) FutureFeature);
      }
      if (HasLegacyFeature) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) LegacyFeature);
      }
      if (HasValueLifetimeFeature) {
        size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) ValueLifetimeFeature);
      }
      if (_unknownFields != null) {
        size += _unknownFields.CalculateSize();
      }
      return size;
    }

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
    [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
    public void MergeFrom(TestFeatures other) {
      if (other == null) {
        return;
      }
      if (other.HasFileFeature) {
        FileFeature = other.FileFeature;
      }
      if (other.HasExtensionRangeFeature) {
        ExtensionRangeFeature = other.ExtensionRangeFeature;
      }
      if (other.HasMessageFeature) {
        MessageFeature = other.MessageFeature;
      }
      if (other.HasFieldFeature) {
        FieldFeature = other.FieldFeature;
      }
      if (other.HasOneofFeature) {
        OneofFeature = other.OneofFeature;
      }
      if (other.HasEnumFeature) {
        EnumFeature = other.EnumFeature;
      }
      if (other.HasEnumEntryFeature) {
        EnumEntryFeature = other.EnumEntryFeature;
      }
      if (other.HasServiceFeature) {
        ServiceFeature = other.ServiceFeature;
      }
      if (other.HasMethodFeature) {
        MethodFeature = other.MethodFeature;
      }
      if (other.HasMultipleFeature) {
        MultipleFeature = other.MultipleFeature;
      }
      if (other.HasBoolFieldFeature) {
        BoolFieldFeature = other.BoolFieldFeature;
      }
      if (other.HasSourceFeature) {
        SourceFeature = other.SourceFeature;
      }
      if (other.HasSourceFeature2) {
        SourceFeature2 = other.SourceFeature2;
      }
      if (other.HasRemovedFeature) {
        RemovedFeature = other.RemovedFeature;
      }
      if (other.HasFutureFeature) {
        FutureFeature = other.FutureFeature;
      }
      if (other.HasLegacyFeature) {
        LegacyFeature = other.LegacyFeature;
      }
      if (other.HasValueLifetimeFeature) {
        ValueLifetimeFeature = other.ValueLifetimeFeature;
      }
      _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) {
      if ((tag & 7) == 4) {
        // Abort on any end group tag.
        return;
      }
      switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
            break;
          case 8: {
            FileFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 16: {
            ExtensionRangeFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 24: {
            MessageFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 32: {
            FieldFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 40: {
            OneofFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 48: {
            EnumFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 56: {
            EnumEntryFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 64: {
            ServiceFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 72: {
            MethodFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 80: {
            MultipleFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 88: {
            BoolFieldFeature = input.ReadBool();
            break;
          }
          case 120: {
            SourceFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 128: {
            SourceFeature2 = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 136: {
            RemovedFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 144: {
            FutureFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 152: {
            LegacyFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 160: {
            ValueLifetimeFeature = (global::Pb.ValueLifetimeFeature) 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) {
      if ((tag & 7) == 4) {
        // Abort on any end group tag.
        return;
      }
      switch(tag) {
          default:
            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
            break;
          case 8: {
            FileFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 16: {
            ExtensionRangeFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 24: {
            MessageFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 32: {
            FieldFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 40: {
            OneofFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 48: {
            EnumFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 56: {
            EnumEntryFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 64: {
            ServiceFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 72: {
            MethodFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 80: {
            MultipleFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 88: {
            BoolFieldFeature = input.ReadBool();
            break;
          }
          case 120: {
            SourceFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 128: {
            SourceFeature2 = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 136: {
            RemovedFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 144: {
            FutureFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 152: {
            LegacyFeature = (global::Pb.EnumFeature) input.ReadEnum();
            break;
          }
          case 160: {
            ValueLifetimeFeature = (global::Pb.ValueLifetimeFeature) input.ReadEnum();
            break;
          }
        }
      }
    }
    #endif

  }

  #endregion

}

#endregion Designer generated code
