Exemplo n.º 1
0
        public static void DecodeMinDelta32(ref byte *src, int skip, byte *dst)
        {
            var len = *(int *)src;
            var end = src + len;

            src += sizeof(int);
            var next = sizeof(int) + skip;

            *(int *)dst = Codec.DecodeInt32(ref src);
            var maxNegDelta = Codec.DecodeInt32(ref src);
            var minPosDelta = Codec.DecodeInt32(ref src);

            dst += next;
            while (src < end)
            {
                var delta = Codec.DecodeInt32(ref src, out var isNegative);
                if (isNegative)
                {
                    *(int *)dst = *(int *)(dst - next) - (delta + maxNegDelta);
                }
                else
                {
                    *(int *)dst = *(int *)(dst - next) + delta + minPosDelta;
                }

                dst += next;
            }
        }
Exemplo n.º 2
0
        public void TestEncodeDecodeInt32()
        {
            var values = new int[32 * 4];

            for (var i = 1; i < 32; i++)
            {
                var value = (uint)Math.Pow(2, i);
                values[i * 4]     = (int)value - 1;
                values[i * 4 + 1] = (int)value;
                values[i * 4 + 2] = -values[i * 4];
                values[i * 4 + 3] = -values[i * 4 + 1];
            }

            var buffer = stackalloc byte[5];

            for (var i = 0; i < values.Length; i++)
            {
                var p = buffer;
                Codec.EncodeInt32(values[i], ref p);

                p = buffer;
                var value = Codec.DecodeInt32(ref p);
                Assert.AreEqual(values[i], value, "At idx: " + i);
            }
        }
Exemplo n.º 3
0
        public int DecodeHead(ref byte *src, int len)
        {
            var start = src;

            _minTicks    = Codec.DecodeInt64(ref src);
            _maxNegValue = Codec.DecodeInt32(ref src);
            _minPosValue = Codec.DecodeInt32(ref src);
            return((int)(src - start));
        }