/// <summary> /// 尝试进行解包 /// </summary> /// <param name="ex">解包发生的异常</param> /// <returns>解包的数据</returns> private object Decode(out Exception ex) { var data = new byte[packetLength]; stream.Seek(0, SeekOrigin.Begin); var read = stream.Read(data, 0, data.Length); if (read < stream.Length) { var migrateData = new byte[stream.Length - read]; stream.Read(migrateData, 0, migrateData.Length); Reset(); stream.Write(migrateData, 0, migrateData.Length); } else { Reset(); } var packet = packer.Decode(data, out ex); return(ex != null ? null : packet); }