summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/ProtoBuf/Serializers/NetObjectSerializer.cs56
1 files changed, 56 insertions, 0 deletions
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);
+ }
+ }
+}