public void Test_Write(uint value, byte[] expected) { var bytes = Leb128.Write(value); Assert.Equal(expected, bytes); var decoded = Leb128.Read(bytes); Assert.Equal(value, decoded); }
public void Test_Write(uint value, byte[] expected) { var bytes = new byte[5]; var length = Leb128.Write(bytes, value); Assert.Equal(expected, bytes.Take(length)); var decoded = Leb128.Read(bytes); Assert.Equal(value, decoded); }
protected int WriteKey(Span <byte> buffer) { var length = 0; if (Cid.HasValue) { length += Leb128.Write(buffer, Cid.Value); } length += ByteConverter.FromString(Key, buffer.Slice(length)); return(length); }
// ********************************************************************** public void WriteGrowing(long value, ref long lastValue) { long offset = value - lastValue; if (offset >= ULeb128.Max4BValue || offset < 0) { ULeb128.Write(BaseStream, ULeb128.Max4BValue); Leb128.Write(BaseStream, offset); } else { ULeb128.Write(BaseStream, (uint)offset); } lastValue = value; }
public virtual byte[] CreateKey() { var length = Encoding.UTF8.GetByteCount(Key); //for collections add the leb128 cid if (Cid.HasValue) { length = length + 2; } var buffer = new byte[length]; if (Cid.HasValue) { var leb128Length = Leb128.Write(buffer, Cid.Value); Converter.FromString(Key, buffer, leb128Length); } else { Converter.FromString(Key, buffer, 0); } return(buffer); }
// ********************************************************************** public void WriteLeb128(long value) { Leb128.Write(BaseStream, value); }
public int Baseline() { Span <byte> buffer = stackalloc byte[8]; return(Leb128.Write(buffer, Value)); }