From 10d9fe123959a7a673cd3992dda58fd1f905dfda Mon Sep 17 00:00:00 2001 From: Noisrev Date: Mon, 29 Nov 2021 11:20:31 +0800 Subject: [PATCH] Add the GetRType extension --- Noisrev.League.IO.RST/Helper/RTypeHelper.cs | 22 ++++++++++++++++++++ Noisrev.League.IO.RST/Helper/StreamHelper.cs | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Noisrev.League.IO.RST/Helper/RTypeHelper.cs b/Noisrev.League.IO.RST/Helper/RTypeHelper.cs index 72056af..ce803ca 100644 --- a/Noisrev.League.IO.RST/Helper/RTypeHelper.cs +++ b/Noisrev.League.IO.RST/Helper/RTypeHelper.cs @@ -14,5 +14,27 @@ public static ulong ComputeKey(this RType type) { return (1UL << (int)type) - 1; } + /// + /// Gets the specified RType based on version. + /// + /// the version + /// Returns an RType, or null, depending on whether it is a valid version + public static RType? GetRType(this int version) => + ((byte)version).GetRType(); + /// + /// Gets the specified RType based on version. + /// + /// the version + /// Returns an RType, or null, depending on whether it is a valid version + 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; + } } } diff --git a/Noisrev.League.IO.RST/Helper/StreamHelper.cs b/Noisrev.League.IO.RST/Helper/StreamHelper.cs index 302564e..bde4629 100644 --- a/Noisrev.League.IO.RST/Helper/StreamHelper.cs +++ b/Noisrev.League.IO.RST/Helper/StreamHelper.cs @@ -16,7 +16,7 @@ public static class StreamHelper /// BinaryReader /// The offset /// End Byte - /// UTF-8 string + /// Byte Array /// /// /// @@ -36,7 +36,7 @@ public static byte[] ReadBufferWithEndByte(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(); }