Exemplo n.º 1
0
        /// <summary>
        /// 计算变量Id集合所占的大小
        /// </summary>
        /// <returns></returns>
        private int CalTagIdsSize()
        {
            if (mTagIdMemoryCach != null)
            {
                mTagIdMemoryCach.Dispose();
            }
            var aids = ServiceLocator.Locator.Resolve <IHisEngine>().ListAllTags().Where(e => e.Id >= Id * TagCountOneFile && e.Id < (Id + 1) * TagCountOneFile).OrderBy(e => e.Id).ToArray();

            mTagIdSum = 0;

            mTagIdMemoryCach = new VarintCodeMemory((int)(aids.Count() * 4 * 1.2));
            if (aids.Length > 0)
            {
                int preids = aids[0].Id;
                mTagIdSum += preids;
                mTagIdMemoryCach.WriteInt32(preids);
                for (int i = 1; i < aids.Length; i++)
                {
                    var id = aids[i].Id;
                    mTagIdMemoryCach.WriteInt32(id - preids);
                    mTagIdSum += id;
                    preids     = id;
                }
            }
            return(mTagIdMemoryCach.Position + 4);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memory"></param>
        /// <returns></returns>
        public static List <long> ToLongList(this VarintCodeMemory memory)
        {
            List <long> re = new List <long>();

            memory.Position = 0;
            while (memory.Position < memory.Length)
            {
                re.Add(memory.ReadInt64());
            }
            return(re);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memory"></param>
        /// <returns></returns>
        public static List <int> ToIntList(this VarintCodeMemory memory)
        {
            List <int> re = new List <int>();

            memory.Position = 0;
            while (memory.Position < memory.Length)
            {
                re.Add(memory.ReadInt32());
            }
            return(re);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        public void InitHeadData(Dictionary <long, HisRunTag> mtags)
        {
            memory = new VarintCodeMemory(mtags.Count * 16);
            memory.WriteInt64(mtags.Count);
            var  vtags = mtags.ToArray();
            long prev  = mtags.First().Key;
            int  i     = 0;

            foreach (var vv in mtags)
            {
                if (i == 0)
                {
                    memory.WriteInt64(prev);
                }
                else
                {
                    memory.WriteInt64((vv.Key - prev));
                    prev = vv.Key;
                }
                i++;
            }

            prev = mtags.First().Value.TimerValueStartAddr;
            i    = 0;
            foreach (var vv in mtags)
            {
                if (i == 0)
                {
                    memory.WriteInt64(prev);
                }
                else
                {
                    memory.WriteInt64(vv.Value.TimerValueStartAddr - prev);
                    prev = vv.Value.TimerValueStartAddr;
                }
                i++;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static byte[] GetAvailableDatas(this VarintCodeMemory memory)
 {
     byte[] bvals = new byte[memory.Length];
     Buffer.BlockCopy(memory.Buffer, 0, bvals, 0, bvals.Length);
     return(bvals);
 }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="sourceAddr"></param>
        /// <param name="target"></param>
        /// <param name="targetAddr"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        protected override long Compress <T>(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size)
        {
            var count = (int)(size - this.QulityOffset);
            var tims  = source.ReadUShorts(sourceAddr, (int)count);

            if (mMarshalMemory == null)
            {
                mMarshalMemory = new MemoryBlock(count * 10);
            }

            if (mVarintMemory == null)
            {
                mVarintMemory = new VarintCodeMemory(count * 10);
            }

            Queue <int> emptys = GetEmpityTimers(tims);
            Queue <int> usedIndex;

            long rsize = 0;


            if (typeof(T) == typeof(byte))
            {
                var cval = CompressValues <byte>(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 <int>(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 <short>(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 <int>(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 <ushort>(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 <int>(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 <int>(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 <int>(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))
            {
                var res = CompressValues <uint>(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 <int>(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(long))
            {
                var res = CompressValues <long>(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 <int>(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 <ulong>(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 <int>(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 <double>(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 <int>(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 <float>(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 <int>(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;
            }

            return(rsize);
        }