Skip to content

Commit

Permalink
fix: #9
Browse files Browse the repository at this point in the history
  • Loading branch information
InuInu2022 committed Jan 24, 2024
1 parent 387e013 commit 207568e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions LibSasara.VoiSona/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static LibSasara.VoiSona.Util.BinaryUtil.ParseIntegerFromBytes(System.ReadOnlyMemory<byte> memory, int countType) -> uint
20 changes: 9 additions & 11 deletions LibSasara.VoiSona/Util/BinaryUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,11 @@ private static int ConvertCountTypeToNumber(int countType, ReadOnlySpan<byte> co
return countType switch
{
0 or 1 => countData[0],
2 => BitConverter
sizeof(ushort) => BitConverter
.ToUInt16(countData.ToArray(), 0),
3 => BitConverter
.ToInt32(countData.ToArray(), 0),
//not tested
4 => (int)BitConverter
.ToInt64(countData.ToArray(), 0),
sizeof(int) => BitConverter
.ToInt32(countData.ToArray(), 0),
_ => -1
};
}
Expand Down Expand Up @@ -231,20 +229,20 @@ out ReadOnlyCollection<ReadOnlyMemory<byte>> collection
/// <param name="memory"></param>
/// <param name="countType"></param>
/// <returns></returns>
public static int ParseIntegerFromBytes(
public static uint ParseIntegerFromBytes(
ReadOnlyMemory<byte> memory,
int countType
){
return countType switch
{
0 => 0,
sizeof(byte) => BitConverter
sizeof(byte) => (uint)BitConverter
.ToInt32(memory[..countType].ToArray(), 0),
sizeof(ushort) => BitConverter
.ToUInt16(memory[..countType].ToArray(), 0),
sizeof(int) => BitConverter
.ToInt32(memory[..countType].ToArray(), 0),
_ => -1
sizeof(uint) => BitConverter
.ToUInt32(memory[..countType].ToArray(), 0),
_ => throw new InvalidCastException(nameof(ParseIntegerFromBytes))
};
}

Expand All @@ -261,7 +259,7 @@ long count
<= byte.MaxValue => sizeof(byte),
<= ushort.MaxValue => sizeof(ushort),
//uint?
<= int.MaxValue => sizeof(int),
<= uint.MaxValue => sizeof(uint),
<= long.MaxValue => sizeof(long),
};
}
Expand Down

0 comments on commit 207568e

Please sign in to comment.