Skip to content

Commit

Permalink
Add the GetRType extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenveo committed Nov 29, 2021
1 parent 4368b38 commit 10d9fe1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Noisrev.League.IO.RST/Helper/RTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,27 @@ public static ulong ComputeKey(this RType type)
{
return (1UL << (int)type) - 1;
}
/// <summary>
/// Gets the specified RType based on version.
/// </summary>
/// <param name="version">the version</param>
/// <returns>Returns an RType, or null, depending on whether it is a valid version</returns>
public static RType? GetRType(this int version) =>
((byte)version).GetRType();
/// <summary>
/// Gets the specified RType based on version.
/// </summary>
/// <param name="version">the version</param>
/// <returns>Returns an RType, or null, depending on whether it is a valid version</returns>
public static RType? GetRType(this byte version)
{
/* Version 2 and Version 3 */
if (version == 2 || version == 3)
return RType.Complex;
else if (version == 4 || version == 5) /* Version 4, 5 */
return RType.Simple;
else /* Unknown */
return null;
}
}
}
4 changes: 2 additions & 2 deletions Noisrev.League.IO.RST/Helper/StreamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class StreamHelper
/// <param name="input">BinaryReader</param>
/// <param name="offset">The offset</param>
/// <param name="end">End Byte</param>
/// <returns>UTF-8 string</returns>
/// <returns>Byte Array</returns>
/// <exception cref="IOException"></exception>
/// <exception cref="NotSupportedException"></exception>
/// <exception cref="ObjectDisposedException"></exception>
Expand All @@ -36,7 +36,7 @@ public static byte[] ReadBufferWithEndByte<T>(this T input, long offset, byte en
buffer.Add(tmp);
}

// To an array and convert it to a UTF-8 string
// return the buffer
return buffer.ToArray();
}

Expand Down

0 comments on commit 10d9fe1

Please sign in to comment.