Exemple #1
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);
        }