Ascii85Encoding

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

Converts between binary data and an Ascii85-encoded string.

public sealed class Ascii85Encoding : IEncoding

Inheritance

objectAscii85Encoding

Implements

IEncoding

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

See Ascii85 at Wikipedia.

Constructors

Ascii85Encoding()

public Ascii85Encoding()

Methods

CanDecode(string)

Determine if we can decode the given string.

public static bool CanDecode(string encoded)

Parameters

NameDescription

encoded string

The Ascii85 string.

Returns

NameDescription

true if we can decode, false if not.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Decode(string)

Decodes the specified Ascii85 string into the corresponding byte array.

public byte[] Decode(string encoded)

Parameters

NameDescription

encoded string

The Ascii85 string.

Returns

NameDescription

The decoded byte array.

Examples

// Encode and decoding using Ascii85Encoding
Ascii85Encoding ascii85 = new Ascii85Encoding();
byte[] data = Enumerable.Range(1, 10).Select(i => (byte)i).ToArray();

// Encode data byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
string encoded = ascii85.Encode(data);

// encoded string
// !<N?+\"U52;#mp

// Decode encodes string 
byte[] decoded = ascii85.Decode(encoded);

// decoded byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA

Encode(byte[])

Encodes the specified byte array in Ascii85.

public string Encode(byte[] bytes)

Parameters

NameDescription

bytes byte[]

The bytes to encode.

Returns

NameDescription

An Ascii85-encoded string representing the input byte array.

Examples

// Encode and decoding using Ascii85Encoding
Ascii85Encoding ascii85 = new Ascii85Encoding();
byte[] data = Enumerable.Range(1, 10).Select(i => (byte)i).ToArray();

// Encode data byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
string encoded = ascii85.Encode(data);

// encoded string
// !<N?+\"U52;#mp

// Decode encodes string 
byte[] decoded = ascii85.Decode(encoded);

// decoded byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA

IsValidChar(char)

Query if the given character is a valid for encoding.

public bool IsValidChar(char value)

Parameters

NameDescription

value char

The input character.

Returns

NameDescription

true if valid character, false if not.

Examples

// Check if a character is valid Ascii85 symbol
Ascii85Encoding ascii85 = new Ascii85Encoding();

bool validAscii85Char1 = ascii85.IsValidChar(Convert.ToChar(0xEF00));
// validAscii85Char1
// flase

bool validAscii85Char2 = ascii85.IsValidChar('!');
// validAscii85Char2
// true

Last updated