public void TestVLQInt64() { var rnd = new Random(); for (var c = 0; c < count; c++) { var memSize = rnd.Next(1, 10_000); var mem = new byte[memSize * SpanUtils.MeasureVLQ(UInt64.MaxValue) + 1]; var span1 = new MemoryStreamer(mem); var span2 = new MemoryStreamer(mem); var data = new Int64[memSize]; for (var i = 0; i < memSize; i++) { data[i] = rnd.NextInt64(); } for (var i = 0; i < memSize; i++) { span1.WriteVLQ(data[i]); } for (var i = 0; i < memSize; i++) { Assert.Equal(data[i], span2.ReadVLQInt64(out var len)); Assert.Equal(SpanUtils.MeasureVLQ(data[i]), len); } // Check overflow new Span <byte>(mem).Fill(0xFF); Assert.Throws <OverflowException>(() => { var span3 = new MemoryStreamer(mem); span3.ReadVLQInt64(out _); }); } }