/// <summary> /// /// </summary> /// <param name="memory"></param> /// <param name="readValueType"></param> /// <returns></returns> private static TagHisValue <T> DeCompressDataBlockRawValue <T>(MarshalMemoryBlock memory, byte readValueType) { var ctype = memory.ReadByte(); var tp = CompressUnitManager2.Manager.GetCompress(ctype); if (tp != null) { return(tp.DeCompressRawValue <T>(memory, 1, readValueType)); } return(TagHisValue <T> .Empty); }
/// <summary> /// /// </summary> /// <param name="memory"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="timeTick"></param> /// <param name="result"></param> private static void DeCompressDataBlockAllValue <T>(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult <T> result) { //MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); //读取压缩类型 var ctype = memory.ReadByte(); var tp = CompressUnitManager2.Manager.GetCompress(ctype); if (tp != null) { tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="memory"></param> /// <param name="datatime"></param> /// <param name="timeTick"></param> /// <param name="type"></param> /// <param name="result"></param> private static void DeCompressDataBlockValue <T>(MarshalMemoryBlock memory, List <DateTime> datatime, int timeTick, QueryValueMatchType type, HisQueryResult <T> result, Func <byte, object> ReadOtherDatablockAction) { //MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); //读取压缩类型 var ctype = memory.ReadByte(); var tp = CompressUnitManager2.Manager.GetCompress(ctype); if (tp != null) { tp.DeCompressValue <T>(memory, 1, datatime, timeTick, type, result, ReadOtherDatablockAction); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="memory"></param> /// <param name="datatime"></param> /// <param name="timeTick"></param> /// <param name="type"></param> /// <returns></returns> private static object DeCompressDataBlockValue <T>(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type, Func <byte, object> ReadOtherDatablockAction) { //MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); //读取压缩类型 var ctype = memory.ReadByte(); var tp = CompressUnitManager2.Manager.GetCompress(ctype); if (tp != null) { return(tp.DeCompressValue <T>(memory, 1, datatime, timeTick, type, ReadOtherDatablockAction)); } return(null); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="offset"></param> /// <param name="totalcount"></param> /// <param name="usedIndex"></param> /// <returns></returns> protected new Memory <byte> CompressQulitys(MarshalMemoryBlock source, long offset, int totalcount, Queue <int> usedIndex) { int count = 1; byte qus = source.ReadByte(offset); //using (VarintCodeMemory memory = new VarintCodeMemory(qulitys.Length * 2)) mVarintMemory.Position = 0; int ig = -1; usedIndex.TryDequeue(out ig); mVarintMemory.WriteInt32(qus); for (int i = 1; i < totalcount; i++) { if (i == ig) { byte bval = source.ReadByte(offset + i); if (bval == qus) { count++; } else { mVarintMemory.WriteInt32(count); qus = bval; mVarintMemory.WriteInt32(qus); count = 1; } if (usedIndex.Count > 0) { usedIndex.TryDequeue(out ig); } } } mVarintMemory.WriteInt32(count); return(mVarintMemory.Buffer.AsMemory(0, mVarintMemory.Position)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <param name="emptyIds"></param> /// <returns></returns> protected override Memory <byte> CompressValues <T>(MarshalMemoryBlock source, long offset, int count, Queue <int> emptyIds) { var deadArea = this.Parameters.ContainsKey("DeadValue") ? this.Parameters["DeadValue"] : 0; var deadType = (int)(this.Parameters.ContainsKey("DeadType") ? this.Parameters["DeadType"] : 0); mMarshalMemory.Position = 0; mVarintMemory.Position = 0; bool isFirst = true; int ig = -1; emptyIds.TryDequeue(out ig); if (typeof(T) == typeof(byte)) { byte sval = 0; for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadByte(offset + i); if (isFirst) { sval = id; mMarshalMemory.Write(id); isFirst = false; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mMarshalMemory.Write(id); sval = id; } } } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(mMarshalMemory.StartMemory.AsMemory <byte>(0, (int)mMarshalMemory.Position)); } else if (typeof(T) == typeof(short)) { short sval = 0; for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadShort(offset + i * 2); if (isFirst) { mVarintMemory.WriteSInt32(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt32(id - sval); sval = id; } } } 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) { var id = source.ReadUShort(offset + i * 2); if (isFirst) { mVarintMemory.WriteSInt32(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt32(id - sval); sval = id; } } } 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) { var id = source.ReadInt(offset + i * 4); if (isFirst) { mVarintMemory.WriteInt32(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt32(id - sval); sval = id; } } } 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) { var id = source.ReadUInt(offset + i * 4); if (isFirst) { mVarintMemory.WriteInt32(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt32((int)(id - sval)); 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) { var id = source.ReadLong(offset + i * 8); if (isFirst) { mVarintMemory.WriteInt64(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt64((id - sval)); sval = id; } } } 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) { var id = source.ReadULong(offset + i * 8); if (isFirst) { mVarintMemory.WriteInt64(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mVarintMemory.WriteSInt64((long)(id - sval)); sval = id; } } } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } } else if (typeof(T) == typeof(double)) { double sval = 0; for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadDouble(offset + i * 8); if (isFirst) { mMarshalMemory.Write(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mMarshalMemory.Write(id); sval = id; } } } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(mMarshalMemory.StartMemory.AsMemory <byte>(0, (int)mMarshalMemory.Position)); } else if (typeof(T) == typeof(float)) { float sval = 0; for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadFloat(offset + i * 4); if (isFirst) { mMarshalMemory.Write(id); isFirst = false; sval = id; } else { if (CheckIsNeedRecord(sval, id, deadArea, deadType)) { mMarshalMemory.Write(id); sval = id; } } } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(mMarshalMemory.StartMemory.AsMemory <byte>(0, (int)mMarshalMemory.Position)); } return(mVarintMemory.Buffer.AsMemory <byte>(0, (int)mVarintMemory.Position)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <param name="emptyIds"></param> /// <param name="mTimers"></param> /// <param name="usedTimerIndex"></param> /// <returns></returns> protected Memory <byte> CompressValues <T>(MarshalMemoryBlock source, long offset, int count, Queue <int> emptyIds, List <ushort> mTimers, out Queue <int> usedTimerIndex) { int ig = -1; emptyIds.TryDequeue(out ig); if (typeof(T) == typeof(byte)) { Dictionary <ushort, byte> mavaibleValues = new Dictionary <ushort, byte>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadByte(offset + i); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(short)) { Dictionary <ushort, short> mavaibleValues = new Dictionary <ushort, short>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadShort(offset + i); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(ushort)) { Dictionary <ushort, ushort> mavaibleValues = new Dictionary <ushort, ushort>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadUShort(offset + i); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(int)) { Dictionary <ushort, int> mavaibleValues = new Dictionary <ushort, int>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadInt(offset + i); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(uint)) { Dictionary <ushort, uint> mavaibleValues = new Dictionary <ushort, uint>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadUInt(offset + i); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(long)) { Dictionary <ushort, long> mavaibleValues = new Dictionary <ushort, long>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadLong(offset + i * 8); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(ulong)) { Dictionary <ushort, ulong> mavaibleValues = new Dictionary <ushort, ulong>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadULong(offset + i * 8); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(double)) { Dictionary <ushort, double> mavaibleValues = new Dictionary <ushort, double>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadDouble(offset + i * 8); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } else if (typeof(T) == typeof(float)) { Dictionary <ushort, float> mavaibleValues = new Dictionary <ushort, float>(); for (int i = 0; i < count; i++) { if (i != ig) { var id = source.ReadFloat(offset + i * 4); mavaibleValues.Add(mTimers[i], id); } else { if (emptyIds.Count > 0) { emptyIds.TryDequeue(out ig); } } } return(SlopeCompress(mavaibleValues, out usedTimerIndex)); } usedTimerIndex = null; return(null); }