From b8e15fbe40ee6aa60df58b27736e16417a926d45 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 18 Nov 2019 23:25:25 +0100 Subject: [PATCH] Move FastByteReader from LCW to own file And make it public. Making it easier to move formats that depend on it to Mods.Cnc independently later. --- .../FileFormats/FastByteReader.cs | 43 +++++++++++++++++++ .../FileFormats/LCWCompression.cs | 28 ------------ 2 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 OpenRA.Mods.Common/FileFormats/FastByteReader.cs diff --git a/OpenRA.Mods.Common/FileFormats/FastByteReader.cs b/OpenRA.Mods.Common/FileFormats/FastByteReader.cs new file mode 100644 index 0000000000..2de20c10d3 --- /dev/null +++ b/OpenRA.Mods.Common/FileFormats/FastByteReader.cs @@ -0,0 +1,43 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Mods.Common.FileFormats +{ + public class FastByteReader + { + readonly byte[] src; + int offset; + + public FastByteReader(byte[] src, int offset = 0) + { + this.src = src; + this.offset = offset; + } + + public bool Done() { return offset >= src.Length; } + public byte ReadByte() { return src[offset++]; } + public int ReadWord() + { + var x = ReadByte(); + return x | (ReadByte() << 8); + } + + public void CopyTo(byte[] dest, int offset, int count) + { + Array.Copy(src, this.offset, dest, offset, count); + this.offset += count; + } + + public int Remaining() { return src.Length - offset; } + } +} diff --git a/OpenRA.Mods.Common/FileFormats/LCWCompression.cs b/OpenRA.Mods.Common/FileFormats/LCWCompression.cs index 0a3450e66e..78cbeb0b71 100644 --- a/OpenRA.Mods.Common/FileFormats/LCWCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/LCWCompression.cs @@ -14,34 +14,6 @@ using System.IO; namespace OpenRA.Mods.Common.FileFormats { - class FastByteReader - { - readonly byte[] src; - int offset; - - public FastByteReader(byte[] src, int offset = 0) - { - this.src = src; - this.offset = offset; - } - - public bool Done() { return offset >= src.Length; } - public byte ReadByte() { return src[offset++]; } - public int ReadWord() - { - var x = ReadByte(); - return x | (ReadByte() << 8); - } - - public void CopyTo(byte[] dest, int offset, int count) - { - Array.Copy(src, this.offset, dest, offset, count); - this.offset += count; - } - - public int Remaining() { return src.Length - offset; } - } - // Lempel - Castle - Welch algorithm (aka Format80) public static class LCWCompression {