From c306dd6eb98e13b56edb68add002f48ad99d73fb Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 6 Jun 2018 10:00:24 -0400 Subject: [PATCH] feat: Initial commit of IcdBinaryReader --- .../ICD.Common.Utils_SimplSharp.csproj | 1 + ICD.Common.Utils/IO/IcdBinaryReader.cs | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 ICD.Common.Utils/IO/IcdBinaryReader.cs diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 89b8d8a..253c0bd 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -98,6 +98,7 @@ + diff --git a/ICD.Common.Utils/IO/IcdBinaryReader.cs b/ICD.Common.Utils/IO/IcdBinaryReader.cs new file mode 100644 index 0000000..78f9e5e --- /dev/null +++ b/ICD.Common.Utils/IO/IcdBinaryReader.cs @@ -0,0 +1,69 @@ +using System; +#if SIMPLSHARP +using Crestron.SimplSharp.CrestronIO; +#else +using System.IO; +#endif + +namespace ICD.Common.Utils.IO +{ + public sealed class IcdBinaryReader : IDisposable + { + private readonly BinaryReader m_Reader; + + public BinaryReader WrappedReader { get { return m_Reader; } } + + /// + /// Constructor. + /// + /// + public IcdBinaryReader(IcdStream stream) + : this(new BinaryReader(stream.WrappedStream)) + { + } + + /// + /// Constructor. + /// + /// + public IcdBinaryReader(BinaryReader reader) + { + m_Reader = reader; + } + + public void Dispose() + { + m_Reader.Dispose(); + } + + public void Close() + { + m_Reader.Close(); + } + + public ushort ReadUInt16() + { + return m_Reader.ReadUInt16(); + } + + public int ReadInt32() + { + return m_Reader.ReadInt32(); + } + + public short ReadInt16() + { + return m_Reader.ReadInt16(); + } + + public uint ReadUInt32() + { + return m_Reader.ReadUInt32(); + } + + public byte[] ReadBytes(short numberOfBytesToRead) + { + return m_Reader.ReadBytes(numberOfBytesToRead); + } + } +} \ No newline at end of file