Skip to content

This library provides methods for encoding and decoding base64url (RFC 4648) data using the new memory efficient Span and Buffer APIs.

License

Notifications You must be signed in to change notification settings

NCodeGroup/Base64Url

Repository files navigation

ci

Overview

This library provides methods for encoding and decoding base64url (RFC 4648) data using the new memory efficient Span and Buffer APIs.

namespace NCode.Encoders;

public static class Base64Url
{
    // Encode...

    public static int GetCharCountForEncode(
        int byteCount);

    public static string Encode(
        ReadOnlySpan<byte> bytes);

    public static int Encode(
        ReadOnlySpan<byte> bytes,
        IBufferWriter<char> writer);

    public static int Encode(
        ReadOnlySequence<byte> sequence,
        IBufferWriter<char> writer);

    public static bool TryEncode(
        ReadOnlySequence<byte> sequence,
        Span<char> chars,
        out int charsWritten);

    public static bool TryEncode(
        ReadOnlySpan<byte> bytes,
        Span<char> chars,
        out int charsWritten);

    // Decode...

    public static int GetByteCountForDecode(
        int charCount);

    public static byte[] Decode(
        ReadOnlySpan<char> chars);

    public static int Decode(
        ReadOnlySpan<char> chars,
        IBufferWriter<byte> writer);

    public static int Decode(
        ReadOnlySequence<char> sequence,
        IBufferWriter<byte> writer);

    public static bool TryDecode(
        ReadOnlySequence<char> sequence,
        Span<byte> bytes,
        out int bytesWritten);

    public static bool TryDecode(
        ReadOnlySpan<char> chars,
        Span<byte> bytes,
        out int bytesWritten);
}

Release Notes

  • v1.0.0 - Initial release
  • v1.1.0 - Added support for sequences
  • v1.1.1 - Added support for sequences without buffer writer
  • v1.1.2 - Added optimization for single segment sequences

About

This library provides methods for encoding and decoding base64url (RFC 4648) data using the new memory efficient Span and Buffer APIs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages