private uint LastOrDefault() { int lastPos = VarintEncoder.FindLast(data.AsSpan(0, length)); if (lastPos >= 0) { return((uint)VarintEncoder.Decode(data.AsSpan(lastPos))); } else { return(0); } }
public void FindLastTest() { var data = new byte[30]; int pos = 0; pos += VarintEncoder.Encode(1023, data.AsSpan(pos)); pos += VarintEncoder.Encode(5, data.AsSpan(pos)); pos += VarintEncoder.Encode(ulong.MaxValue, data.AsSpan(pos)); pos += VarintEncoder.Encode(ulong.MinValue, data.AsSpan(pos)); pos += VarintEncoder.Encode(719, data.AsSpan(pos)); int posLast = VarintEncoder.FindLast(data.AsSpan()); ulong last = VarintEncoder.Decode(data.AsSpan(posLast)); Assert.Equal(719ul, last); }