// <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",
            "CzIQLnBiLlRlc3RGZWF0dXJlcyLbCgoMVGVzdEZlYXR1cmVzEnsKDGZpbGVf",
            "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",
            "mAEBmAEEogELEgZWQUxVRTEYhAeiAQsSBlZBTFVFMhjoB7IBBgjnByDoByrJ",
            "AgoLRW51bUZlYXR1cmUSHQoZVEVTVF9FTlVNX0ZFQVRVUkVfVU5LTk9XThAA",
            "EgoKBlZBTFVFMRABEgoKBlZBTFVFMhACEgoKBlZBTFVFMxADEgoKBlZBTFVF",
            "NBAEEgoKBlZBTFVFNRAFEgoKBlZBTFVFNhAGEgoKBlZBTFVFNxAHEgoKBlZB",
            "TFVFOBAIEgoKBlZBTFVFORAJEgsKB1ZBTFVFMTAQChILCgdWQUxVRTExEAsS",
            "CwoHVkFMVUUxMhAMEgsKB1ZBTFVFMTMQDRILCgdWQUxVRTE0EA4SCwoHVkFM",
            "VUUxNRAPEhsKE1ZBTFVFX0VNUFRZX1NVUFBPUlQQYhoCIgASRAoMVkFMVUVf",
            "RlVUVVJFEGMaMiIwCJ2NBhCejQYaIkN1c3RvbSBmZWF0dXJlIGRlcHJlY2F0",
            "aW9uIHdhcm5pbmcgn40GOjwKBHRlc3QSGy5nb29nbGUucHJvdG9idWYuRmVh",
            "dHVyZVNldBiPTiABKAsyEC5wYi5UZXN0RmVhdHVyZXM="));
      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor, },
          new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Pb.EnumFeature), }, 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" }, 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,
    [pbr::OriginalName("VALUE_EMPTY_SUPPORT")] ValueEmptySupport = 98,
    [pbr::OriginalName("VALUE_FUTURE")] ValueFuture = 99,
  }

  #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_;
      _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;
    }

    [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;
      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 (_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 (_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 (_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 (_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;
      }
      _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;
          }
        }
      }
    #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;
          }
        }
      }
    }
    #endif

  }

  #endregion

}

#endregion Designer generated code
