diff --git a/Common/Cdy.Tag.Common/Common/CustomQueue.cs b/Common/Cdy.Tag.Common/Common/CustomQueue.cs new file mode 100644 index 0000000000000000000000000000000000000000..cafa7df7717f319e12194059d43907a8cae05064 --- /dev/null +++ b/Common/Cdy.Tag.Common/Common/CustomQueue.cs @@ -0,0 +1,90 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/5/23 23:58:40. +// Version 1.0 +// 种道洋 +//============================================================== + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Cdy.Tag +{ + public class CustomQueue + { + + #region ... Variables ... + private T[] mColections; + private int mCount = 0; + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + /// + /// + /// + /// + public CustomQueue(int count) + { + mColections = new T[count]; + mCount = count; + } + + #endregion ...Constructor... + + #region ... Properties ... + + + + public int Index { get; set; } + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + /// + public void Insert(T value) + { + Index++; + mColections[Index] = value; + } + + /// + /// + /// + /// + public T Remove() + { + Index--; + if (Index < 0) + { + Index = -1; + return default(T); + } + else + { + return mColections[Index]; + } + } + + public T Get(int index) + { + return mColections[index]; + } + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } +} diff --git a/Common/Cdy.Tag.Common/Common/MemoryBlock.cs b/Common/Cdy.Tag.Common/Common/MemoryBlock.cs index d8faa27fa81020fbadefacc5f82768057ae78e09..ba0dc081f963b8a5dc6df217eb4df6101985cd90 100644 --- a/Common/Cdy.Tag.Common/Common/MemoryBlock.cs +++ b/Common/Cdy.Tag.Common/Common/MemoryBlock.cs @@ -47,7 +47,7 @@ namespace Cdy.Tag private object mUserSizeLock = new object(); - public int BufferItemSize = 1024 * 1024 * 128; + public int BufferItemSize = 1024 * 1024 * 4; public static byte[] zoreData = new byte[1024 * 10]; diff --git a/Common/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj b/Common/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj index 4aa2b5f4678466516691b21c988261058fa25996..106c3898ae2bf8a00dc11a7e5ba464030ea5ee5e 100644 --- a/Common/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj +++ b/Common/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj @@ -8,6 +8,10 @@ true + + true + + diff --git a/Common/Cdy.Tag/His/CompressUnitManager.cs b/Common/Cdy.Tag/His/CompressUnitManager.cs index b71e6dfae7713afd67eb1ccf33ccc3a31a42c7cf..92a86bcde730af136efebf6f3626a5f55a0d7431 100644 --- a/Common/Cdy.Tag/His/CompressUnitManager.cs +++ b/Common/Cdy.Tag/His/CompressUnitManager.cs @@ -26,11 +26,18 @@ namespace Cdy.Tag /// private Dictionary mCompressUnit = new Dictionary(); + /// + /// + /// + private Dictionary> mPoolCompressUnits = new Dictionary>(); + /// /// /// public static CompressUnitManager Manager = new CompressUnitManager(); + + #endregion ...Variables... #region ... Events ... @@ -54,7 +61,52 @@ namespace Cdy.Tag /// public CompressUnitbase GetCompress(int type) { - return mCompressUnit.ContainsKey(type) ? mCompressUnit[type] : null; + lock (mPoolCompressUnits) + { + if (mCompressUnit.ContainsKey(type)) + { + if (mPoolCompressUnits.ContainsKey(type) && mPoolCompressUnits[type].Count > 0) + { + return mPoolCompressUnits[type].Dequeue(); + } + else + { + return mCompressUnit[type].Clone(); + } + } + } + return null; + } + + /// + /// + /// + /// + /// + public CompressUnitbase GetCompressQuick(int type) + { + return mCompressUnit.ContainsKey(type)?mCompressUnit[type]:null; + } + + /// + /// + /// + /// + public void ReleaseCompress(CompressUnitbase compress) + { + lock (mPoolCompressUnits) + { + if (mPoolCompressUnits.ContainsKey(compress.TypeCode)) + { + mPoolCompressUnits[compress.TypeCode].Enqueue(compress); + } + else + { + var dd = new Queue(); + dd.Enqueue(compress); + mPoolCompressUnits.Add(compress.TypeCode, dd); + } + } } /// diff --git a/Common/Cdy.Tag/His/CompressUnitbase.cs b/Common/Cdy.Tag/His/CompressUnitbase.cs index 40b21e21884177fa6612b57734b5a7834ce0b7a4..e699ebc3e155f9fd256310b4fd168999808dca29 100644 --- a/Common/Cdy.Tag/His/CompressUnitbase.cs +++ b/Common/Cdy.Tag/His/CompressUnitbase.cs @@ -91,6 +91,7 @@ namespace Cdy.Tag #region ... Methods ... + /// /// /// diff --git a/Common/Cdy.Tag/Interface/HisQueryResult.cs b/Common/Cdy.Tag/Interface/HisQueryResult.cs index 75c0a187a9890285fbfe9ffba54eb1c906618e8e..2f545027932fd808b9cbaf78713a3fbe7e73b9ba 100644 --- a/Common/Cdy.Tag/Interface/HisQueryResult.cs +++ b/Common/Cdy.Tag/Interface/HisQueryResult.cs @@ -838,6 +838,95 @@ namespace Cdy.Tag AddPoint(value.X, value.Y, value.Z, time, qulity); } + /// + /// + /// + /// + /// + public T GetValue(int index) + { + object re = null; + switch (mDataType) + { + case 0: + re = Convert.ToBoolean(MemoryHelper.ReadByte((void*)handle, index)); + break; + case 1: + re = MemoryHelper.ReadByte((void*)handle, index); + break; + case 2: + re = MemoryHelper.ReadShort((void*)handle, index * 2); + break; + case 3: + re = MemoryHelper.ReadShort((void*)handle, index * 2); + break; + case 4: + re = MemoryHelper.ReadInt32((void*)handle, index * 4); + break; + case 5: + re = MemoryHelper.ReadUInt32((void*)handle, index * 4); + break; + case 6: + re = MemoryHelper.ReadInt64((void*)handle, index * 8); + break; + case 7: + re = MemoryHelper.ReadUInt64((void*)handle, index * 8); + break; + case 8: + re = MemoryHelper.ReadFloat((void*)handle, index * 4); + break; + case 9: + re = MemoryHelper.ReadDouble((void*)handle, index * 8); + break; + case 10: + re = MemoryHelper.ReadDateTime((void*)handle, index * 8); + break; + case 11: + + int cc = 0; + int pos = 0; + while (true) + { + if (cc >= index) + { + break; + } + //pos += (mDataBuffer[pos]+1); + pos += MemoryHelper.ReadByte((void*)handle, pos) + 1; + cc++; + } + re = new string((char*)handle, pos + 1, MemoryHelper.ReadByte((void*)handle, pos)); + break; + case 12: + var x = MemoryHelper.ReadInt32((void*)handle, index * 8); + var y = MemoryHelper.ReadInt32((void*)handle, index * 8 + 4); + re = new IntPointData(x, y); + break; + case 13: + re = new UIntPointData(MemoryHelper.ReadUInt32((void*)handle, index * 8), MemoryHelper.ReadUInt32((void*)handle, index * 8 + 4)); + break; + case 14: + re = new IntPoint3Data(MemoryHelper.ReadInt32((void*)handle, index * 12), MemoryHelper.ReadInt32((void*)handle, index * 12 + 4), MemoryHelper.ReadInt32((void*)handle, index * 12 + 8)); + break; + case 15: + re = new UIntPoint3Data(MemoryHelper.ReadUInt32((void*)handle, index * 12), MemoryHelper.ReadUInt32((void*)handle, index * 12 + 4), MemoryHelper.ReadUInt32((void*)handle, index * 12 + 8)); + break; + case 16: + re = new LongPointData(MemoryHelper.ReadInt64((void*)handle, index * 16), MemoryHelper.ReadInt64((void*)handle, index * 16 + 8)); + break; + case 17: + re = new ULongPointData(MemoryHelper.ReadUInt64((void*)handle, index * 16), MemoryHelper.ReadUInt64((void*)handle, index * 16 + 8)); + break; + case 18: + re = new LongPoint3Data(MemoryHelper.ReadInt64((void*)handle, index * 24), MemoryHelper.ReadInt64((void*)handle, index * 24 + 8), MemoryHelper.ReadInt64((void*)handle, index * 24 + 16)); + break; + case 19: + re = new ULongPoint3Data(MemoryHelper.ReadUInt64((void*)handle, index * 24), MemoryHelper.ReadUInt64((void*)handle, index * 24 + 8), MemoryHelper.ReadUInt64((void*)handle, index * 24 + 16)); + break; + } + return (T)re; + } + /// /// /// diff --git a/Develop/DBStudio/Program.cs b/Develop/DBStudio/Program.cs index 25ff84a5f058c47bd3f016a0a420c56bd149145b..34cbf59af039473c0c3e84f8f63f584e971f94c8 100644 --- a/Develop/DBStudio/Program.cs +++ b/Develop/DBStudio/Program.cs @@ -396,6 +396,7 @@ namespace DBStudio { StringBuilder re = new StringBuilder(); re.AppendLine(); + re.AppendLine("save // save database "); re.AppendLine("start // start database "); re.AppendLine("restart // restart database "); re.AppendLine("stop // stop database "); diff --git a/Proxy/DBHighApi/DBHighApi.csproj b/Proxy/DBHighApi/DBHighApi.csproj index 297a9205d32901ef0ccfdc223bf15cd42b57c52b..8778bdc9204295818e5c6968c519e9d92867f14e 100644 --- a/Proxy/DBHighApi/DBHighApi.csproj +++ b/Proxy/DBHighApi/DBHighApi.csproj @@ -9,6 +9,10 @@ true + + true + + diff --git a/RunTime/DBHisDataServer/DBHisDataServer.csproj b/RunTime/DBHisDataServer/DBHisDataServer.csproj index 57e6be5b677834dbff1524e615b3d3f968c75128..097d67093902a1cbb3320567d1992072d10a9d79 100644 --- a/RunTime/DBHisDataServer/DBHisDataServer.csproj +++ b/RunTime/DBHisDataServer/DBHisDataServer.csproj @@ -10,6 +10,11 @@ true + + false + true + + diff --git a/RunTime/DBRuntime.Proxy/DBRuntime.Proxy.csproj b/RunTime/DBRuntime.Proxy/DBRuntime.Proxy.csproj index 1a0bfec13f5c6a95b2eae96f1825977f27e9261a..59647958974803672cd4ba7435e854d9a1128399 100644 --- a/RunTime/DBRuntime.Proxy/DBRuntime.Proxy.csproj +++ b/RunTime/DBRuntime.Proxy/DBRuntime.Proxy.csproj @@ -8,6 +8,10 @@ true + + true + + diff --git a/RunTime/DBRuntime.Real/DBRuntime.Real.csproj b/RunTime/DBRuntime.Real/DBRuntime.Real.csproj index da10528c9bb7d567f3e8ef6a0c70583e5fb7c4fb..ddea1c3d69fc10fead0d8cfcefbf8a570419135e 100644 --- a/RunTime/DBRuntime.Real/DBRuntime.Real.csproj +++ b/RunTime/DBRuntime.Real/DBRuntime.Real.csproj @@ -8,6 +8,10 @@ true + + true + + diff --git a/RunTime/DBRuntime/His/Compress/CompressEnginer.cs b/RunTime/DBRuntime/His/Compress/CompressEnginer.cs index d2e62ee2ffb98fe99eb28c8c7e7c1c668261c01a..4af30bb77550ab6ae9a495f56ee0fcb0cb1b49df 100644 --- a/RunTime/DBRuntime/His/Compress/CompressEnginer.cs +++ b/RunTime/DBRuntime/His/Compress/CompressEnginer.cs @@ -102,7 +102,7 @@ namespace Cdy.Tag } } - long psize = mTotalSize/mTargetMemorys.Count; + long psize = (long)(mTotalSize*1.5)/mTargetMemorys.Count; System.Threading.Tasks.Parallel.ForEach(mTargetMemorys, (vv) => { vv.Value.ReAlloc(vv.Value.HeadSize + psize); diff --git a/RunTime/DBRuntime/His/Compress/CompressMemory.cs b/RunTime/DBRuntime/His/Compress/CompressMemory.cs index 89b8225f54ba281982288a548580b1b1c44a9acd..c19a1cfed538b9437c30f5c2fa2d066f30f54198 100644 --- a/RunTime/DBRuntime/His/Compress/CompressMemory.cs +++ b/RunTime/DBRuntime/His/Compress/CompressMemory.cs @@ -28,6 +28,8 @@ namespace Cdy.Tag private Dictionary> mTagAddress; private DateTime mCurrentTime; private IHisEngine mHisTagService; + private Dictionary mCompressCach = new Dictionary(); + private Dictionary dtmp = new Dictionary(); #endregion ...Variables... #region ... Events ... @@ -67,6 +69,8 @@ namespace Cdy.Tag /// public static int TagCountPerMemory { get; set; } + + /// /// /// @@ -120,14 +124,15 @@ namespace Cdy.Tag #region ... Methods ... - /// - /// - /// - public void ResetTagAddress() - { - mTagAddress.Clear(); - mTagAddress = null; - } + ///// + ///// + ///// + //public void ResetTagAddress() + //{ + // mTagAddress.Clear(); + // mTagAddress = null; + // mCompressCach.Clear(); + //} /// /// @@ -135,12 +140,20 @@ namespace Cdy.Tag /// private void CheckTagAddress(MergeMemoryBlock sourceM) { - if(mTagAddress==null && sourceM!=null) + + if (mTagAddress==null && sourceM!=null) { mTagAddress = new Dictionary>(); + dtmp.Clear(); foreach (var vv in sourceM.TagAddress.Where(e=>e.Key>=Id* TagCountPerMemory && e.Key<(Id+1)* TagCountPerMemory)) { mTagAddress.Add(vv.Key,vv.Value); + dtmp.Add(vv.Key, 0); + var cpt = mHisTagService.GetHisTag(vv.Key).CompressType; + if(!mCompressCach.ContainsKey(cpt)) + { + mCompressCach.Add(cpt, CompressUnitManager.Manager.GetCompressQuick(cpt).Clone()); + } } } } @@ -165,16 +178,15 @@ namespace Cdy.Tag int headOffset = 4 + 4; long Offset = headOffset + this.mTagAddress.Count * 8; - - Dictionary dtmp = new Dictionary(); - this.MakeMemoryBusy(); + long ltmp1 = sw.ElapsedMilliseconds; + //更新数据区域 foreach(var vv in mTagAddress) { var size = CompressBlockMemory(source, vv.Value.Item1, Offset,vv.Value.Item3, vv.Value.Item4, vv.Key); - dtmp.Add(vv.Key, Offset); + dtmp[vv.Key]= Offset; Offset += size; datasize += size; } @@ -183,6 +195,8 @@ namespace Cdy.Tag this.WriteInt(0,(int)datasize); this.Write((int)this.mTagAddress.Count); + long ltmp2 = sw.ElapsedMilliseconds; + int count = 0; foreach (var vv in dtmp) { @@ -191,10 +205,12 @@ namespace Cdy.Tag count+=8; } + long ltmp3 = sw.ElapsedMilliseconds; + ServiceLocator.Locator.Resolve().RequestToSeriseFile(this, mCurrentTime); sw.Stop(); - - LoggerService.Service.Info("CompressEnginer", Id+ "压缩完成 耗时:"+sw.ElapsedMilliseconds); + + LoggerService.Service.Info("CompressEnginer", Id+ "压缩完成 耗时:"+sw.ElapsedMilliseconds +" ltmp1:"+ltmp1 +" ltmp2:"+(ltmp2-ltmp1)+" ltmp3:"+(ltmp3-ltmp2),ConsoleColor.Red); } /// @@ -219,12 +235,12 @@ namespace Cdy.Tag var comtype = histag.CompressType;//压缩类型 - this.CheckAndResize(targetPosition + len); + // this.CheckAndResize(targetPosition + len); //写入压缩类型 this.WriteByte(targetPosition + 4, (byte)comtype); - var tp = CompressUnitManager.Manager.GetCompress(comtype); + var tp = mCompressCach[comtype]; if (tp != null) { tp.QulityOffset = (int)qulityoffset; @@ -235,6 +251,7 @@ namespace Cdy.Tag var size = tp.Compress(mSourceMemory, addr, this, targetPosition + 5, len) + 1; this.WriteInt(targetPosition, (int)size); //this.Dump(); + return size + 5; } diff --git a/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit.cs b/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit.cs index d214ee02139cfb007f69de1303a44dbec1f94855..aee8404272474e8098f600b59e7652ec14f1c2d4 100644 --- a/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit.cs +++ b/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit.cs @@ -65,7 +65,7 @@ namespace Cdy.Tag /// /// /// - protected override Memory CompressValues(MarshalMemoryBlock source, long offset, int count, Queue emptyIds) + protected override Memory CompressValues(MarshalMemoryBlock source, long offset, int count, CustomQueue emptys, TagType type) { var deadArea = this.Parameters.ContainsKey("DeadValue") ? this.Parameters["DeadValue"] : 0; var deadType = (int)(this.Parameters.ContainsKey("DeadType") ? this.Parameters["DeadType"] : 0); @@ -76,7 +76,7 @@ namespace Cdy.Tag bool isFirst = true; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; if (typeof(T) == typeof(byte)) { @@ -103,8 +103,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); @@ -134,8 +134,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } @@ -165,8 +165,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } @@ -196,8 +196,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } @@ -227,8 +227,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } } @@ -257,8 +257,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } @@ -288,8 +288,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } @@ -319,8 +319,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); @@ -350,8 +350,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); diff --git a/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit.cs b/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit.cs index 5e07fb55bc90dcf85e5f7f14ede31a8373a1de25..6800d77b4921b40bbe64edad27473505112ded46 100644 --- a/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit.cs +++ b/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit.cs @@ -59,43 +59,44 @@ namespace Cdy.Tag switch (TagType) { case TagType.Bool: - return Compress(source, sourceAddr, target, targetAddr+8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr+8, size,TagType) + 8; case TagType.Byte: - return Compress(source, sourceAddr, target, targetAddr+8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr+8, size, TagType) + 8; case TagType.UShort: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.Short: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.UInt: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.Int: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.ULong: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.Long: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.Double: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; + case TagType.Float: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.String: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.IntPoint: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.UIntPoint: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.LongPoint: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.ULongPoint: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.IntPoint3: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.UIntPoint3: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.LongPoint3: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; case TagType.ULongPoint3: - return Compress(source, sourceAddr, target, targetAddr + 8, size) + 8; + return Compress(source, sourceAddr, target, targetAddr + 8, size, TagType) + 8; } return 8; } @@ -106,10 +107,11 @@ namespace Cdy.Tag /// /// /// - protected byte[] CompressTimers(List timerVals, Queue emptyIds) + protected Memory CompressTimers(List timerVals, CustomQueue emptyIds) { int preids = 0; mVarintMemory.Position = 0; + emptys.Index = -1; bool isFirst = true; for (int i = 0; i < timerVals.Count; i++) { @@ -129,12 +131,45 @@ namespace Cdy.Tag } else { - emptyIds.Enqueue(i); + emptyIds.Insert(i); } } - return mVarintMemory.Buffer.AsSpan(0, mVarintMemory.Position).ToArray(); + return mVarintMemory.Buffer.AsMemory(0, mVarintMemory.Position); + } + + protected Memory CompressTimers(MarshalMemoryBlock timerVals,long startaddr,int count, CustomQueue emptyIds) + { + int preids = 0; + mVarintMemory.Position = 0; + emptyIds.Index = -1; + bool isFirst = true; + int id = 0; + for (int i = 0; i < count; i++) + { + + if (timerVals[i] > 0 || i == 0) + { + id = timerVals.ReadShort(startaddr + i * 2); + //var id = timerVals[i]; + if (isFirst) + { + mVarintMemory.WriteInt32(id); + isFirst = false; + } + else + { + mVarintMemory.WriteInt32(id - preids); + } + preids = id; + } + else + { + emptyIds.Insert(i); + } + } + return mVarintMemory.Buffer.AsMemory(0, mVarintMemory.Position); } - + /// /// /// @@ -144,508 +179,464 @@ namespace Cdy.Tag /// /// /// - protected virtual Memory CompressValues(MarshalMemoryBlock source,long offset,int count, Queue emptyIds) + protected virtual Memory CompressValues(MarshalMemoryBlock source,long offset,int count, CustomQueue emptyIds,TagType type) { mMarshalMemory.Position = 0; mVarintMemory.Position = 0; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + // emptyIds.TryDequeue(out ig); bool isFirst = true; - - if (typeof(T) == typeof(byte)) + switch (type) { - for (int i = 0; i < count; i++) - { - if (i != ig) - { - var id = source.ReadByte(offset + i); - mMarshalMemory.Write(id); - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); - } - else if (typeof(T) == typeof(short)) - { - short sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + case TagType.Byte: + for (int i = 0; i < count; i++) { - var id = source.ReadShort(offset + i * 2); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteSInt32(id); - isFirst = false; - sval = id; + var id = source.ReadByte(offset + i); + mMarshalMemory.Write(id); } else { - mVarintMemory.WriteSInt32(id - sval); - sval = id; + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + // emptyIds.TryDequeue(out ig); } } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(ushort)) - { - ushort sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); + case TagType.Short: + short sval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadUShort(offset + i * 2); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteSInt32(id); - isFirst = false; - sval = id; + var id = source.ReadShort(offset + i * 2); + if (isFirst) + { + mVarintMemory.WriteSInt32(id); + isFirst = false; + sval = id; + } + else + { + mVarintMemory.WriteSInt32(id - sval); + sval = id; + } } else { - mVarintMemory.WriteSInt32(id - sval); - sval = id; + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(int)) - { - int sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.UShort: + ushort ssval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadInt(offset + i * 4); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - isFirst = false; - sval = id; + var id = source.ReadUShort(offset + i * 2); + if (isFirst) + { + mVarintMemory.WriteSInt32(id); + isFirst = false; + ssval = id; + } + else + { + mVarintMemory.WriteSInt32(id - ssval); + ssval = id; + } } else { - mVarintMemory.WriteSInt32(id - sval); - sval = id; + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(uint)) - { - uint sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.Int: + int isval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadUInt(offset + i * 4); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - isFirst = false; + var id = source.ReadInt(offset + i * 4); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + isFirst = false; + isval = id; + } + else + { + mVarintMemory.WriteSInt32(id - isval); + isval = id; + } } else { - mVarintMemory.WriteSInt32((int)(id - sval)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - } - else if (typeof(T) == typeof(long)) - { - long sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.UInt: + uint uisval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadLong(offset + i * 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - isFirst = false; - sval = id; + var id = source.ReadUInt(offset + i * 4); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + isFirst = false; + uisval = id; + } + else + { + mVarintMemory.WriteSInt32((int)(id - uisval)); + } + uisval = id; } else { - mVarintMemory.WriteSInt64((id - sval)); - sval = id; + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(ulong)) - { - ulong sval = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.Long: + long lsval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadULong(offset + i * 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - isFirst = false; - sval = id; + var id = source.ReadLong(offset + i * 8); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + isFirst = false; + lsval = id; + } + else + { + mVarintMemory.WriteSInt64((id - lsval)); + lsval = id; + } } else { - mVarintMemory.WriteSInt64((long)(id - sval)); - sval = id; + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(double)) - { - for (int i = 0; i < count; i++) - { - if (i != ig) - { - var id = source.ReadDouble(offset + i * 8); - mMarshalMemory.Write(id); - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); - } - else if (typeof(T) == typeof(float)) - { - for (int i = 0; i < count; i++) - { - if (i != ig) - { - var id = source.ReadFloat(offset + i * 4); - mMarshalMemory.Write(id); - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); - } - else if (typeof(T) == typeof(IntPointData)) - { - int sval = 0; - int sval2 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.ULong: + ulong ulsval = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadInt(offset + i * 8); - var id2 = source.ReadInt(offset + i * 8 + 4); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - mVarintMemory.WriteInt32(id2); - isFirst = false; + var id = source.ReadULong(offset + i * 8); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + isFirst = false; + ulsval = id; + } + else + { + mVarintMemory.WriteSInt64((long)(id - ulsval)); + ulsval = id; + } } else { - mVarintMemory.WriteSInt32(id - sval); - mVarintMemory.WriteSInt32(id2 - sval2); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(UIntPointData)) - { - uint sval = 0; - uint sval2 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.Double: + for (int i = 0; i < count; i++) { - var id = source.ReadUInt(offset + i * 8); - var id2 = source.ReadUInt(offset + i * 8 + 4); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - mVarintMemory.WriteInt32(id2); - isFirst = false; + var id = source.ReadDouble(offset + i * 8); + mMarshalMemory.Write(id); } else { - mVarintMemory.WriteSInt32((int)(id - sval)); - mVarintMemory.WriteSInt32((int)(id2 - sval2)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); } - } - - } - else if (typeof(T) == typeof(IntPoint3Data)) - { - int sval = 0; - int sval2 = 0; - int sval3 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); + case TagType.Float: + for (int i = 0; i < count; i++) { - var id = source.ReadInt(offset + i * 12); - var id2 = source.ReadInt(offset + i * 12 + 4); - var id3 = source.ReadInt(offset + i * 12 + 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - mVarintMemory.WriteInt32(id2); - mVarintMemory.WriteInt32(id3); - isFirst = false; + var id = source.ReadFloat(offset + i * 4); + mMarshalMemory.Write(id); } else { - mVarintMemory.WriteSInt32((int)(id - sval)); - mVarintMemory.WriteSInt32((int)(id2 - sval2)); - mVarintMemory.WriteSInt32((int)(id3 - sval3)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - sval3 = id3; - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); } - } - - } - else if (typeof(T) == typeof(UIntPoint3Data)) - { - uint sval = 0; - uint sval2 = 0; - uint sval3 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); + case TagType.IntPoint: + int psval = 0; + int psval2 = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadUInt(offset + i * 12); - var id2 = source.ReadUInt(offset + i * 12 + 4); - var id3 = source.ReadUInt(offset + i * 12 + 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt32(id); - mVarintMemory.WriteInt32(id2); - mVarintMemory.WriteInt32(id3); - isFirst = false; + var id = source.ReadInt(offset + i * 8); + var id2 = source.ReadInt(offset + i * 8 + 4); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + mVarintMemory.WriteInt32(id2); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt32(id - psval); + mVarintMemory.WriteSInt32(id2 - psval2); + } + psval = id; + psval2 = id2; } else { - mVarintMemory.WriteSInt32((int)(id - sval)); - mVarintMemory.WriteSInt32((int)(id2 - sval2)); - mVarintMemory.WriteSInt32((int)(id3 - sval3)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - sval3 = id3; } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); - } - } - - } - else if (typeof(T) == typeof(LongPointData)) - { - long sval = 0; - long sval2 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.UIntPoint: + uint upsval = 0; + uint upsval2 = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadLong(offset + i * 16); - var id2 = source.ReadLong(offset + i * 16 + 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - mVarintMemory.WriteInt64(id2); - isFirst = false; + var id = source.ReadUInt(offset + i * 8); + var id2 = source.ReadUInt(offset + i * 8 + 4); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + mVarintMemory.WriteInt32(id2); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt32((int)(id - upsval)); + mVarintMemory.WriteSInt32((int)(id2 - upsval2)); + } + upsval = id; + upsval2 = id2; } else { - mVarintMemory.WriteSInt64(id - sval); - mVarintMemory.WriteSInt64(id2 - sval2); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - } - else - { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); } - } - - } - else if (typeof(T) == typeof(ULongPointData)) - { - ulong sval = 0; - ulong sval2 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.IntPoint3: + psval = 0; + psval2 = 0; + int psval3 = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadULong(offset + i * 16); - var id2 = source.ReadULong(offset + i * 16 + 8); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - mVarintMemory.WriteInt64(id2); - isFirst = false; + var id = source.ReadInt(offset + i * 12); + var id2 = source.ReadInt(offset + i * 12 + 4); + var id3 = source.ReadInt(offset + i * 12 + 8); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + mVarintMemory.WriteInt32(id2); + mVarintMemory.WriteInt32(id3); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt32((int)(id - psval)); + mVarintMemory.WriteSInt32((int)(id2 - psval2)); + mVarintMemory.WriteSInt32((int)(id3 - psval3)); + } + psval = id; + psval2 = id2; + psval3 = id3; } else { - mVarintMemory.WriteSInt64((long)(id - sval)); - mVarintMemory.WriteSInt64((long)(id2 - sval2)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; } - else + break; + case TagType.UIntPoint3: + upsval = 0; + upsval2 = 0; + uint upsval3 = 0; + for (int i = 0; i < count; i++) { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + if (i != ig) + { + var id = source.ReadUInt(offset + i * 12); + var id2 = source.ReadUInt(offset + i * 12 + 4); + var id3 = source.ReadUInt(offset + i * 12 + 8); + if (isFirst) + { + mVarintMemory.WriteInt32(id); + mVarintMemory.WriteInt32(id2); + mVarintMemory.WriteInt32(id3); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt32((int)(id - upsval)); + mVarintMemory.WriteSInt32((int)(id2 - upsval2)); + mVarintMemory.WriteSInt32((int)(id3 - upsval3)); + } + upsval = id; + upsval2 = id2; + upsval3 = id3; + } + else + { + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + } } - } - - } - else if (typeof(T) == typeof(LongPoint3Data)) - { - long sval = 0; - long sval2 = 0; - long sval3 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.LongPoint: + long lpsval = 0; + long lpsval2 = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadLong(offset + i * 24); - var id2 = source.ReadLong(offset + i * 24 + 8); - var id3 = source.ReadLong(offset + i * 24 + 16); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - mVarintMemory.WriteInt64(id2); - mVarintMemory.WriteInt64(id3); - isFirst = false; + var id = source.ReadLong(offset + i * 16); + var id2 = source.ReadLong(offset + i * 16 + 8); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + mVarintMemory.WriteInt64(id2); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt64(id - lpsval); + mVarintMemory.WriteSInt64(id2 - lpsval2); + } + lpsval = id; + lpsval2 = id2; } else { - mVarintMemory.WriteSInt64(id - sval); - mVarintMemory.WriteSInt64(id2 - sval2); - mVarintMemory.WriteSInt64(id3 - sval3); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - sval3 = id3; } - else + break; + case TagType.ULongPoint: + ulong ulpsval = 0; + ulong ulpsval2 = 0; + for (int i = 0; i < count; i++) { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + if (i != ig) + { + var id = source.ReadULong(offset + i * 16); + var id2 = source.ReadULong(offset + i * 16 + 8); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + mVarintMemory.WriteInt64(id2); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt64((long)(id - ulpsval)); + mVarintMemory.WriteSInt64((long)(id2 - ulpsval2)); + } + ulpsval = id; + ulpsval2 = id2; + } + else + { + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + } } - } - - } - else if (typeof(T) == typeof(ULongPoint3Data)) - { - ulong sval = 0; - ulong sval2 = 0; - ulong sval3 = 0; - for (int i = 0; i < count; i++) - { - if (i != ig) + break; + case TagType.LongPoint3: + lpsval = 0; + lpsval2 = 0; + long lpsval3 = 0; + for (int i = 0; i < count; i++) { - var id = source.ReadULong(offset + i * 24); - var id2 = source.ReadULong(offset + i * 24 + 8); - var id3 = source.ReadULong(offset + i * 24 + 16); - if (isFirst) + if (i != ig) { - mVarintMemory.WriteInt64(id); - mVarintMemory.WriteInt64(id2); - mVarintMemory.WriteInt64(id3); - isFirst = false; + var id = source.ReadLong(offset + i * 24); + var id2 = source.ReadLong(offset + i * 24 + 8); + var id3 = source.ReadLong(offset + i * 24 + 16); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + mVarintMemory.WriteInt64(id2); + mVarintMemory.WriteInt64(id3); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt64(id - lpsval); + mVarintMemory.WriteSInt64(id2 - lpsval2); + mVarintMemory.WriteSInt64(id3 - lpsval3); + } + lpsval = id; + lpsval2 = id2; + lpsval3 = id3; } else { - mVarintMemory.WriteSInt64((long)(id - sval)); - mVarintMemory.WriteSInt64((long)(id2 - sval2)); - mVarintMemory.WriteSInt64((long)(id3 - sval3)); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } - sval = id; - sval2 = id2; - sval3 = id3; } - else + break; + case TagType.ULongPoint3: + ulpsval = 0; + ulpsval2 = 0; + ulong ulpsval3 = 0; + for (int i = 0; i < count; i++) { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + if (i != ig) + { + var id = source.ReadULong(offset + i * 24); + var id2 = source.ReadULong(offset + i * 24 + 8); + var id3 = source.ReadULong(offset + i * 24 + 16); + if (isFirst) + { + mVarintMemory.WriteInt64(id); + mVarintMemory.WriteInt64(id2); + mVarintMemory.WriteInt64(id3); + isFirst = false; + } + else + { + mVarintMemory.WriteSInt64((long)(id - ulpsval)); + mVarintMemory.WriteSInt64((long)(id2 - ulpsval2)); + mVarintMemory.WriteSInt64((long)(id3 - ulpsval3)); + } + ulpsval = id; + ulpsval2 = id2; + ulpsval3 = id3; + } + else + { + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + } } - } - + break; + default: + break; } - return mVarintMemory.Buffer.AsMemory(0, (int)mVarintMemory.Position); } @@ -656,11 +647,11 @@ namespace Cdy.Tag /// /// /// - protected Memory CompressValues(List timerVals, Queue emptyIds) + protected Memory CompressValues(List timerVals, CustomQueue emptyIds) { mMarshalMemory.Position = 0; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; for (int i = 0; i < timerVals.Count; i++) { if(i != ig) @@ -670,8 +661,7 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); @@ -687,14 +677,15 @@ namespace Cdy.Tag /// /// /// - protected Memory CompressQulitys(MarshalMemoryBlock source, long offset, int totalcount, Queue emptyIds) + protected Memory CompressQulitys(MarshalMemoryBlock source, long offset, int totalcount, CustomQueue emptyIds) { int count = 1; byte qus = source.ReadByte(offset); //using (VarintCodeMemory memory = new VarintCodeMemory(qulitys.Length * 2)) mVarintMemory.Position = 0; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + //emptyIds.TryDequeue(out ig); mVarintMemory.WriteInt32(qus); for (int i = 1; i < totalcount; i++) { @@ -715,8 +706,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + // emptyIds.TryDequeue(out ig); } } mVarintMemory.WriteInt32(count); @@ -729,14 +720,14 @@ namespace Cdy.Tag /// /// /// - protected Memory CompressQulitys(byte[] qulitys, Queue emptyIds) + protected Memory CompressQulitys(byte[] qulitys, CustomQueue emptyIds) { int count = 1; byte qus = qulitys[0]; //using (VarintCodeMemory memory = new VarintCodeMemory(qulitys.Length * 2)) mVarintMemory.Position = 0; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; mVarintMemory.WriteInt32(qus); for (int i = 1; i < qulitys.Length; i++) { @@ -756,8 +747,7 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; } } mVarintMemory.WriteInt32(count); @@ -769,13 +759,14 @@ namespace Cdy.Tag /// /// /// - protected Memory CompressBoolValues(MarshalMemoryBlock source, long offset, int totalcount, Queue emptyIds) + protected Memory CompressBoolValues(MarshalMemoryBlock source, long offset, int totalcount, CustomQueue emptyIds) { List re = new List(totalcount); byte bval = source.ReadByte(offset); short scount = 1; int ig = -1; - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + //emptyIds.TryDequeue(out ig); short sval = (short)(bval << 15); for(int i=0;i< totalcount; i++) @@ -798,8 +789,8 @@ namespace Cdy.Tag } else { - if (emptyIds.Count > 0) - emptyIds.TryDequeue(out ig); + ig = emptys.Index >= 0 ? emptys.Remove() : -1; + // emptyIds.TryDequeue(out ig); } } sval = (short)(sval | scount); @@ -813,6 +804,8 @@ namespace Cdy.Tag return mMarshalMemory.StartMemory.AsMemory(0, (int)mMarshalMemory.Position); } + CustomQueue emptys = new CustomQueue(604); + /// /// /// @@ -821,10 +814,10 @@ namespace Cdy.Tag /// /// /// - protected virtual long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size) + protected virtual long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size, TagType type) { var count = (int)(size - this.QulityOffset); - var tims = source.ReadUShorts(sourceAddr, (int)count); + //var tims = source.ReadUShorts(sourceAddr, (int)count); if(mMarshalMemory==null) { @@ -836,14 +829,14 @@ namespace Cdy.Tag mVarintMemory = new VarintCodeMemory(count * 10); } - Queue emptys = new Queue(); - var datas = CompressTimers(tims, emptys); - - var emptys2 = new Queue(emptys); + //Queue emptys = new Queue(); + //var datas = CompressTimers(tims, emptys); + var datas = CompressTimers(source, sourceAddr, (int)count, emptys); + //var emptys2 = new Queue(emptys); long rsize = 0; //byte[] qus = null; - int rcount = count - emptys.Count; + int rcount = count - emptys.Index; target.WriteUShort(targetAddr,(ushort)rcount); rsize += 2; @@ -851,208 +844,271 @@ namespace Cdy.Tag target.Write(datas); rsize += 4; rsize += datas.Length; - - if (typeof(T) == typeof(bool)) - { - //var vals = source.ReadBytes(count * 2 + sourceAddr, (int)count); - var cval = CompressBoolValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(cval.Length); - target.Write(cval); - rsize += 4; - rsize += cval.Length; - - var cqus = CompressQulitys(source, count * 3 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(byte)) - { - //var vals = source.ReadBytes(count * 2 + sourceAddr, (int)count); - // qus = source.ReadBytes(count * 3 + sourceAddr, (int)count); - - var cval = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(cval.Length); - target.Write(cval); - rsize += 4; - rsize += cval.Length; - - var cqus = CompressQulitys(source, count * 3 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(short)) - { - //var vals = source.ReadShorts(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 4 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 4 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(ushort)) - { - //var vals = source.ReadUShorts(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 4 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 4 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(int)) - { - //var vals = source.ReadInts(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 6 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(uint)) - { - //var vals = source.ReadUInts(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 6 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(long)) - { - //var vals = source.ReadLongs(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 10 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(ulong)) - { - //var vals = source.ReadULongs(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 10 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(DateTime)) - { - //var vals = source.ReadULongs(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 10 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(double)) - { - //var vals = source.ReadDoubles(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 10 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(float)) - { - //var vals = source.ReadFloats(count * 2 + sourceAddr, (int)count); - //qus = source.ReadBytes(count * 6 + sourceAddr, (int)count); - - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(string)) + int idx = emptys.Index; + switch (TagType) { - - var vals = source.ReadStrings(count * 2 + sourceAddr, count); - var qus = source.ReadBytes(count); - var res = CompressValues(vals, emptys); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - var cqus = CompressQulitys(qus, emptys2); - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; + case TagType.Bool: + var cval = CompressBoolValues(source, count * 2 + sourceAddr, count, emptys); + target.Write(cval.Length); + target.Write(cval); + rsize += 4; + rsize += cval.Length; + emptys.Index = idx; + var cqus = CompressQulitys(source, count * 3 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Byte: + cval = CompressValues(source, count * 2 + sourceAddr, count, emptys,TagType); + target.Write(cval.Length); + target.Write(cval); + rsize += 4; + rsize += cval.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 3 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UShort: + var ures = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ures.Length); + target.Write(ures); + rsize += 4; + rsize += ures.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 4 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Short: + var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(res.Length); + target.Write(res); + rsize += 4; + rsize += res.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 4 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UInt: + var uires = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(uires.Length); + target.Write(uires); + rsize += 4; + rsize += uires.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Int: + var ires = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ires.Length); + target.Write(ires); + rsize += 4; + rsize += ires.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.ULong: + var ulres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ulres.Length); + target.Write(ulres); + rsize += 4; + rsize += ulres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Long: + var lres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(lres.Length); + target.Write(lres); + rsize += 4; + rsize += lres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.DateTime: + var dres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(dres.Length); + target.Write(dres); + rsize += 4; + rsize += dres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Double: + var ddres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ddres.Length); + target.Write(ddres); + rsize += 4; + rsize += ddres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Float: + var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(fres.Length); + target.Write(fres); + rsize += 4; + rsize += fres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.String: + var vals = source.ReadStrings(count * 2 + sourceAddr, count); + var qus = source.ReadBytes(count); + var sres = CompressValues(vals, emptys); + target.Write(sres.Length); + target.Write(sres); + rsize += 4; + rsize += sres.Length; + emptys.Index = idx; + cqus = CompressQulitys(qus, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.IntPoint: + var ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UIntPoint: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.LongPoint: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 18 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.ULongPoint: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 18 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.IntPoint3: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 14 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UIntPoint3: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 14 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.LongPoint3: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 26 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.ULongPoint3: + ipres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); + target.Write(ipres.Length); + target.Write(ipres); + rsize += 4; + rsize += ipres.Length; + emptys.Index = idx; + cqus = CompressQulitys(source, count * 26 + sourceAddr, count, emptys); + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; } return rsize; } diff --git a/RunTime/DBRuntime/His/Compress/Special/NoneCompressUnit.cs b/RunTime/DBRuntime/His/Compress/Special/NoneCompressUnit.cs index 93cb194ce58d4f719c0310af07d6821614e3684b..d13f6b6b9e663609788f9c04a3eb8acc9132b02c 100644 --- a/RunTime/DBRuntime/His/Compress/Special/NoneCompressUnit.cs +++ b/RunTime/DBRuntime/His/Compress/Special/NoneCompressUnit.cs @@ -851,53 +851,16 @@ namespace Cdy.Tag /// public bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - - var valaddr = qs.Count * 2+10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressBoolValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadByte(valaddr + i)>0; - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadByte(valaddr + i) > 0; - case QueryValueMatchType.After: - return source.ReadByte(valaddr + i+1) > 0; - case QueryValueMatchType.Linear: - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadByte(valaddr + i) > 0; - } - else - { - return source.ReadByte(valaddr + i + 1) > 0; - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadByte(valaddr + i+1) > 0; - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// @@ -922,17 +885,35 @@ namespace Cdy.Tag var valaddr = qs.Count * 2+10 + sourceAddr; int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; + + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; if (time1 == skey.Value.Item1) { - var val = source.ReadByte(valaddr + i) > 0; + var val = source.ReadByte(valaddr + icount) > 0; result.Add(val, time1, qq[skey.Key]); count++; break; @@ -943,13 +924,13 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadByte(valaddr + i) > 0; + var val = source.ReadByte(valaddr + icount) > 0; result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadByte(valaddr + i+1) > 0; + val = source.ReadByte(valaddr + icount1) > 0; result.Add(val, time1, qq[snext.Key]); count++; break; @@ -961,13 +942,13 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadByte(valaddr + i) > 0; + val = source.ReadByte(valaddr + icount) > 0; result.Add(val, time1, qq[skey.Key]); break; } else { - val = source.ReadByte(valaddr + i + 1) > 0; + val = source.ReadByte(valaddr + icount1) > 0; result.Add(val, time1, qq[snext.Key]); break; } @@ -977,7 +958,7 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadByte(valaddr + i + 1) > 0; + var val = source.ReadByte(valaddr + icount1) > 0; result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1000,53 +981,16 @@ namespace Cdy.Tag /// public byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - - var valaddr = qs.Count * 2+10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressByteValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadByte(valaddr + i); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadByte(valaddr + i); - case QueryValueMatchType.After: - return source.ReadByte(valaddr + i + 1); - case QueryValueMatchType.Linear: - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadByte(valaddr + i); - } - else - { - return source.ReadByte(valaddr + i + 1); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadByte(valaddr + i + 1); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// /// @@ -1070,17 +1014,36 @@ namespace Cdy.Tag var valaddr = qs.Count * 2+10 + sourceAddr; int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + //for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; + + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; if (time1 == skey.Value.Item1) { - var val = source.ReadByte(valaddr + i); + var val = source.ReadByte(valaddr + icount); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -1091,13 +1054,13 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadByte(valaddr + i); + var val = source.ReadByte(valaddr + icount); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadByte(valaddr + i + 1); + val = source.ReadByte(valaddr + icount1); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1109,13 +1072,13 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadByte(valaddr + i); + val = source.ReadByte(valaddr + icount); result.Add(val, time1, qq[skey.Key]); break; } else { - val = source.ReadByte(valaddr + i + 1); + val = source.ReadByte(valaddr + icount1); result.Add(val, time1, qq[snext.Key]); break; } @@ -1125,7 +1088,7 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadByte(valaddr + i + 1); + var val = source.ReadByte(valaddr + icount1); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1147,53 +1110,16 @@ namespace Cdy.Tag /// public DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - - var valaddr = qs.Count * 2+10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressDateTimeValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadDateTime(valaddr + i*8); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadDateTime(valaddr + i*8); - case QueryValueMatchType.After: - return source.ReadDateTime(valaddr + (i + 1) * 8); - case QueryValueMatchType.Linear: - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadDateTime(valaddr + i*8); - } - else - { - return source.ReadDateTime(valaddr + (i + 1) * 8); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadDateTime(valaddr + (i + 1) * 8); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// /// @@ -1217,17 +1143,36 @@ namespace Cdy.Tag var valaddr = qs.Count * 2+10 + sourceAddr; int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + // for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; + + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; if (time1 == skey.Value.Item1) { - var val = source.ReadDateTime(valaddr + i*8); + var val = source.ReadDateTime(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -1238,13 +1183,13 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadDateTime(valaddr + i * 8); + var val = source.ReadDateTime(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadDateTime(valaddr + (i + 1)*8); + val = source.ReadDateTime(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1256,13 +1201,13 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadDateTime(valaddr + i * 8); + val = source.ReadDateTime(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); break; } else { - val = source.ReadDateTime(valaddr + (i + 1) * 8); + val = source.ReadDateTime(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); break; } @@ -1272,7 +1217,7 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadDateTime(valaddr + (i + 1) * 8); + var val = source.ReadDateTime(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1295,75 +1240,16 @@ namespace Cdy.Tag /// public double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 10+10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2+10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressDoubleValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadDouble(valaddr + i*8); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadDouble(valaddr + i * 8); - case QueryValueMatchType.After: - return source.ReadDouble(valaddr + (i + 1)*8); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadDouble(valaddr + i * 8); - var sval2 = source.ReadDouble(valaddr + (i + 1) * 8); - return (double)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadDouble(valaddr + i * 8); - } - else if (qq[snext.Key] < 20) - { - return source.ReadDouble(valaddr + (i + 1) * 8); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadDouble(valaddr + i * 8); - } - else - { - return source.ReadDouble(valaddr + (i + 1) * 8); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadDouble(valaddr + (i + 1) * 8); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; - - } /// @@ -1501,73 +1387,16 @@ namespace Cdy.Tag public float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 6 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressFloatValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if(count>0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadFloat(valaddr + i*4); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadFloat(valaddr + i * 4); - case QueryValueMatchType.After: - return source.ReadFloat(valaddr + (i + 1)*4); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadFloat(valaddr + i * 4); - var sval2 = source.ReadFloat(valaddr + (i + 1) * 4); - return (float)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadFloat(valaddr + i * 4); - } - else if (qq[snext.Key] < 20) - { - return source.ReadFloat(valaddr + (i + 1) * 4); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadFloat(valaddr + i * 4); - } - else - { - return source.ReadFloat(valaddr + (i + 1) * 4); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadFloat(valaddr + (i + 1) * 4); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// @@ -1592,17 +1421,35 @@ namespace Cdy.Tag var valaddr = qs.Count * 2 + 10 + sourceAddr; int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = source.ReadFloat(valaddr + i*4); + var val = source.ReadFloat(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -1613,12 +1460,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadFloat(valaddr + i * 4); + var val = source.ReadFloat(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadFloat(valaddr + (i + 1) * 4); + val = source.ReadFloat(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1627,19 +1474,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadFloat(valaddr + i * 4); - var sval2 = source.ReadFloat(valaddr + (i + 1) * 4); + var sval1 = source.ReadFloat(valaddr + icount * 4); + var sval2 = source.ReadFloat(valaddr + icount1 * 4); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; result.Add((float)val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadFloat(valaddr + i * 4); + val = source.ReadFloat(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadFloat(valaddr + (i + 1) * 4); + val = source.ReadFloat(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } else @@ -1654,12 +1501,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadFloat(valaddr + i * 4); + val = source.ReadFloat(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadFloat(valaddr + (i + 1) * 4); + val = source.ReadFloat(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } count++; @@ -1670,95 +1517,124 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadFloat(valaddr + (i + 1) * 4); + var val = source.ReadFloat(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } - return count; - } + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; - /// - /// - /// - /// - /// - /// - /// + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadFloat(valaddr + i*4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadFloat(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadFloat(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadFloat(valaddr + i * 4); + // var sval2 = source.ReadFloat(valaddr + (i + 1) * 4); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((float)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadFloat(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadFloat(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadFloat(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadFloat(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadFloat(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + return count; + } + + /// + /// + /// + /// + /// + /// + /// /// /// public int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 6 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressIntValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadInt(valaddr + i * 4); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadInt(valaddr + i * 4); - case QueryValueMatchType.After: - return source.ReadInt(valaddr + (i + 1) * 4); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadInt(valaddr + i * 4); - var sval2 = source.ReadInt(valaddr + (i + 1) * 4); - return (int)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadInt(valaddr + i * 4); - } - else if (qq[snext.Key] < 20) - { - return source.ReadInt(valaddr + (i + 1) * 4); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadInt(valaddr + i*4); - } - else - { - return source.ReadInt(valaddr + (i + 1) * 4); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadInt(valaddr + (i + 1) * 4); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// @@ -1781,19 +1657,36 @@ namespace Cdy.Tag var vv = qs.ToArray(); var valaddr = qs.Count * 2 + 10 + sourceAddr; - int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) { - var val = source.ReadInt(valaddr + i*4); + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) + { + var val = source.ReadInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -1804,12 +1697,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadInt(valaddr + i * 4); + var val = source.ReadInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadInt(valaddr + (i + 1) * 4); + val = source.ReadInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -1818,19 +1711,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadInt(valaddr + i * 4); - var sval2 = source.ReadInt(valaddr + (i + 1) * 4); + var sval1 = source.ReadInt(valaddr + icount * 4); + var sval2 = source.ReadInt(valaddr + icount1 * 4); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; result.Add((int)val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadInt(valaddr + i * 4); + val = source.ReadInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadInt(valaddr + (i + 1) * 4); + val = source.ReadInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } else @@ -1845,12 +1738,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadInt(valaddr + i * 4); + val = source.ReadInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadInt(valaddr + (i + 1) * 4); + val = source.ReadInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } count++; @@ -1861,14 +1754,101 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadInt(valaddr + (i + 1) * 4); + var val = source.ReadInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadInt(valaddr + i*4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadInt(valaddr + i * 4); + // var sval2 = source.ReadInt(valaddr + (i + 1) * 4); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((int)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} return count; } @@ -1883,73 +1863,16 @@ namespace Cdy.Tag /// public long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 10 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressLongValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadLong(valaddr + i*8); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadLong(valaddr + i * 8); - case QueryValueMatchType.After: - return source.ReadLong(valaddr + (i + 1)*8); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadLong(valaddr + i * 8); - var sval2 = source.ReadLong(valaddr + (i + 1) * 8); - return (long)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadLong(valaddr + i * 8); - } - else if (qq[snext.Key] < 20) - { - return source.ReadLong(valaddr + (i + 1) * 8); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadLong(valaddr + i * 8); - } - else - { - return source.ReadLong(valaddr + (i + 1) * 8); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadLong(valaddr + (i + 1) * 8); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// @@ -1974,17 +1897,36 @@ namespace Cdy.Tag var valaddr = qs.Count * 2 + 10 + sourceAddr; int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + //for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) { - var val = source.ReadLong(valaddr + i*8); + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) + { + var val = source.ReadLong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -1995,12 +1937,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadLong(valaddr + i * 8); + var val = source.ReadLong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadLong(valaddr + (i + 1) * 8); + val = source.ReadLong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2009,19 +1951,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadLong(valaddr + i * 8); - var sval2 = source.ReadLong(valaddr + (i + 1) * 8); + var sval1 = source.ReadLong(valaddr + icount * 8); + var sval2 = source.ReadLong(valaddr + icount1 * 8); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; - result.Add((long)val1, time1, 0); + result.Add(val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadLong(valaddr + i * 8); + val = source.ReadLong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadLong(valaddr + (i + 1) * 8); + val = source.ReadLong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); } else @@ -2036,12 +1978,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadLong(valaddr + i * 8); + val = source.ReadLong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadLong(valaddr + (i + 1) * 8); + val = source.ReadLong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); } count++; @@ -2052,16 +1994,105 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadLong(valaddr + (i + 1) * 8); + var val = source.ReadLong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadLong(valaddr + i*8); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadLong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadLong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadLong(valaddr + i * 8); + // var sval2 = source.ReadLong(valaddr + (i + 1) * 8); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((long)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadLong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadLong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadLong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadLong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadLong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + //return count; + } @@ -2076,73 +2107,16 @@ namespace Cdy.Tag /// public short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 4 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressShortValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadShort(valaddr + i*2); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadShort(valaddr + i * 2); - case QueryValueMatchType.After: - return source.ReadShort(valaddr + (i + 1)*2); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadShort(valaddr + i * 2); - var sval2 = source.ReadShort(valaddr + (i + 1) * 2); - return (short)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadShort(valaddr + i * 2); - } - else if (qq[snext.Key] < 20) - { - return source.ReadShort(valaddr + (i + 1) * 2); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadShort(valaddr + i * 2); - } - else - { - return source.ReadShort(valaddr + (i + 1) * 2); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadShort(valaddr + (i + 1) * 2); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; } /// @@ -2166,19 +2140,37 @@ namespace Cdy.Tag var vv = qs.ToArray(); var valaddr = qs.Count * 2 + 10 + sourceAddr; - int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + //for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = source.ReadShort(valaddr + i*2); + var val = source.ReadShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -2189,12 +2181,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadShort(valaddr + i * 2); + var val = source.ReadShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadShort(valaddr + (i + 1) * 2); + val = source.ReadShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2203,19 +2195,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadShort(valaddr + i * 2); - var sval2 = source.ReadShort(valaddr + (i + 1) * 2); + var sval1 = source.ReadShort(valaddr + icount * 2); + var sval2 = source.ReadShort(valaddr + icount1 * 2); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; - result.Add((short)val1, time1, 0); + result.Add(val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadShort(valaddr + i * 2); + val = source.ReadShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadShort(valaddr + (i + 1) * 2); + val = source.ReadShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); } else @@ -2230,12 +2222,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadShort(valaddr + i * 2); + val = source.ReadShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadShort(valaddr + (i + 1) * 2); + val = source.ReadShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); } count++; @@ -2246,17 +2238,105 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadShort(valaddr + (i + 1) * 2); + var val = source.ReadShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadShort(valaddr + i*2); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadShort(valaddr + i * 2); + // var sval2 = source.ReadShort(valaddr + (i + 1) * 2); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((short)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + //return count; + - } /// @@ -2270,60 +2350,16 @@ namespace Cdy.Tag /// public string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - - var valaddr = qs.Count * 2 + sourceAddr; - Dictionary dtmp = new Dictionary(); - source.Position = valaddr; - - for (int i = 0; i < qs.Count; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressStringValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - dtmp.Add(i, source.ReadString()); + return re.GetValue(0); } - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + else { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return dtmp[i]; - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return dtmp[i]; - case QueryValueMatchType.After: - return dtmp[i + 1]; - case QueryValueMatchType.Linear: - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return dtmp[i]; - } - else - { - return dtmp[i + 1]; - } - } - } - else if (time == snext.Value.Item1) - { - return dtmp[i + 1]; - } - + return null; } - return string.Empty; } /// @@ -2358,32 +2394,54 @@ namespace Cdy.Tag var vv = qs.ToArray(); int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + //for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = dtmp[i]; + var val = dtmp[icount]; + // var val = source.ReadShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); count++; break; } else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) { + switch (type) { case QueryValueMatchType.Previous: - var val = dtmp[i]; + var val = dtmp[icount]; + result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = dtmp[i + 1]; + val = dtmp[icount1]; result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2394,31 +2452,93 @@ namespace Cdy.Tag if (pval < fval) { - val = dtmp[i]; + val = dtmp[icount]; result.Add(val, time1, qq[skey.Key]); - break; } else { - val = dtmp[i + 1]; + val = dtmp[icount1]; result.Add(val, time1, qq[snext.Key]); - break; } + count++; + break; } - count++; + break; } else if (time1 == snext.Value.Item1) { - var val = dtmp[i]; + var val = dtmp[icount1]; result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = dtmp[i]; + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = dtmp[i]; + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = dtmp[i + 1]; + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = dtmp[i]; + // result.Add(val, time1, qq[skey.Key]); + // break; + // } + // else + // { + // val = dtmp[i + 1]; + // result.Add(val, time1, qq[snext.Key]); + // break; + // } + // } + // count++; + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = dtmp[i]; + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + //return count; } @@ -2433,74 +2553,17 @@ namespace Cdy.Tag /// public uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 6 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressUIntValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadUInt(valaddr + i*4); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadUInt(valaddr + i * 4); - case QueryValueMatchType.After: - return source.ReadUInt(valaddr + (i + 1)*4); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadUInt(valaddr + i * 4); - var sval2 = source.ReadUInt(valaddr + (i + 1) * 4); - return (uint)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadUInt(valaddr + i * 4); - } - else if (qq[snext.Key] < 20) - { - return source.ReadUInt(valaddr + (i + 1) * 4); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadUInt(valaddr + i * 4); - } - else - { - return source.ReadUInt(valaddr + (i + 1) * 4); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadUInt(valaddr + (i + 1) * 4); - } - + return re.GetValue(0); } - return null; - + else + { + return null; + } + } /// @@ -2523,19 +2586,36 @@ namespace Cdy.Tag var vv = qs.ToArray(); var valaddr = qs.Count * 2 + 10 + sourceAddr; - int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = source.ReadUInt(valaddr + i*4); + var val = source.ReadUInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -2546,12 +2626,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadUInt(valaddr + i * 4); + var val = source.ReadUInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadUInt(valaddr + (i + 1) * 4); + val = source.ReadUInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2560,19 +2640,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadUInt(valaddr + i * 4); - var sval2 = source.ReadUInt(valaddr + (i + 1) * 4); + var sval1 = source.ReadUInt(valaddr + icount * 4); + var sval2 = source.ReadUInt(valaddr + icount1 * 4); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; result.Add((uint)val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadUInt(valaddr + i * 4); + val = source.ReadUInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadUInt(valaddr + (i + 1) * 4); + val = source.ReadUInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } else @@ -2587,12 +2667,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadUInt(valaddr + i * 4); + val = source.ReadUInt(valaddr + icount * 4); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadUInt(valaddr + (i + 1) * 4); + val = source.ReadUInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); } count++; @@ -2603,15 +2683,103 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadUInt(valaddr + (i + 1) * 4); + var val = source.ReadUInt(valaddr + icount1 * 4); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadUInt(valaddr + i*4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadUInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadUInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadUInt(valaddr + i * 4); + // var sval2 = source.ReadUInt(valaddr + (i + 1) * 4); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((uint)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadUInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadUInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadUInt(valaddr + i * 4); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadUInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadUInt(valaddr + (i + 1) * 4); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + //return count; } /// @@ -2625,75 +2793,18 @@ namespace Cdy.Tag /// public ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 10 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressULongValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadULong(valaddr + i*8); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadULong(valaddr + i*8); - case QueryValueMatchType.After: - return source.ReadULong(valaddr + (i + 1)*8); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadULong(valaddr + i * 8); - var sval2 = source.ReadULong(valaddr + (i + 1) * 8); - return (ulong)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadULong(valaddr + i * 8); - } - else if (qq[snext.Key] < 20) - { - return source.ReadULong(valaddr + (i + 1) * 8); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadULong(valaddr + i * 8); - } - else - { - return source.ReadULong(valaddr + (i + 1) * 8); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadULong(valaddr + (i + 1) * 8); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; - + } /// @@ -2716,19 +2827,37 @@ namespace Cdy.Tag var vv = qs.ToArray(); var valaddr = qs.Count * 2 + 10 + sourceAddr; - int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + //for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = source.ReadULong(valaddr + i * 8); + var val = source.ReadULong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -2739,12 +2868,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadULong(valaddr + i * 8); + var val = source.ReadULong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadULong(valaddr + (i + 1) * 8); + val = source.ReadULong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2753,19 +2882,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadULong(valaddr + i * 8); - var sval2 = source.ReadULong(valaddr + (i + 1) * 8); + var sval1 = source.ReadULong(valaddr + icount * 8); + var sval2 = source.ReadULong(valaddr + icount1 * 8); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; - result.Add((ulong)val1, time1, 0); + result.Add(val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadULong(valaddr + i * 8); + val = source.ReadULong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadULong(valaddr + (i + 1) * 8); + val = source.ReadULong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); } else @@ -2780,12 +2909,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadULong(valaddr + i * 8); + val = source.ReadULong(valaddr + icount * 8); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadULong(valaddr + (i + 1) * 8); + val = source.ReadULong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); } count++; @@ -2796,14 +2925,102 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadULong(valaddr + (i + 1) * 8); + var val = source.ReadULong(valaddr + icount1 * 8); result.Add(val, time1, qq[snext.Key]); count++; break; } + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadULong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadULong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadULong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadULong(valaddr + i * 8); + // var sval2 = source.ReadULong(valaddr + (i + 1) * 8); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((ulong)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadULong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadULong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadULong(valaddr + i * 8); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadULong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadULong(valaddr + (i + 1) * 8); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + // } + //} + //return count; } /// @@ -2817,75 +3034,18 @@ namespace Cdy.Tag /// public ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { - DateTime time1; - int valuecount = 0; - var qs = ReadTimeQulity(source, sourceAddr, timeTick, out valuecount, out time1); - var qq = source.ReadBytes(qs.Count * 4 + 10 + sourceAddr, qs.Count); - - var valaddr = qs.Count * 2 + 10 + sourceAddr; - - var vv = qs.ToArray(); - - for (int i = 0; i < vv.Length - 1; i++) + HisQueryResult re = new HisQueryResult(1); + var count = DeCompressUShortValue(source, sourceAddr, new List() { time }, timeTick, type, re); + if (count > 0) { - var skey = vv[i]; - - var snext = vv[i + 1]; - - if (time == skey.Value.Item1) - { - return source.ReadUShort(valaddr + i); - } - else if (time > skey.Value.Item1 && time < snext.Value.Item1) - { - switch (type) - { - case QueryValueMatchType.Previous: - return source.ReadUShort(valaddr + i*2); - case QueryValueMatchType.After: - return source.ReadUShort(valaddr + (i + 1)*2); - case QueryValueMatchType.Linear: - - if (qq[skey.Key] < 20 && qq[snext.Key] < 20) - { - var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; - var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadUShort(valaddr + i * 2); - var sval2 = source.ReadUShort(valaddr + (i + 1) * 2); - return (ushort)(pval1 / tval1 * (sval2 - sval1) + sval1); - } - else if (qq[skey.Key] < 20) - { - return source.ReadUShort(valaddr + i * 2); - } - else if (qq[snext.Key] < 20) - { - return source.ReadUShort(valaddr + (i + 1) * 2); - } - break; - - case QueryValueMatchType.Closed: - var pval = (time - skey.Value.Item1).TotalMilliseconds; - var fval = (snext.Value.Item1 - time).TotalMilliseconds; - if (pval < fval) - { - return source.ReadUShort(valaddr + i * 2); - } - else - { - return source.ReadUShort(valaddr + (i + 1) * 2); - } - } - } - else if (time == snext.Value.Item1) - { - return source.ReadUShort(valaddr + (i + 1) * 2); - } - + return re.GetValue(0); + } + else + { + return null; } - return null; - + } /// @@ -2908,19 +3068,36 @@ namespace Cdy.Tag var vv = qs.ToArray(); var valaddr = qs.Count * 2 + 10 + sourceAddr; - int count = 0; + int icount = 0; + int icount1 = 0; foreach (var time1 in time) { - for (int i = 0; i < vv.Length - 1; i++) + while (icount < vv.Length - 1) { - var skey = vv[i]; + while (!vv[icount].Value.Item2) + { + icount++; + if (icount > (vv.Length - 1)) + return count; + } - var snext = vv[i + 1]; + var skey = vv[icount]; - if (time1 == skey.Value.Item1) + icount1 = icount + 1; + + while (!vv[icount1].Value.Item2) + { + icount1++; + if (icount1 > (vv.Length)) + return count; + } + + var snext = vv[icount1]; + + if (time1 <= skey.Value.Item1) { - var val = source.ReadUShort(valaddr + i * 2); + var val = source.ReadUShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); count++; break; @@ -2931,12 +3108,12 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - var val = source.ReadUShort(valaddr + i * 2); + var val = source.ReadUShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); count++; break; case QueryValueMatchType.After: - val = source.ReadUShort(valaddr + (i + 1) * 2); + val = source.ReadUShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); count++; break; @@ -2945,19 +3122,19 @@ namespace Cdy.Tag { var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; - var sval1 = source.ReadUShort(valaddr + i * 2); - var sval2 = source.ReadUShort(valaddr + (i + 1) * 2); + var sval1 = source.ReadUShort(valaddr + icount * 2); + var sval2 = source.ReadUShort(valaddr + icount1 * 2); var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; - result.Add((ushort)val1, time1, 0); + result.Add(val1, time1, 0); } else if (qq[skey.Key] < 20) { - val = source.ReadUShort(valaddr + i * 2); + val = source.ReadUShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); } else if (qq[snext.Key] < 20) { - val = source.ReadUShort(valaddr + (i + 1) * 2); + val = source.ReadUShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); } else @@ -2972,12 +3149,12 @@ namespace Cdy.Tag if (pval < fval) { - val = source.ReadUShort(valaddr + i * 2); + val = source.ReadUShort(valaddr + icount * 2); result.Add(val, time1, qq[skey.Key]); } else { - val = source.ReadUShort(valaddr + (i + 1) * 2); + val = source.ReadUShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); } count++; @@ -2988,15 +3165,103 @@ namespace Cdy.Tag } else if (time1 == snext.Value.Item1) { - var val = source.ReadUShort(valaddr + (i + 1) * 2); + var val = source.ReadUShort(valaddr + icount1 * 2); result.Add(val, time1, qq[snext.Key]); count++; break; } - + icount = icount1; } } return count; + //int count = 0; + //foreach (var time1 in time) + //{ + // for (int i = 0; i < vv.Length - 1; i++) + // { + // var skey = vv[i]; + + // var snext = vv[i + 1]; + + // if (time1 == skey.Value.Item1) + // { + // var val = source.ReadUShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // } + // else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + // { + + // switch (type) + // { + // case QueryValueMatchType.Previous: + // var val = source.ReadUShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // count++; + // break; + // case QueryValueMatchType.After: + // val = source.ReadUShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // case QueryValueMatchType.Linear: + // if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + // { + // var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + // var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + // var sval1 = source.ReadUShort(valaddr + i * 2); + // var sval2 = source.ReadUShort(valaddr + (i + 1) * 2); + // var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + // result.Add((ushort)val1, time1, 0); + // } + // else if (qq[skey.Key] < 20) + // { + // val = source.ReadUShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // } + // else if (qq[snext.Key] < 20) + // { + // val = source.ReadUShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // } + // else + // { + // result.Add(0, time1, (byte)QualityConst.Null); + // } + // count++; + // break; + // case QueryValueMatchType.Closed: + // var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + // var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + // if (pval < fval) + // { + // val = source.ReadUShort(valaddr + i * 2); + // result.Add(val, time1, qq[skey.Key]); + // } + // else + // { + // val = source.ReadUShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // } + // count++; + // break; + // } + + // break; + // } + // else if (time1 == snext.Value.Item1) + // { + // var val = source.ReadUShort(valaddr + (i + 1) * 2); + // result.Add(val, time1, qq[snext.Key]); + // count++; + // break; + // } + + // } + //} + //return count; } /// diff --git a/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit.cs b/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit.cs index dfd765b869098e9e463f67bba51dfcd2157dca4e..b85334968b77f733b8e431282a0d078c97f4c861 100644 --- a/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit.cs +++ b/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit.cs @@ -822,7 +822,7 @@ namespace Cdy.Tag /// /// /// - protected override long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size) + protected override long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size, TagType type) { var count = (int)(size - this.QulityOffset); var tims = source.ReadUShorts(sourceAddr, (int)count); @@ -842,243 +842,237 @@ namespace Cdy.Tag long rsize = 0; - - if (typeof(T) == typeof(byte)) - { - var cval = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims,out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 3 + sourceAddr, count, new Queue(usedIndex)); - var timeData = CompressTimers(tims, usedIndex); - - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(cval.Length); - target.Write(cval); - rsize += 4; - rsize += cval.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(short)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 4 + sourceAddr, count,new Queue(usedIndex)); - var timeData = CompressTimers(tims, usedIndex); - - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(ushort)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 4 + sourceAddr, count, new Queue(usedIndex)); - var timeData = CompressTimers(tims, usedIndex); - - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(int)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); - var timeData = CompressTimers(tims, usedIndex); - - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(uint)) + switch (TagType) { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; + case TagType.Byte: + var cval = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + var cqus = CompressQulitys(source, count * 3 + sourceAddr, count, new Queue(usedIndex)); + var timeData = CompressTimers(tims, usedIndex); + + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); - var timeData = CompressTimers(tims, usedIndex); + target.Write(cval.Length); + target.Write(cval); + rsize += 4; + rsize += cval.Length; - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Short: + var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 4 + sourceAddr, count, new Queue(usedIndex)); + timeData = CompressTimers(tims, usedIndex); - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(long)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); - - var timeData = CompressTimers(tims, usedIndex); - - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(ulong)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); - - var timeData = CompressTimers(tims, usedIndex); - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - - else if (typeof(T) == typeof(double)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); - - var timeData = CompressTimers(tims, usedIndex); - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; - } - else if (typeof(T) == typeof(float)) - { - var res = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); - - target.WriteUShort(targetAddr, (ushort)usedIndex.Count); - rsize += 2; - - var cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); - - var timeData = CompressTimers(tims, usedIndex); - target.Write((int)timeData.Length); - target.Write(timeData); - rsize += 4; - rsize += timeData.Length; - - - target.Write(res.Length); - target.Write(res); - rsize += 4; - rsize += res.Length; - - - target.Write(cqus.Length); - target.Write(cqus); - rsize += 4; - rsize += cqus.Length; + target.Write(res.Length); + target.Write(res); + rsize += 4; + rsize += res.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UShort: + var ures = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 4 + sourceAddr, count, new Queue(usedIndex)); + timeData = CompressTimers(tims, usedIndex); + + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + target.Write(ures.Length); + target.Write(ures); + rsize += 4; + rsize += ures.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Int: + var ires = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); + timeData = CompressTimers(tims, usedIndex); + + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + target.Write(ires.Length); + target.Write(ires); + rsize += 4; + rsize += ires.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.UInt: + var uires = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); + timeData = CompressTimers(tims, usedIndex); + + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + + target.Write(uires.Length); + target.Write(uires); + rsize += 4; + rsize += uires.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Long: + var lres = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); + + timeData = CompressTimers(tims, usedIndex); + + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + target.Write(lres.Length); + target.Write(lres); + rsize += 4; + rsize += lres.Length; + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.ULong: + var ulres = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); + + timeData = CompressTimers(tims, usedIndex); + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + target.Write(ulres.Length); + target.Write(ulres); + rsize += 4; + rsize += ulres.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Double: + var dres = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 10 + sourceAddr, count, new Queue(usedIndex)); + + timeData = CompressTimers(tims, usedIndex); + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + + target.Write(dres.Length); + target.Write(dres); + rsize += 4; + rsize += dres.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + case TagType.Float: + var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, tims, out usedIndex); + + target.WriteUShort(targetAddr, (ushort)usedIndex.Count); + rsize += 2; + + cqus = CompressQulitys(source, count * 6 + sourceAddr, count, new Queue(usedIndex)); + + timeData = CompressTimers(tims, usedIndex); + target.Write((int)timeData.Length); + target.Write(timeData); + rsize += 4; + rsize += timeData.Length; + + + target.Write(fres.Length); + target.Write(fres); + rsize += 4; + rsize += fres.Length; + + + target.Write(cqus.Length); + target.Write(cqus); + rsize += 4; + rsize += cqus.Length; + break; + default: + base.Compress(source, sourceAddr, target, targetAddr, size, type); + break; } - return rsize; }