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