From 15bf2001b5b50abdbedb6bdef1c75edfaf97742e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 21 Sep 2023 22:27:19 -0400 Subject: [PATCH] Add multiple byte reading --- BitStream.cs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/BitStream.cs b/BitStream.cs index 4da6621..c6599eb 100644 --- a/BitStream.cs +++ b/BitStream.cs @@ -59,7 +59,7 @@ namespace SabreTools.Compression public byte? ReadBitLSB() => ReadBitInternal(false); /// - /// Read a full byte, if possible + /// Read a byte, if possible /// /// The next byte, null on error or end of stream public byte? ReadByte() @@ -82,7 +82,7 @@ namespace SabreTools.Compression } /// - /// Read a full UInt16, if possible + /// Read a UInt16, if possible /// /// The next UInt16, null on error or end of stream public ushort? ReadUInt16() @@ -105,7 +105,7 @@ namespace SabreTools.Compression } /// - /// Read a full UInt32, if possible + /// Read a UInt32, if possible /// /// The next UInt32, null on error or end of stream public uint? ReadUInt32() @@ -128,7 +128,7 @@ namespace SabreTools.Compression } /// - /// Read a full UInt64, if possible + /// Read a UInt64, if possible /// /// The next UInt64, null on error or end of stream public ulong? ReadUInt64() @@ -150,6 +150,30 @@ namespace SabreTools.Compression throw new NotImplementedException(); } + /// + /// Read bytes, if possible + /// + /// Number of bytes to read + /// The next paramref name="bytes"/> bytes, null on error or end of stream + public byte[] ReadBytes(int bytes) + { + // If we don't have a value cached + if (_lastRead == null) + { + try + { + return _source.ReadBytes(bytes); + } + catch + { + return null; + } + } + + // Otherwise, assemble the value from the next bits + throw new NotImplementedException(); + } + /// /// Read a single bit, if possible ///