Decodes the sequence of bytes represented by the specified string of hexadecimal characters. Returns a slice of the output buffer containing the decoded bytes.
pub fn hexToBytes(out: []u8, input: []const u8) ![]u8
pub fn hexToBytes(out: []u8, input: []const u8) ![]u8 {
// Expect 0 or n pairs of hexadecimal digits.
if (input.len & 1 != 0)
return error.InvalidLength;
if (out.len * 2 < input.len)
return error.NoSpaceLeft;
var in_i: usize = 0;
while (in_i < input.len) : (in_i += 2) {
const hi = try charToDigit(input[in_i], 16);
const lo = try charToDigit(input[in_i + 1], 16);
out[in_i / 2] = (hi << 4) | lo;
}
return out[0 .. in_i / 2];
}