Пример #1
0
        public void TestEncodeDecodeUInt64()
        {
            const int factor = 5;
            var       values = new ulong[64 * factor];

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

            var buffer = stackalloc byte[9];

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

                p = buffer;
                var value = Codec.DecodeUInt64(ref p);
                Assert.AreEqual(values[i], value, "At idx: " + i);
            }
        }
Пример #2
0
        public static void DecodeMinDeltaU64(ref byte *src, int skip, byte *dst)
        {
            var len = *(int *)src;
            var end = src + len;

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

            *(ulong *)dst = Codec.DecodeUInt64(ref src);
            var minDelta = Codec.DecodeUInt64(ref src);

            dst += next;

            while (src < end)
            {
                *(ulong *)dst = *(ulong *)(dst - next) + minDelta + Codec.DecodeUInt64(ref src);
                dst          += next;
            }
        }