From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../ProtoBuf/Serializers/NetObjectSerializer.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs') diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs new file mode 100644 index 00000000..6dd8be72 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs @@ -0,0 +1,56 @@ +using System; +using ProtoBuf.Meta; + +namespace ProtoBuf.Serializers +{ + internal sealed class NetObjectSerializer : IProtoSerializer + { + public Type ExpectedType + { + get + { + return this.type; + } + } + + public bool ReturnsValue + { + get + { + return true; + } + } + + public bool RequiresOldValue + { + get + { + return true; + } + } + + private readonly int key; + + private readonly Type type; + + private readonly BclHelpers.NetObjectOptions options; + + public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options) + { + bool flag = (options & BclHelpers.NetObjectOptions.DynamicType) > BclHelpers.NetObjectOptions.None; + this.key = (flag ? -1 : key); + this.type = (flag ? model.MapType(typeof(object)) : type); + this.options = options; + } + + public object Read(object value, ProtoReader source) + { + return BclHelpers.ReadNetObject(value, source, this.key, (this.type == typeof(object)) ? null : this.type, this.options); + } + + public void Write(object value, ProtoWriter dest) + { + BclHelpers.WriteNetObject(value, dest, this.key, this.options); + } + } +} -- cgit v1.1-26-g67d0