You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
using System.Diagnostics;
|
|
using ProtoCSStruct;
|
|
using Sog;
|
|
using Sog.IO;
|
|
|
|
namespace Mail
|
|
{
|
|
public abstract class MailDBOperator
|
|
{
|
|
private long zipLenOld;
|
|
private long zipLenNew;
|
|
private long zipCpuTicks;
|
|
private int zipCount;
|
|
private long zipTimeMs => swMsFreq > 0 ? zipCpuTicks / swMsFreq : 0;
|
|
|
|
private long unzipLenOld;
|
|
private long unzipLenNew;
|
|
private long unzipCpuTicks;
|
|
private int unzipCount;
|
|
private long unzipTimeMs => swMsFreq > 0 ? unzipCpuTicks / swMsFreq : 0;
|
|
|
|
private Stopwatch sw;
|
|
private long swMsFreq;
|
|
|
|
|
|
public MailDBOperator()
|
|
{
|
|
sw = new Stopwatch();
|
|
sw.Start();
|
|
// 转换成每毫秒的tick频率
|
|
swMsFreq = Stopwatch.Frequency / 1000;
|
|
}
|
|
|
|
public byte[] ZipData(byte[] unzipData)
|
|
{
|
|
if (unzipData == null || unzipData.Length == 0)
|
|
{
|
|
return unzipData;
|
|
}
|
|
|
|
long oldTicks = sw.ElapsedTicks;
|
|
byte[] zipData = ZipUtils.CompressBytes(unzipData);
|
|
long costTicks = sw.ElapsedTicks - oldTicks;
|
|
|
|
zipLenOld += unzipData.Length;
|
|
zipLenNew += zipData.Length;
|
|
zipCpuTicks += costTicks;
|
|
zipCount++;
|
|
|
|
TraceLog.Trace("MailDBOperator.ZipData len {0} -> {1} cpuTicks {2}, total Len {3} -> {4} timeMs {5} count {6}"
|
|
, unzipData.Length, zipData.Length, costTicks, zipLenOld, zipLenNew, zipTimeMs, zipCount);
|
|
|
|
return zipData;
|
|
}
|
|
|
|
public byte[] UnzipData(byte[] zipData)
|
|
{
|
|
if (zipData == null || zipData.Length == 0)
|
|
{
|
|
return zipData;
|
|
}
|
|
|
|
long oldTicks = sw.ElapsedTicks;
|
|
byte[] unzipData = ZipUtils.DecompressBytes(zipData);
|
|
long costTicks = sw.ElapsedTicks - oldTicks;
|
|
|
|
unzipLenOld += zipData.Length;
|
|
unzipLenNew += unzipData.Length;
|
|
unzipCpuTicks += costTicks;
|
|
unzipCount++;
|
|
|
|
TraceLog.Trace("MailDBOperator.UnzipData len {0} -> {1} cpuTicks {2}, total Len {3} -> {4} timeMs {5} count {6}"
|
|
, zipData.Length, unzipData.Length, costTicks, unzipLenOld, unzipLenNew, unzipTimeMs, unzipCount);
|
|
|
|
return unzipData;
|
|
}
|
|
|
|
//销毁的时候置空
|
|
public abstract void Dispose();
|
|
|
|
public abstract void KeepAlive();
|
|
|
|
public abstract int QueryMail(long uid, ref DBMailBlob blob);
|
|
|
|
public abstract bool InsertMail(long uid, ref DBMailBlob blob);
|
|
|
|
public abstract bool UpdateMail(long uid, ref DBMailBlob blob);
|
|
}
|
|
|
|
|
|
}
|
|
|