Show / Hide Table of Contents

Struct Base64Decoder

Represents base64 decoder suitable for decoding large base64-encoded binary data using streaming approach.

Implements
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Buffers.Text
Assembly: DotNext.dll
Syntax
public struct Base64Decoder : IResettable
Remarks

This type maintains internal state for correct decoding of streaming data. Therefore, it must be passed by reference to any routine. It's not a ref struct to allow construction of high-level decoders in the form of classes. Base64-encoded bytes can be accepted as UTF-8 or Unicode characters. Decoding methods should not be intermixed by the caller code.

Properties

View Source

NeedMoreData

Indicates that the decoder expects additional data to decode.

Declaration
public readonly bool NeedMoreData { get; }
Property Value
Type Description
bool

Methods

View Source

DecodeFromUtf16(scoped ReadOnlySpan<char>, scoped ref BufferWriterSlim<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf16(scoped ReadOnlySpan<char> chars, scoped ref BufferWriterSlim<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<char> chars

UTF-8 encoded portion of base64 string.

BufferWriterSlim<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

View Source

DecodeFromUtf16(scoped ReadOnlySpan<char>, MemoryAllocator<byte>?)

Decodes base64 characters.

Declaration
public MemoryOwner<byte> DecodeFromUtf16(scoped ReadOnlySpan<char> chars, MemoryAllocator<byte>? allocator = null)
Parameters
Type Name Description
ReadOnlySpan<char> chars

The span containing base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the result buffer.

Returns
Type Description
MemoryOwner<byte>

A buffer containing decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

View Source

DecodeFromUtf16(scoped ReadOnlySpan<char>, IBufferWriter<byte>)

Decodes base64 characters.

Declaration
public void DecodeFromUtf16(scoped ReadOnlySpan<char> chars, IBufferWriter<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<char> chars

The span containing base64-encoded bytes.

IBufferWriter<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

View Source

DecodeFromUtf16Async(IAsyncEnumerable<ReadOnlyMemory<char>>, MemoryAllocator<byte>?, CancellationToken)

Decodes a sequence of base64-encoded bytes.

Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> DecodeFromUtf16Async(IAsyncEnumerable<ReadOnlyMemory<char>> chars, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters
Type Name Description
IAsyncEnumerable<ReadOnlyMemory<char>> chars

A sequence of base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the buffer used for decoded bytes.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
IAsyncEnumerable<ReadOnlyMemory<byte>>

A sequence of decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

OperationCanceledException

The operation has been canceled.

View Source

DecodeFromUtf8(scoped ReadOnlySpan<byte>, scoped ref BufferWriterSlim<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf8(scoped ReadOnlySpan<byte> chars, scoped ref BufferWriterSlim<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

BufferWriterSlim<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

View Source

DecodeFromUtf8(scoped ReadOnlySpan<byte>, MemoryAllocator<byte>?)

Decodes UTF-8 encoded base64 string.

Declaration
public MemoryOwner<byte> DecodeFromUtf8(scoped ReadOnlySpan<byte> chars, MemoryAllocator<byte>? allocator = null)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

MemoryAllocator<byte> allocator

The allocator of the result buffer.

Returns
Type Description
MemoryOwner<byte>

A buffer containing decoded bytes.

View Source

DecodeFromUtf8(scoped ReadOnlySpan<byte>, IBufferWriter<byte>)

Decodes UTF-8 encoded base64 string.

Declaration
public void DecodeFromUtf8(scoped ReadOnlySpan<byte> chars, IBufferWriter<byte> bytes)
Parameters
Type Name Description
ReadOnlySpan<byte> chars

UTF-8 encoded portion of base64 string.

IBufferWriter<byte> bytes

The output growable buffer used to write decoded bytes.

Exceptions
Type Condition
ArgumentNullException

bytes is null.

FormatException

The input base64 string is malformed.

View Source

DecodeFromUtf8Async(IAsyncEnumerable<ReadOnlyMemory<byte>>, MemoryAllocator<byte>?, CancellationToken)

Decodes a sequence of base64-encoded bytes.

Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> DecodeFromUtf8Async(IAsyncEnumerable<ReadOnlyMemory<byte>> utf8Chars, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters
Type Name Description
IAsyncEnumerable<ReadOnlyMemory<byte>> utf8Chars

A sequence of base64-encoded bytes.

MemoryAllocator<byte> allocator

The allocator of the buffer used for decoded bytes.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
IAsyncEnumerable<ReadOnlyMemory<byte>>

A sequence of decoded bytes.

Exceptions
Type Condition
FormatException

The input base64 string is malformed.

OperationCanceledException

The operation has been canceled.

View Source

Reset()

Resets the internal state of the decoder.

Declaration
public void Reset()

Implements

IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾