Show / Hide Table of Contents

Struct Leb128<T>

Represents encoder and decoder for 7-bit encoded integers.

Implements
ISupplier<T>
IFunctional<Func<T>>
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 Source

MaxSizeInBytes

Maximum size of encoded T, in bytes.

Declaration
public static int MaxSizeInBytes { get; }
Property Value
Type Description
int
| Edit this page View Source

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 Source

Append(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.

| Edit this page View Source

GetEnumerator()

Gets an enumerator over encoded octets.

Declaration
public readonly Leb128<T>.Enumerator GetEnumerator()
Returns
Type Description
Leb128<T>.Enumerator
| Edit this page View Source

Reset()

Resets the decoder.

Declaration
public void Reset()
| Edit this page View Source

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 buffer has enough space to save the encoded value; otherwise, false.

| Edit this page View Source

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 buffer.

Returns
Type Description
bool

true if operation is successful; otherwise, false.

Implements

ISupplier<TResult>
IFunctional<TDelegate>
IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)

See Also

LEB128 encoding
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾