protobuf从字节数组转换为对象

  • 主要的核心就是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;
		}

版权声明:本文为qq_33574890原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。