Ejemplo n.º 1
0
        public unsafe void BitBufferCompression()
        {
            using (var allocator = new ByteStringContext(SharedMultipleUseFlag.None))
                using (allocator.Allocate(2048, out var buffer))
                {
                    Memory.Set(buffer.Ptr, 0, buffer.Length);
                    var bitBuffer = new BitsBuffer(buffer.Ptr, buffer.Length);

                    for (int i = 0; i < 12; i++)
                    {
                        bitBuffer.AddValue((ulong)(i & 1), 1);
                    }

                    bitBuffer.TryCompressBuffer(allocator, 0);


                    bitBuffer.Uncompress(allocator, out var newBuffer);

                    for (int i = 0; i < 12; i++)
                    {
                        int copy = i;
                        var v    = newBuffer.ReadValue(ref copy, 1);
                        Assert.Equal((ulong)(i & 1), v);
                    }
                }
        }