1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
using System;
using System.Collections.Generic;
using System.IO;
using ProtoBuf.Meta;
namespace ProtoBuf
{
public static class Serializer
{
private static bool useMultiThread = false;
public static bool isSkipProtoIgnore = false;
private const string ProtoBinaryField = "proto";
public const int ListItemTag = 1;
public static class NonGeneric
{
public static object DeepClone(object instance)
{
return (instance == null) ? null : RuntimeTypeModel.Default.DeepClone(instance);
}
public static void Serialize(Stream dest, object instance)
{
bool flag = instance != null;
if (flag)
{
RuntimeTypeModel.Default.Serialize(dest, instance);
}
}
public static object Deserialize(Type type, Stream source)
{
return RuntimeTypeModel.Default.Deserialize(source, null, type);
}
public static object Merge(Stream source, object instance)
{
bool flag = instance == null;
if (flag)
{
throw new ArgumentNullException("instance");
}
return RuntimeTypeModel.Default.Deserialize(source, instance, instance.GetType(), null);
}
public static void SerializeWithLengthPrefix(Stream destination, object instance, PrefixStyle style, int fieldNumber)
{
bool flag = instance == null;
if (flag)
{
throw new ArgumentNullException("instance");
}
RuntimeTypeModel @default = RuntimeTypeModel.Default;
@default.SerializeWithLengthPrefix(destination, instance, @default.MapType(instance.GetType()), style, fieldNumber);
}
public static bool TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style, Serializer.TypeResolver resolver, out object value)
{
value = RuntimeTypeModel.Default.DeserializeWithLengthPrefix(source, null, null, style, 0, resolver);
return value != null;
}
public static bool CanSerialize(Type type)
{
return RuntimeTypeModel.Default.IsDefined(type);
}
}
public static class GlobalOptions
{
[Obsolete("Please use RuntimeTypeModel.Default.InferTagFromNameDefault instead (or on a per-model basis)", false)]
public static bool InferTagFromName
{
get
{
return RuntimeTypeModel.Default.InferTagFromNameDefault;
}
set
{
RuntimeTypeModel.Default.InferTagFromNameDefault = value;
}
}
}
public delegate Type TypeResolver(int fieldNumber);
public static string GetProto<T>()
{
return RuntimeTypeModel.Default.GetSchema(RuntimeTypeModel.Default.MapType(typeof(T)));
}
public static void SetMultiThread(bool multiThread)
{
Serializer.useMultiThread = multiThread;
}
public static void SetSkipProtoIgnore(bool skipProtoIgnore)
{
Serializer.isSkipProtoIgnore = skipProtoIgnore;
}
public static T DeepClone<T>(T instance)
{
bool flag = instance == null;
T result;
if (flag)
{
result = instance;
}
else
{
bool flag2 = Serializer.useMultiThread;
if (flag2)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
RuntimeTypeModel obj = @default;
lock (obj)
{
return (T)((object)@default.DeepClone(instance));
}
}
result = (T)((object)RuntimeTypeModel.Default.DeepClone(instance));
}
return result;
}
public static T Merge<T>(Stream source, T instance)
{
bool flag = Serializer.useMultiThread;
if (flag)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
RuntimeTypeModel obj = @default;
lock (obj)
{
return (T)((object)@default.Deserialize(source, instance, typeof(T)));
}
}
return (T)((object)RuntimeTypeModel.Default.Deserialize(source, instance, typeof(T)));
}
public static T Deserialize<T>(Stream source)
{
bool flag = Serializer.useMultiThread;
if (flag)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
RuntimeTypeModel obj = @default;
lock (obj)
{
return (T)((object)@default.Deserialize(source, null, typeof(T)));
}
}
return (T)((object)RuntimeTypeModel.Default.Deserialize(source, null, typeof(T)));
}
public static void Serialize<T>(Stream destination, T instance)
{
bool flag = instance != null;
if (flag)
{
bool flag2 = Serializer.useMultiThread;
if (flag2)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
RuntimeTypeModel obj = @default;
lock (obj)
{
@default.Serialize(destination, instance);
}
}
else
{
RuntimeTypeModel.Default.Serialize(destination, instance);
}
}
}
public static void Clear()
{
bool flag = Serializer.useMultiThread;
if (flag)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
RuntimeTypeModel obj = @default;
lock (obj)
{
RuntimeTypeModel.Default.Clear();
}
}
}
public static TTo ChangeType<TFrom, TTo>(TFrom instance)
{
TTo result;
using (MemoryStream memoryStream = new MemoryStream())
{
Serializer.Serialize<TFrom>(memoryStream, instance);
memoryStream.Position = 0L;
result = Serializer.Deserialize<TTo>(memoryStream);
}
return result;
}
public static void PrepareSerializer<T>()
{
}
public static IEnumerable<T> DeserializeItems<T>(Stream source, PrefixStyle style, int fieldNumber)
{
return RuntimeTypeModel.Default.DeserializeItems<T>(source, style, fieldNumber);
}
public static T DeserializeWithLengthPrefix<T>(Stream source, PrefixStyle style)
{
return Serializer.DeserializeWithLengthPrefix<T>(source, style, 0);
}
public static T DeserializeWithLengthPrefix<T>(Stream source, PrefixStyle style, int fieldNumber)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
return (T)((object)@default.DeserializeWithLengthPrefix(source, null, @default.MapType(typeof(T)), style, fieldNumber));
}
public static T MergeWithLengthPrefix<T>(Stream source, T instance, PrefixStyle style)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
return (T)((object)@default.DeserializeWithLengthPrefix(source, instance, @default.MapType(typeof(T)), style, 0));
}
public static void SerializeWithLengthPrefix<T>(Stream destination, T instance, PrefixStyle style)
{
Serializer.SerializeWithLengthPrefix<T>(destination, instance, style, 0);
}
public static void SerializeWithLengthPrefix<T>(Stream destination, T instance, PrefixStyle style, int fieldNumber)
{
RuntimeTypeModel @default = RuntimeTypeModel.Default;
@default.SerializeWithLengthPrefix(destination, instance, @default.MapType(typeof(T)), style, fieldNumber);
}
public static bool TryReadLengthPrefix(Stream source, PrefixStyle style, out int length)
{
int num;
int num2;
length = ProtoReader.ReadLengthPrefix(source, false, style, out num, out num2);
return num2 > 0;
}
public static bool TryReadLengthPrefix(byte[] buffer, int index, int count, PrefixStyle style, out int length)
{
bool result;
using (Stream stream = new MemoryStream(buffer, index, count))
{
result = Serializer.TryReadLengthPrefix(stream, style, out length);
}
return result;
}
public static void FlushPool()
{
BufferPool.Flush();
}
}
}
|