diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/ProtoBuf/ExtensibleUtil.cs | 109 |
1 files changed, 109 insertions, 0 deletions
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<TValue> GetExtendedValues<TValue>(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);
+ }
+ }
+ }
+}
|