44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright (c) The OpenRA Developers and Contributors
|
|
* 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; }
|
|
}
|
|
}
|