|
|
@@ -14,7 +14,6 @@ namespace ETModel
|
|
|
|
|
|
public static object FromBytes(Type type, byte[] bytes, int index, int count)
|
|
|
{
|
|
|
- // 这个message可以从池中获取,减少gc
|
|
|
object message = Activator.CreateInstance(type);
|
|
|
((Google.Protobuf.IMessage)message).MergeFrom(bytes, index, count);
|
|
|
ISupportInitialize iSupportInitialize = message as ISupportInitialize;
|
|
|
@@ -28,7 +27,6 @@ namespace ETModel
|
|
|
|
|
|
public static object FromStream(Type type, MemoryStream stream)
|
|
|
{
|
|
|
- // 这个message可以从池中获取,减少gc
|
|
|
object message = Activator.CreateInstance(type);
|
|
|
((Google.Protobuf.IMessage)message).MergeFrom(stream.GetBuffer(), (int)stream.Position, (int)stream.Length);
|
|
|
ISupportInitialize iSupportInitialize = message as ISupportInitialize;
|
|
|
@@ -39,5 +37,18 @@ namespace ETModel
|
|
|
iSupportInitialize.EndInit();
|
|
|
return message;
|
|
|
}
|
|
|
+
|
|
|
+ public static object FromStream(object message, MemoryStream stream)
|
|
|
+ {
|
|
|
+ // 这个message可以从池中获取,减少gc
|
|
|
+ ((Google.Protobuf.IMessage)message).MergeFrom(stream.GetBuffer(), (int)stream.Position, (int)stream.Length);
|
|
|
+ ISupportInitialize iSupportInitialize = message as ISupportInitialize;
|
|
|
+ if (iSupportInitialize == null)
|
|
|
+ {
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ iSupportInitialize.EndInit();
|
|
|
+ return message;
|
|
|
+ }
|
|
|
}
|
|
|
}
|