/// <summary> /// 序列化 /// </summary> /// <param name="map">成员位图</param> /// <param name="serializeSize">序列化字节长度</param> /// <param name="stream">数据流</param> public static unsafe void Serialize(byte[] map, int serializeSize, memoryStream stream) { if (map == null) { stream.PrepLength(serializeSize); fixed(byte *dataFixed = stream.Array) { fastCSharp.unsafer.memory.Fill(dataFixed + stream.Length, 0xffffffffU, serializeSize >> 2); } stream.Unsafer.AddLength(serializeSize); } else { stream.Write(map, 0, serializeSize); } }
/// <summary> /// 序列化 /// </summary> /// <param name="stream">数据流</param> public void Serialize(memoryStream stream) { stream.Write(map); }
/// <summary> /// 解压缩数据 /// </summary> /// <param name="compressData">压缩数据</param> /// <param name="type">压缩类型</param> /// <param name="startIndex">起始位置</param> /// <param name="count">解压缩字节数</param> /// <returns>解压缩后的数据</returns> public static memoryStream getDeCompressStream(this byte[] compressData, compression type, int startIndex, int count) { array.range range = new array.range(compressData.length(), startIndex, count); if (count == range.GetCount) { using (Stream memoryStream = new MemoryStream(compressData, 0, compressData.Length)) using (Stream compressStream = memoryStream.toCompressStream(CompressionMode.Decompress, false, type)) { memoryStream dataStream = new memoryStream(compressData.Length); byte[] buffer = new byte[config.pub.Default.StreamBufferLength]; for (int readLength = compressStream.Read(buffer, 0, config.pub.Default.StreamBufferLength); readLength != 0; readLength = compressStream.Read(buffer, 0, config.pub.Default.StreamBufferLength)) { dataStream.Write(buffer, 0, readLength); } return dataStream; } } else if (count == 0) return null; log.Default.Throw(log.exceptionType.IndexOutOfRange); return null; }