Beispiel #1
0
        private void TestEncodeDecodeMinDelta32 <T>(int count, Func <int, T[]> factory, int shift, int skip)
            where T : unmanaged
        {
            var chunk  = factory(count);
            var result = new T[count];

            var size   = CodecExt.GetMaxEncodedSizeForMinDelta32(chunk.Length);
            var buffer = new UnsafeBuffer(size);

            // Copy partial data
            if (skip > 0)
            {
                fixed(T *src = chunk)
                fixed(T * dst = result)
                {
                    Extensions.CopyBlock((byte *)src, (byte *)dst, count * sizeof(T), skip, sizeof(T) - skip);
                }
            }

            fixed(T *p = chunk)
            {
                var dst = buffer.Ptr;

                CodecExt.EncodeMinDelta32((byte *)p + shift, count * sizeof(T) - shift, skip, ref dst);
            }

            fixed(T *p = result)
            {
                var src = buffer.Ptr;

                CodecExt.DecodeMinDelta32(ref src, skip, (byte *)p + shift);
            }

            chunk.IsEqualTo(result);
        }
Beispiel #2
0
        private void TestEncodeDecodeMinDelta64 <T>(int count, Func <int, T[]> factory, int skip)
            where T : unmanaged
        {
            var chunk  = factory(count);
            var result = new T[count];

            var size   = CodecExt.GetMaxEncodedSizeForMinDeltaU64(chunk.Length);
            var buffer = new UnsafeBuffer(size);

            fixed(T *p = chunk)
            {
                var dst = buffer.Ptr;

                CodecExt.EncodeMinDeltaU64((byte *)p, count * sizeof(T), skip, ref dst);
            }

            fixed(T *p = result)
            {
                var src = buffer.Ptr;

                CodecExt.DecodeMinDeltaU64(ref src, skip, (byte *)p);
            }

            chunk.IsEqualTo(result);
        }
Beispiel #3
0
        public int Encode(Int32Entry *src, int count, byte *dst)
        {
            var start = dst;

            *(int *)dst = count;
            dst        += sizeof(int);

            CodecExt.EncodeMinDeltaU64((byte *)src, count * sizeof(Int32Entry), sizeof(int), ref dst);
            CodecExt.EncodeMinDelta32((byte *)(src + sizeof(long)), count * sizeof(Int32Entry) - sizeof(long), sizeof(long), ref dst);

            return((int)(dst - start));
        }
Beispiel #4
0
        public int Decode(byte *src, int len, Int32Entry *dst)
        {
            var count = *(int *)src;

            src += sizeof(int);

            // Decodes header
            CodecExt.DecodeMinDeltaU64(ref src, sizeof(int), (byte *)dst);
            CodecExt.DecodeMinDelta32(ref src, sizeof(long), (byte *)(dst + sizeof(long)));

            return(count);
        }
Beispiel #5
0
 public int GetMaxEncodedSize(int count)
 {
     return(CodecExt.GetMaxEncodedSizeForMinDeltaU64(count)
            + Codec.MAX_INT32_LENGTH * (count + 2));
 }