From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/ProtoBuf/ProtoContractAttribute.cs | 194 +++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/ProtoContractAttribute.cs (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/ProtoContractAttribute.cs') diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/ProtoContractAttribute.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/ProtoContractAttribute.cs new file mode 100644 index 00000000..ee0e6152 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/ProtoContractAttribute.cs @@ -0,0 +1,194 @@ +using System; + +namespace ProtoBuf +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] + public sealed class ProtoContractAttribute : Attribute + { + public string Name + { + get + { + return this.name; + } + set + { + this.name = value; + } + } + + public int ImplicitFirstTag + { + get + { + return this.implicitFirstTag; + } + set + { + bool flag = value < 1; + if (flag) + { + throw new ArgumentOutOfRangeException("ImplicitFirstTag"); + } + this.implicitFirstTag = value; + } + } + + public bool UseProtoMembersOnly + { + get + { + return this.HasFlag(4); + } + set + { + this.SetFlag(4, value); + } + } + + public bool IgnoreListHandling + { + get + { + return this.HasFlag(16); + } + set + { + this.SetFlag(16, value); + } + } + + public ImplicitFields ImplicitFields + { + get + { + return this.implicitFields; + } + set + { + this.implicitFields = value; + } + } + + public bool InferTagFromName + { + get + { + return this.HasFlag(1); + } + set + { + this.SetFlag(1, value); + this.SetFlag(2, true); + } + } + + internal bool InferTagFromNameHasValue + { + get + { + return this.HasFlag(2); + } + } + + public int DataMemberOffset + { + get + { + return this.dataMemberOffset; + } + set + { + this.dataMemberOffset = value; + } + } + + public bool SkipConstructor + { + get + { + return this.HasFlag(8); + } + set + { + this.SetFlag(8, value); + } + } + + public bool AsReferenceDefault + { + get + { + return this.HasFlag(32); + } + set + { + this.SetFlag(32, value); + } + } + + public bool EnumPassthru + { + get + { + return this.HasFlag(64); + } + set + { + this.SetFlag(64, value); + this.SetFlag(128, true); + } + } + + internal bool EnumPassthruHasValue + { + get + { + return this.HasFlag(128); + } + } + + private string name; + + private int implicitFirstTag; + + private ImplicitFields implicitFields; + + private int dataMemberOffset; + + private byte flags; + + private const byte OPTIONS_InferTagFromName = 1; + + private const byte OPTIONS_InferTagFromNameHasValue = 2; + + private const byte OPTIONS_UseProtoMembersOnly = 4; + + private const byte OPTIONS_SkipConstructor = 8; + + private const byte OPTIONS_IgnoreListHandling = 16; + + private const byte OPTIONS_AsReferenceDefault = 32; + + private const byte OPTIONS_EnumPassthru = 64; + + private const byte OPTIONS_EnumPassthruHasValue = 128; + + private bool HasFlag(byte flag) + { + return (this.flags & flag) == flag; + } + + private void SetFlag(byte flag, bool value) + { + if (value) + { + this.flags |= flag; + } + else + { + this.flags &= (byte)~flag; + } + } + } +} -- cgit v1.1-26-g67d0