private static byte[] CheckTrailingNULL(byte[] data)
{
Throw.IfNull(nameof(data), data);
int length = data.Length;
while (length > 2)
{
if (data[length - 1] != '\0')
break;
length--;
}
if (length == data.Length)
return data;
byte[] result = new byte[length];
Buffer.BlockCopy(data, 0, result, 0, length);
return result;
}