/// <summary> /// 异步流读取完成 /// </summary> /// <param name="result">异步操作状态</param> private void onRead(IAsyncResult result) { try { int read = stream.EndRead(result); if (read > 0) { memoryStream.UnsafeAddLength(read); if (memoryStream.UnsafeArray.Length == memoryStream.Length) { memoryStream.PrepLength(memoryStream.Length); } stream.BeginRead(memoryStream.UnsafeArray, memoryStream.Length, memoryStream.UnsafeArray.Length - memoryStream.Length, onRead, result.AsyncState); } else if (read == 0) { completed(); } } catch (Exception error) { this.error = error; completed(); } }
/// <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); } }