Ejemplo n.º 1
0
        public void BitBufferCanHandleLargeValuesAndCompression()
        {
            var values = GetFailingValues();

            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);

                    var numberOfValues = values.Length;


                    for (int i = 0; i < numberOfValues; i++)
                    {
                        bitBuffer.EnsureAdditionalBits(allocator, values[i].Item2);
                        bitBuffer.AddValue(values[i].Item1, values[i].Item2);
                    }

                    using (bitBuffer.Uncompress(allocator, out var newBuf))
                    {
                        int offset = 0;
                        for (int i = 0; i < numberOfValues; i++)
                        {
                            var val = newBuf.ReadValue(ref offset, values[i].Item2);
                            if (val != values[i].Item1)
                            {
                                Assert.False(true, "Unmatch value at index: " + i);
                            }
                        }
                    }
                }
        }