From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs') diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs new file mode 100644 index 00000000..c4105259 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using ProtoBuf.Meta; + +namespace ProtoBuf +{ + internal static class ExtensibleUtil + { + internal static IEnumerable GetExtendedValues(IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag) + { + foreach (object obj in ExtensibleUtil.GetExtendedValues(RuntimeTypeModel.Default, typeof(TValue), instance, tag, format, singleton, allowDefinedTag)) + { + TValue value = (TValue)((object)obj); + yield return value; + value = default(TValue); + } + IEnumerator enumerator = null; + yield break; + yield break; + } + + internal static IEnumerable GetExtendedValues(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag) + { + bool flag = instance == null; + if (flag) + { + throw new ArgumentNullException("instance"); + } + bool flag2 = tag <= 0; + if (flag2) + { + throw new ArgumentOutOfRangeException("tag"); + } + IExtension extn = instance.GetExtensionObject(false); + bool flag3 = extn == null; + if (flag3) + { + yield break; + } + Stream stream = extn.BeginQuery(); + object value = null; + ProtoReader reader = null; + try + { + SerializationContext ctx = new SerializationContext(); + reader = ProtoReader.Create(stream, model, ctx, -1); + while (model.TryDeserializeAuxiliaryType(reader, format, tag, type, ref value, true, false, false, false) && value != null) + { + bool flag4 = !singleton; + if (flag4) + { + yield return value; + value = null; + } + } + bool flag5 = singleton && value != null; + if (flag5) + { + yield return value; + } + ctx = null; + } + finally + { + ProtoReader.Recycle(reader); + extn.EndQuery(stream); + } + yield break; + yield break; + } + + internal static void AppendExtendValue(TypeModel model, IExtensible instance, int tag, DataFormat format, object value) + { + bool flag = instance == null; + if (flag) + { + throw new ArgumentNullException("instance"); + } + bool flag2 = value == null; + if (flag2) + { + throw new ArgumentNullException("value"); + } + IExtension extensionObject = instance.GetExtensionObject(true); + bool flag3 = extensionObject == null; + if (flag3) + { + throw new InvalidOperationException("No extension object available; appended data would be lost."); + } + bool commit = false; + Stream stream = extensionObject.BeginAppend(); + try + { + using (ProtoWriter protoWriter = new ProtoWriter(stream, model, null)) + { + model.TrySerializeAuxiliaryType(protoWriter, null, format, tag, value, false); + protoWriter.Close(); + } + commit = true; + } + finally + { + extensionObject.EndAppend(stream, commit); + } + } + } +} -- cgit v1.1-26-g67d0