public void SkipVarIntOk() { var buf = Buf(VarIntHelper.GetVarInt32Bytes(889863845U)); buf.SkipVarInt(); Assert.True(buf.End); buf = Buf(VarIntHelper.GetVarInt64Bytes(ulong.MaxValue)); buf.SkipVarInt(); Assert.True(buf.End); Assert.Throws <InvalidDataException>(() => buf.SkipVarInt()); buf = Buf(VarIntHelper.GetVarInt64Bytes(ulong.MaxValue).TakeWhile(x => x > 128).ToArray()); Assert.Throws <InvalidDataException>(() => buf.SkipVarInt()); buf = Buf(Enumerable.Range(0, 20).Select(x => (byte)128).ToArray()); Assert.Throws <InvalidDataException>(() => buf.SkipVarInt()); }
public void GetVarInt64BytesSeemsOk() { var b0 = VarIntHelper.GetVarInt64Bytes(0U); Assert.Equal(1, b0.Length); Assert.Equal(0, b0[0]); for (var i = 1; i < 10; i++) { var breakingPoint = VarIntHelper.GetVarInt64Bytes((1UL << (7 * i)) - 1); Assert.Equal(i, breakingPoint.Length); Assert.True(breakingPoint.Take(i - 1).All(x => x == 255)); Assert.Equal(127, breakingPoint.Last()); var next = VarIntHelper.GetVarInt64Bytes(1UL << (7 * i)); Assert.Equal(i + 1, next.Length); Assert.True(next.Take(i).All(x => x == 128)); Assert.Equal(1, next.Last()); } }