change throw to return and fix bug: when error always throw
This commit is contained in:
@@ -234,18 +234,18 @@ namespace WebProtocol
|
||||
{
|
||||
if (bytes.Length != 8)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
return new(new ArgumentException(
|
||||
"Bytes are not equal to 8 bytes.",
|
||||
nameof(bytes)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
if (checkSign && bytes[0] != (byte)PackSign.SendAddr)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"The sign of bytes is not SendAddr Package, but you can disable it by set checkSign false.",
|
||||
nameof(bytes)
|
||||
);
|
||||
return new(new ArgumentException(
|
||||
"The sign of bytes is not SendAddr Package, but you can disable it by set checkSign false.",
|
||||
nameof(bytes)
|
||||
));
|
||||
}
|
||||
|
||||
var address = Common.Number.BytesToNumber(bytes[4..]).Value;
|
||||
@@ -377,10 +377,10 @@ namespace WebProtocol
|
||||
public static Result<RecvDataPackage> FromBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes[0] != (byte)PackSign.RecvData)
|
||||
throw new ArgumentException(
|
||||
return new(new ArgumentException(
|
||||
$"The sign of bytes is not RecvData Package, Sign: 0x{BitConverter.ToString([bytes[0]])}",
|
||||
nameof(bytes)
|
||||
);
|
||||
));
|
||||
return new RecvDataPackage(bytes[1], bytes[2], bytes[4..]);
|
||||
}
|
||||
|
||||
@@ -480,10 +480,10 @@ namespace WebProtocol
|
||||
public static Result<RecvRespPackage> FromBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes[0] != (byte)PackSign.RecvResp)
|
||||
throw new ArgumentException(
|
||||
return new(new ArgumentException(
|
||||
$"The sign of bytes is not RecvResp Package, Sign: 0x{BitConverter.ToString([bytes[0]])}",
|
||||
nameof(bytes)
|
||||
);
|
||||
));
|
||||
return new RecvRespPackage(bytes[1], bytes[2]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user