完善开发环境工具、音乐服务和界面性能
This commit is contained in:
@@ -55,7 +55,18 @@ public static class SerialPayloadCodec
|
||||
return Encoding.UTF8.GetBytes(value ?? string.Empty);
|
||||
}
|
||||
|
||||
var compact = new string((value ?? string.Empty).Where(Uri.IsHexDigit).ToArray());
|
||||
var input = value ?? string.Empty;
|
||||
foreach (var character in input)
|
||||
{
|
||||
if (!char.IsAsciiHexDigit(character) &&
|
||||
!char.IsWhiteSpace(character) &&
|
||||
character is not (',' or ';' or ':' or '-'))
|
||||
{
|
||||
throw new FormatException("Hexadecimal input contains an invalid character.");
|
||||
}
|
||||
}
|
||||
|
||||
var compact = new string(input.Where(char.IsAsciiHexDigit).ToArray());
|
||||
if (compact.Length == 0)
|
||||
{
|
||||
return [];
|
||||
@@ -77,7 +88,13 @@ public static class SerialPayloadCodec
|
||||
}
|
||||
|
||||
public static string Format(ReadOnlySpan<byte> data, bool hexadecimal)
|
||||
=> hexadecimal
|
||||
? Convert.ToHexString(data).Chunk(2).Select(chars => new string(chars)).Aggregate(string.Empty, (current, item) => string.IsNullOrEmpty(current) ? item : current + " " + item)
|
||||
: Encoding.UTF8.GetString(data);
|
||||
{
|
||||
if (!hexadecimal)
|
||||
{
|
||||
return Encoding.UTF8.GetString(data);
|
||||
}
|
||||
|
||||
var encoded = Convert.ToHexString(data);
|
||||
return string.Join(' ', encoded.Chunk(2).Select(chars => new string(chars)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user