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.
This commit is contained in:
43
OpenRA.Mods.Common/FileFormats/FastByteReader.cs
Normal file
43
OpenRA.Mods.Common/FileFormats/FastByteReader.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,34 +14,6 @@ using System.IO;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.FileFormats
|
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)
|
// Lempel - Castle - Welch algorithm (aka Format80)
|
||||||
public static class LCWCompression
|
public static class LCWCompression
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user