public void TestVLQInt32() { 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(UInt32.MaxValue) + 1]; var span1 = new SpanStream(mem); var span2 = new SpanStream(mem); var data = new Int32[memSize]; for (var i = 0; i < memSize; i++) { data[i] = rnd.NextInt32(); } for (var i = 0; i < memSize; i++) { span1.WriteVLQ(data[i]); } for (var i = 0; i < memSize; i++) { Assert.Equal(data[i], span2.ReadVLQInt32(out var len)); Assert.Equal(SpanUtils.MeasureVLQ(data[i]), len); } // Check overflow new Span <byte>(mem).Fill(0xFF); Assert.Throws <OverflowException>(() => { var span3 = new SpanStream(mem); span3.ReadVLQInt32(out _); }); } }