public static byte[] Decode(byte[] input, byte escapeChar, byte space)
{
using (MemoryStream stream = new MemoryStream(input.Length))
{
for (int i = 0; i < input.Length; i++)
{
if (input[i] == space)
{
stream.WriteByte(0x20);
}
else if ((input[i] == escapeChar) && ((i + 2) < input.Length))
{
i++;
stream.WriteByte(Hex2Byte(input, i++));
}
else
{
stream.WriteByte(input[i]);
}
}
return stream.ToArray();
}
}