protobuf从字节数组转换为对象
阿里云国际版折扣https://www.yundadi.com |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
- 主要的核心就是mergeFrom
public static object FromBytes(Type type, byte[] bytes, int index, int count)
{
object message = Activator.CreateInstance(type);
((Google.Protobuf.IMessage)message).MergeFrom(bytes, index, count);
ISupportInitialize iSupportInitialize = message as ISupportInitialize;
if (iSupportInitialize == null)
{
return message;
}
iSupportInitialize.EndInit();
return message;
}