ocean.util.encode.Base16

This module is used to decode and encode hex char[] arrays.

Members

Functions

allocateEncodeSize
size_t allocateEncodeSize(ubyte[] data)

calculates and returns the size needed to encode the length of the array passed.

allocateEncodeSize
size_t allocateEncodeSize(size_t length)

calculates and returns the size needed to encode the length passed.

decode
ubyte[] decode(cstring data, ubyte[] buff)

decodes an ASCII hex string and returns it as ubyte[] data.

decode
ubyte[] decode(cstring data)

decodes an ASCII hex string and returns it as ubyte[] data. Pre-allocates the size of the array.

encode
char[] encode(ubyte[] data, char[] buff)

encodes data and returns as an ASCII hex string.

encode
char[] encode(ubyte[] data)

encodes data and returns as an ASCII hex string.

Examples

char[] blah = "Hello there, my name is Jeff.";

scope encodebuf = new char[allocateEncodeSize(cast(ubyte[])blah)];
char[] encoded = encode(cast(ubyte[])blah, encodebuf);

scope decodebuf = new ubyte[encoded.length];
if (cast(char[])decode(encoded, decodebuf) == "Hello there, my name is Jeff.")
    Stdout("yay").newline;

Since v1.0

Meta