Struct Leb128<T>
Represents encoder and decoder for 7-bit encoded integers.
Inherited Members
Namespace: DotNext.Buffers.Binary
Assembly: DotNext.dll
Syntax
public struct Leb128<T> : ISupplier<T>, IFunctional<Func<T>>, IResettable where T : struct, IBinaryInteger<T>
Type Parameters
Name | Description |
---|---|
T | The type of the integer. |
Remarks
Note that encoding of signed and unsigned integers produce different octets.
Properties
| Edit this page View SourceMaxSizeInBytes
Maximum size of encoded T
, in bytes.
Declaration
public static int MaxSizeInBytes { get; }
Property Value
Type | Description |
---|---|
int |
Value
Gets a value represented by the encoded.
Declaration
public T Value { readonly get; set; }
Property Value
Type | Description |
---|---|
T |
Methods
| Edit this page View SourceAppend(byte)
Decodes an octet.
Declaration
public bool Append(byte b)
Parameters
Type | Name | Description |
---|---|---|
byte | b | The byte that represents a part of 7-bit encoded integer. |
Returns
Type | Description |
---|---|
bool | true if the decoder expects more data to decode; false if the last octet detected. |
Exceptions
Type | Condition |
---|---|
InvalidDataException | The maximum number of octets reached. |
GetEnumerator()
Gets an enumerator over encoded octets.
Declaration
public readonly Leb128<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
Leb128<T>.Enumerator |
Reset()
Resets the decoder.
Declaration
public void Reset()
TryGetBytes(T, Span<byte>, out int)
Tries to encode the value by using LEB128 binary format.
Declaration
public static bool TryGetBytes(T value, Span<byte> buffer, out int bytesWritten)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to encode. |
Span<byte> | buffer | The output buffer. |
int | bytesWritten | The number of bytes written. |
Returns
Type | Description |
---|---|
bool | true if |
TryParse(ReadOnlySpan<byte>, out T, out int)
Decodes LEB128-encoded integer.
Declaration
public static bool TryParse(ReadOnlySpan<byte> buffer, out T result, out int bytesConsumed)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | buffer | The input buffer containing LEB128 octets. |
T | result | The decoded value. |
int | bytesConsumed | The number of bytes consumed from |
Returns
Type | Description |
---|---|
bool |