Edit

Share via


Base64.DecodeFromUtf8 Method

Definition

Decodes the span of UTF-8 encoded text represented as base 64 into binary data. If the input is not a multiple of 4, it will decode as much as it can, to the closest multiple of 4.

public static System.Buffers.OperationStatus DecodeFromUtf8 (ReadOnlySpan<byte> utf8, Span<byte> bytes, out int bytesConsumed, out int bytesWritten, bool isFinalBlock = true);
static member DecodeFromUtf8 : ReadOnlySpan<byte> * Span<byte> * int * int * bool -> System.Buffers.OperationStatus
Public Shared Function DecodeFromUtf8 (utf8 As ReadOnlySpan(Of Byte), bytes As Span(Of Byte), ByRef bytesConsumed As Integer, ByRef bytesWritten As Integer, Optional isFinalBlock As Boolean = true) As OperationStatus

Parameters

utf8
ReadOnlySpan<Byte>

The input span that contains UTF-8 encoded text in base 64 that needs to be decoded.

bytes
Span<Byte>

The output span that contains the result of the operation, that is, the decoded binary data.

bytesConsumed
Int32

When this method returns, contains the number of input bytes consumed during the operation. This can be used to slice the input for subsequent calls, if necessary.

bytesWritten
Int32

When this method returns, contains the number of bytes written into the output span. This can be used to slice the output for subsequent calls, if necessary.

isFinalBlock
Boolean

true (default) to indicate that the input span contains the entire data to decode. false to indicate that the input span contains partial data with more data to follow.

Returns

One of the enumeration values that indicates the status of the decoding operation.

Remarks

The return value can be as follows:

  • OperationStatus.Done: Processing of the entire input span succeeded.
  • OperationStatus.DestinationTooSmall: There is not enough space in the output span to write the decoded input.
  • OperationStatus.NeedMoreData: isFinalBlock is false and the input is not a multiple of 4. Otherwise, the partial input is considered InvalidData.
  • OperationStatus.InvalidData: The input contains bytes outside of the expected base 64 range, or is incomplete (that is, not a multiple of 4) and isFinalBlock is true. In .NET 7 and earlier versions, this value can also indicate that the input has invalid or more than two padding characters.

Applies to