Start allowing larger numeric types for reads

This commit is contained in:
Matt Nadareski
2025-09-25 12:08:22 -04:00
parent 24a69166f0
commit e4a0a08d13
4 changed files with 149 additions and 149 deletions

View File

@@ -30,7 +30,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadByteTest()
{
int offset = 0;
long offset = 0;
byte read = _bytes.ReadByte(ref offset);
Assert.Equal(0x00, read);
}
@@ -38,7 +38,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadByteValueTest()
{
int offset = 0;
long offset = 0;
byte read = _bytes.ReadByteValue(ref offset);
Assert.Equal(0x00, read);
}
@@ -46,16 +46,16 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadBytesTest()
{
int offset = 0, length = 4;
long offset = 0, length = 4;
byte[] read = _bytes.ReadBytes(ref offset, length);
Assert.Equal(length, read.Length);
Assert.True(read.SequenceEqual(_bytes.Take(length)));
Assert.True(read.SequenceEqual(_bytes.Take((int)length)));
}
[Fact]
public void ReadSByteTest()
{
int offset = 0;
long offset = 0;
sbyte read = _bytes.ReadSByte(ref offset);
Assert.Equal(0x00, read);
}
@@ -63,7 +63,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadCharTest()
{
int offset = 0;
long offset = 0;
char read = _bytes.ReadChar(ref offset);
Assert.Equal('\0', read);
}
@@ -71,7 +71,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt16Test()
{
int offset = 0;
long offset = 0;
short read = _bytes.ReadInt16(ref offset);
Assert.Equal(0x0100, read);
}
@@ -79,7 +79,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt16BigEndianTest()
{
int offset = 0;
long offset = 0;
short read = _bytes.ReadInt16BigEndian(ref offset);
Assert.Equal(0x0001, read);
}
@@ -87,7 +87,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt16LittleEndianTest()
{
int offset = 0;
long offset = 0;
short read = _bytes.ReadInt16LittleEndian(ref offset);
Assert.Equal(0x0100, read);
}
@@ -95,7 +95,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt16Test()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadUInt16(ref offset);
Assert.Equal(0x0100, read);
}
@@ -103,7 +103,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt16BigEndianTest()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadUInt16BigEndian(ref offset);
Assert.Equal(0x0001, read);
}
@@ -111,7 +111,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt16LittleEndianTest()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadUInt16LittleEndian(ref offset);
Assert.Equal(0x0100, read);
}
@@ -119,7 +119,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadWORDTest()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadWORD(ref offset);
Assert.Equal(0x0100, read);
}
@@ -127,7 +127,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadWORDBigEndianTest()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadWORDBigEndian(ref offset);
Assert.Equal(0x0001, read);
}
@@ -135,7 +135,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadWORDLittleEndianTest()
{
int offset = 0;
long offset = 0;
ushort read = _bytes.ReadWORDLittleEndian(ref offset);
Assert.Equal(0x0100, read);
}
@@ -143,7 +143,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadHalfTest()
{
int offset = 0;
long offset = 0;
Half expected = BitConverter.Int16BitsToHalf(0x0100);
Half read = _bytes.ReadHalf(ref offset);
Assert.Equal(expected, read);
@@ -152,7 +152,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadHalfBigEndianTest()
{
int offset = 0;
long offset = 0;
Half expected = BitConverter.Int16BitsToHalf(0x0001);
Half read = _bytes.ReadHalfBigEndian(ref offset);
Assert.Equal(expected, read);
@@ -161,7 +161,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt24Test()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt24(ref offset);
Assert.Equal(0x020100, read);
}
@@ -169,7 +169,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt24BigEndianTest()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt24BigEndian(ref offset);
Assert.Equal(0x000102, read);
}
@@ -177,7 +177,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt24LittleEndianTest()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt24LittleEndian(ref offset);
Assert.Equal(0x020100, read);
}
@@ -185,7 +185,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt24Test()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt24(ref offset);
Assert.Equal((uint)0x020100, read);
}
@@ -193,7 +193,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt24BigEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt24BigEndian(ref offset);
Assert.Equal((uint)0x000102, read);
}
@@ -201,7 +201,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt24LittleEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt24LittleEndian(ref offset);
Assert.Equal((uint)0x020100, read);
}
@@ -209,7 +209,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt32Test()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt32(ref offset);
Assert.Equal(0x03020100, read);
}
@@ -217,7 +217,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt32BigEndianTest()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt32BigEndian(ref offset);
Assert.Equal(0x00010203, read);
}
@@ -225,7 +225,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt32LittleEndianTest()
{
int offset = 0;
long offset = 0;
int read = _bytes.ReadInt32LittleEndian(ref offset);
Assert.Equal(0x03020100, read);
}
@@ -233,7 +233,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt32Test()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt32(ref offset);
Assert.Equal((uint)0x03020100, read);
}
@@ -241,7 +241,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt32BigEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt32BigEndian(ref offset);
Assert.Equal((uint)0x00010203, read);
}
@@ -249,7 +249,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt32LittleEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadUInt32LittleEndian(ref offset);
Assert.Equal((uint)0x03020100, read);
}
@@ -257,7 +257,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDWORDTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadDWORD(ref offset);
Assert.Equal((uint)0x03020100, read);
}
@@ -265,7 +265,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDWORDBigEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadDWORDBigEndian(ref offset);
Assert.Equal((uint)0x00010203, read);
}
@@ -273,7 +273,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDWORDLittleEndianTest()
{
int offset = 0;
long offset = 0;
uint read = _bytes.ReadDWORDLittleEndian(ref offset);
Assert.Equal((uint)0x03020100, read);
}
@@ -281,7 +281,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadSingleTest()
{
int offset = 0;
long offset = 0;
float expected = BitConverter.Int32BitsToSingle(0x03020100);
float read = _bytes.ReadSingle(ref offset);
Assert.Equal(expected, read);
@@ -290,7 +290,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadSingleBigEndianTest()
{
int offset = 0;
long offset = 0;
float expected = BitConverter.Int32BitsToSingle(0x00010203);
float read = _bytes.ReadSingleBigEndian(ref offset);
Assert.Equal(expected, read);
@@ -299,7 +299,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt48Test()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt48(ref offset);
Assert.Equal(0x050403020100, read);
}
@@ -307,7 +307,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt48BigEndianTest()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt48BigEndian(ref offset);
Assert.Equal(0x000102030405, read);
}
@@ -315,7 +315,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt48LittleEndianTest()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt48LittleEndian(ref offset);
Assert.Equal(0x050403020100, read);
}
@@ -323,7 +323,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt48Test()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt48(ref offset);
Assert.Equal((ulong)0x050403020100, read);
}
@@ -331,7 +331,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt48BigEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt48BigEndian(ref offset);
Assert.Equal((ulong)0x000102030405, read);
}
@@ -339,7 +339,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt48LittleEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt48LittleEndian(ref offset);
Assert.Equal((ulong)0x050403020100, read);
}
@@ -347,7 +347,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt64Test()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt64(ref offset);
Assert.Equal(0x0706050403020100, read);
}
@@ -355,7 +355,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt64BigEndianTest()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt64BigEndian(ref offset);
Assert.Equal(0x0001020304050607, read);
}
@@ -363,7 +363,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt64LittleEndianTest()
{
int offset = 0;
long offset = 0;
long read = _bytes.ReadInt64LittleEndian(ref offset);
Assert.Equal(0x0706050403020100, read);
}
@@ -371,7 +371,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt64Test()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt64(ref offset);
Assert.Equal((ulong)0x0706050403020100, read);
}
@@ -379,7 +379,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt64BigEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt64BigEndian(ref offset);
Assert.Equal((ulong)0x0001020304050607, read);
}
@@ -387,7 +387,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt64LittleEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadUInt64LittleEndian(ref offset);
Assert.Equal((ulong)0x0706050403020100, read);
}
@@ -395,7 +395,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadQWORDTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadQWORD(ref offset);
Assert.Equal((ulong)0x0706050403020100, read);
}
@@ -403,7 +403,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadQWORDBigEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadQWORDBigEndian(ref offset);
Assert.Equal((ulong)0x0001020304050607, read);
}
@@ -411,7 +411,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadQWORDLittleEndianTest()
{
int offset = 0;
long offset = 0;
ulong read = _bytes.ReadQWORDLittleEndian(ref offset);
Assert.Equal((ulong)0x0706050403020100, read);
}
@@ -419,7 +419,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDoubleTest()
{
int offset = 0;
long offset = 0;
double expected = BitConverter.Int64BitsToDouble(0x0706050403020100);
double read = _bytes.ReadDouble(ref offset);
Assert.Equal(expected, read);
@@ -428,7 +428,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDoubleBigEndianTest()
{
int offset = 0;
long offset = 0;
double expected = BitConverter.Int64BitsToDouble(0x0001020304050607);
double read = _bytes.ReadDoubleBigEndian(ref offset);
Assert.Equal(expected, read);
@@ -437,7 +437,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDecimalTest()
{
int offset = 0;
long offset = 0;
decimal expected = 0.0123456789M;
decimal read = _decimalBytes.ReadDecimal(ref offset);
Assert.Equal(expected, read);
@@ -446,7 +446,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadDecimalBigEndianTest()
{
int offset = 0;
long offset = 0;
decimal expected = 0.0123456789M;
decimal read = _decimalBytes.Reverse().ToArray().ReadDecimalBigEndian(ref offset);
Assert.Equal(expected, read);
@@ -455,7 +455,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadGuidTest()
{
int offset = 0;
long offset = 0;
var expected = new Guid(_bytes);
Guid read = _bytes.ReadGuid(ref offset);
Assert.Equal(expected, read);
@@ -464,7 +464,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadGuidBigEndianTest()
{
int offset = 0;
long offset = 0;
var expected = new Guid(_bytes.Reverse().ToArray());
Guid read = _bytes.ReadGuidBigEndian(ref offset);
Assert.Equal(expected, read);
@@ -473,7 +473,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt128Test()
{
int offset = 0;
long offset = 0;
var expected = (Int128)new BigInteger(_bytes);
Int128 read = _bytes.ReadInt128(ref offset);
Assert.Equal(expected, read);
@@ -482,7 +482,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadInt128BigEndianTest()
{
int offset = 0;
long offset = 0;
var reversed = _bytes.Reverse().ToArray();
var expected = (Int128)new BigInteger(reversed);
Int128 read = _bytes.ReadInt128BigEndian(ref offset);
@@ -492,7 +492,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt128Test()
{
int offset = 0;
long offset = 0;
var expected = (UInt128)new BigInteger(_bytes);
UInt128 read = _bytes.ReadUInt128(ref offset);
Assert.Equal(expected, read);
@@ -501,7 +501,7 @@ namespace SabreTools.IO.Test.Extensions
[Fact]
public void ReadUInt128BigEndianTest()
{
int offset = 0;
long offset = 0;
var reversed = _bytes.Reverse().ToArray();
var expected = (UInt128)new BigInteger(reversed);
UInt128 read = _bytes.ReadUInt128BigEndian(ref offset);
@@ -512,7 +512,7 @@ namespace SabreTools.IO.Test.Extensions
public void ReadNullTerminatedStringTest()
{
// Encoding.ASCII
int offset = 0;
long offset = 0;
byte[] bytes = [0x41, 0x42, 0x43, 0x00];
string? actual = bytes.ReadNullTerminatedString(ref offset, Encoding.ASCII);
Assert.Equal("ABC", actual);
@@ -546,7 +546,7 @@ namespace SabreTools.IO.Test.Extensions
public void ReadTypeTest()
{
// Guid
int offset = 0;
long offset = 0;
var expectedGuid = new Guid(_bytes);
Guid actualGuid = _bytes.ReadType<Guid>(ref offset);
Assert.Equal(expectedGuid, actualGuid);
@@ -585,7 +585,7 @@ namespace SabreTools.IO.Test.Extensions
0x41, 0x42, 0x43, 0x00,
];
int offset = 0;
long offset = 0;
var expected = new TestStructExplicit
{
FirstValue = TestEnum.RecognizedTestValue,
@@ -610,7 +610,7 @@ namespace SabreTools.IO.Test.Extensions
0x08, 0x09, 0x0A, 0x0B, 0x41, 0x42, 0x43, 0x00,
];
int offset = 0;
long offset = 0;
var expected = new TestStructSequential
{
FirstValue = TestEnum.RecognizedTestValue,
@@ -639,7 +639,7 @@ namespace SabreTools.IO.Test.Extensions
0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x00, 0x00, // LPWStr
];
int offset = 0;
long offset = 0;
var expected = new TestStructStrings
{
AnsiBStr = "ABC",
@@ -687,7 +687,7 @@ namespace SabreTools.IO.Test.Extensions
0x00, 0x01, 0x02, 0x03,
];
int offset = 0;
long offset = 0;
var expected = new TestStructArrays
{
ByteArray = [0x00, 0x01, 0x02, 0x03],
@@ -734,7 +734,7 @@ namespace SabreTools.IO.Test.Extensions
0x55, 0xAA, 0x55, 0xAA, // FieldB
];
int offset1 = 0;
long offset1 = 0;
var expected1 = new TestStructInheritanceChild1
{
Signature = [0x41, 0x42, 0x43, 0x44],
@@ -757,7 +757,7 @@ namespace SabreTools.IO.Test.Extensions
0x55, 0xAA, // FieldB
];
int offset2 = 0;
long offset2 = 0;
var expected2 = new TestStructInheritanceChild2
{
Signature = [0x41, 0x42, 0x43, 0x44],

View File

@@ -504,7 +504,7 @@ namespace SabreTools.IO.Extensions
var sb = new StringBuilder();
// Check for strings
int offset = 0;
long offset = 0;
while (offset < bytes.Length)
{
// Read the next character from the stream

View File

@@ -17,7 +17,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a UInt8 and increment the pointer to an array
/// </summary>
public static byte ReadByte(this byte[] content, ref int offset)
public static byte ReadByte(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 1);
return buffer[0];
@@ -26,20 +26,20 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a UInt8 and increment the pointer to an array
/// </summary>
public static byte ReadByteValue(this byte[] content, ref int offset)
public static byte ReadByteValue(this byte[] content, ref long offset)
=> content.ReadByte(ref offset);
/// <summary>
/// Read a UInt8[] and increment the pointer to an array
/// </summary>
public static byte[] ReadBytes(this byte[] content, ref int offset, int count)
public static byte[] ReadBytes(this byte[] content, ref long offset, long count)
=> ReadExactlyToBuffer(content, ref offset, count);
/// <summary>
/// Read a UInt8[] and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static byte[] ReadBytesBigEndian(this byte[] content, ref int offset, int count)
public static byte[] ReadBytesBigEndian(this byte[] content, ref long offset, long count)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, count);
Array.Reverse(buffer);
@@ -49,7 +49,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read an Int8 and increment the pointer to an array
/// </summary>
public static sbyte ReadSByte(this byte[] content, ref int offset)
public static sbyte ReadSByte(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 1);
return (sbyte)buffer[0];
@@ -58,7 +58,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a Char and increment the pointer to an array
/// </summary>
public static char ReadChar(this byte[] content, ref int offset)
public static char ReadChar(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 1);
return (char)buffer[0];
@@ -68,7 +68,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static short ReadInt16(this byte[] content, ref int offset)
public static short ReadInt16(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadInt16LittleEndian(ref offset);
@@ -80,7 +80,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static short ReadInt16BigEndian(this byte[] content, ref int offset)
public static short ReadInt16BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
return (short)(buffer[1]
@@ -91,7 +91,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static short ReadInt16LittleEndian(this byte[] content, ref int offset)
public static short ReadInt16LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
return (short)(buffer[0]
@@ -102,7 +102,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static ushort ReadUInt16(this byte[] content, ref int offset)
public static ushort ReadUInt16(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadUInt16LittleEndian(ref offset);
@@ -114,7 +114,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static ushort ReadUInt16BigEndian(this byte[] content, ref int offset)
public static ushort ReadUInt16BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
return (ushort)(buffer[1]
@@ -125,7 +125,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt16 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static ushort ReadUInt16LittleEndian(this byte[] content, ref int offset)
public static ushort ReadUInt16LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
return (ushort)(buffer[0]
@@ -136,21 +136,21 @@ namespace SabreTools.IO.Extensions
/// Read a WORD (2-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static ushort ReadWORD(this byte[] content, ref int offset)
public static ushort ReadWORD(this byte[] content, ref long offset)
=> content.ReadUInt16(ref offset);
/// <summary>
/// Read a WORD (2-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static ushort ReadWORDBigEndian(this byte[] content, ref int offset)
public static ushort ReadWORDBigEndian(this byte[] content, ref long offset)
=> content.ReadUInt16BigEndian(ref offset);
/// <summary>
/// Read a WORD (2-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static ushort ReadWORDLittleEndian(this byte[] content, ref int offset)
public static ushort ReadWORDLittleEndian(this byte[] content, ref long offset)
=> content.ReadUInt16LittleEndian(ref offset);
// Half was introduced in net5.0 but doesn't have a BitConverter implementation until net6.0
@@ -159,7 +159,7 @@ namespace SabreTools.IO.Extensions
/// Read a Half and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static Half ReadHalf(this byte[] content, ref int offset)
public static Half ReadHalf(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
return BitConverter.ToHalf(buffer, 0);
@@ -169,7 +169,7 @@ namespace SabreTools.IO.Extensions
/// Read a Half and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static Half ReadHalfBigEndian(this byte[] content, ref int offset)
public static Half ReadHalfBigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 2);
Array.Reverse(buffer);
@@ -181,7 +181,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int24 encoded as an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static int ReadInt24(this byte[] content, ref int offset)
public static int ReadInt24(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadInt24LittleEndian(ref offset);
@@ -193,7 +193,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int24 encoded as an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static int ReadInt24BigEndian(this byte[] content, ref int offset)
public static int ReadInt24BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 3);
return (int)(buffer[2]
@@ -205,7 +205,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int24 encoded as an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static int ReadInt24LittleEndian(this byte[] content, ref int offset)
public static int ReadInt24LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 3);
return (int)(buffer[0]
@@ -217,7 +217,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt24 encoded as a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static uint ReadUInt24(this byte[] content, ref int offset)
public static uint ReadUInt24(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadUInt24LittleEndian(ref offset);
@@ -229,7 +229,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt24 encoded as a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static uint ReadUInt24BigEndian(this byte[] content, ref int offset)
public static uint ReadUInt24BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 3);
return (uint)(buffer[2]
@@ -241,7 +241,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt24 encoded as a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static uint ReadUInt24LittleEndian(this byte[] content, ref int offset)
public static uint ReadUInt24LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 3);
return (uint)(buffer[0]
@@ -253,7 +253,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static int ReadInt32(this byte[] content, ref int offset)
public static int ReadInt32(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadInt32LittleEndian(ref offset);
@@ -265,7 +265,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static int ReadInt32BigEndian(this byte[] content, ref int offset)
public static int ReadInt32BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
return (int)(buffer[3]
@@ -278,7 +278,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static int ReadInt32LittleEndian(this byte[] content, ref int offset)
public static int ReadInt32LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
return (int)(buffer[0]
@@ -291,7 +291,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static uint ReadUInt32(this byte[] content, ref int offset)
public static uint ReadUInt32(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadUInt32LittleEndian(ref offset);
@@ -303,7 +303,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static uint ReadUInt32BigEndian(this byte[] content, ref int offset)
public static uint ReadUInt32BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
return (uint)(buffer[3]
@@ -316,7 +316,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt32 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static uint ReadUInt32LittleEndian(this byte[] content, ref int offset)
public static uint ReadUInt32LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
return (uint)(buffer[0]
@@ -329,28 +329,28 @@ namespace SabreTools.IO.Extensions
/// Read a DWORD (4-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static uint ReadDWORD(this byte[] content, ref int offset)
public static uint ReadDWORD(this byte[] content, ref long offset)
=> content.ReadUInt32(ref offset);
/// <summary>
/// Read a DWORD (4-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static uint ReadDWORDBigEndian(this byte[] content, ref int offset)
public static uint ReadDWORDBigEndian(this byte[] content, ref long offset)
=> content.ReadUInt32BigEndian(ref offset);
/// <summary>
/// Read a DWORD (4-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static uint ReadDWORDLittleEndian(this byte[] content, ref int offset)
public static uint ReadDWORDLittleEndian(this byte[] content, ref long offset)
=> content.ReadUInt32LittleEndian(ref offset);
/// <summary>
/// Read a Single and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static float ReadSingle(this byte[] content, ref int offset)
public static float ReadSingle(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
return BitConverter.ToSingle(buffer, 0);
@@ -360,7 +360,7 @@ namespace SabreTools.IO.Extensions
/// Read a Single and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static float ReadSingleBigEndian(this byte[] content, ref int offset)
public static float ReadSingleBigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 4);
Array.Reverse(buffer);
@@ -371,7 +371,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int48 encoded as an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static long ReadInt48(this byte[] content, ref int offset)
public static long ReadInt48(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadInt48LittleEndian(ref offset);
@@ -383,7 +383,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int48 encoded as an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static long ReadInt48BigEndian(this byte[] content, ref int offset)
public static long ReadInt48BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 6);
return ((long)buffer[5] << 0)
@@ -398,7 +398,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int48 encoded as an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static long ReadInt48LittleEndian(this byte[] content, ref int offset)
public static long ReadInt48LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 6);
return ((long)buffer[0] << 0)
@@ -413,7 +413,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt48 encoded as a UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static ulong ReadUInt48(this byte[] content, ref int offset)
public static ulong ReadUInt48(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadUInt48LittleEndian(ref offset);
@@ -425,7 +425,7 @@ namespace SabreTools.IO.Extensions
/// Read an UInt48 encoded as an UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static ulong ReadUInt48BigEndian(this byte[] content, ref int offset)
public static ulong ReadUInt48BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 6);
return ((ulong)buffer[5] << 0)
@@ -440,7 +440,7 @@ namespace SabreTools.IO.Extensions
/// Read an UInt48 encoded as an UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static ulong ReadUInt48LittleEndian(this byte[] content, ref int offset)
public static ulong ReadUInt48LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 6);
return ((ulong)buffer[0] << 0)
@@ -455,7 +455,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static long ReadInt64(this byte[] content, ref int offset)
public static long ReadInt64(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadInt64LittleEndian(ref offset);
@@ -467,7 +467,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static long ReadInt64BigEndian(this byte[] content, ref int offset)
public static long ReadInt64BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
return ((long)buffer[7] << 0)
@@ -484,7 +484,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static long ReadInt64LittleEndian(this byte[] content, ref int offset)
public static long ReadInt64LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
return ((long)buffer[0] << 0)
@@ -501,7 +501,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static ulong ReadUInt64(this byte[] content, ref int offset)
public static ulong ReadUInt64(this byte[] content, ref long offset)
{
if (BitConverter.IsLittleEndian)
return content.ReadUInt64LittleEndian(ref offset);
@@ -513,7 +513,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static ulong ReadUInt64BigEndian(this byte[] content, ref int offset)
public static ulong ReadUInt64BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
return ((ulong)buffer[7] << 0)
@@ -530,7 +530,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt64 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static ulong ReadUInt64LittleEndian(this byte[] content, ref int offset)
public static ulong ReadUInt64LittleEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
return ((ulong)buffer[0] << 0)
@@ -547,28 +547,28 @@ namespace SabreTools.IO.Extensions
/// Read a QWORD (8-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static ulong ReadQWORD(this byte[] content, ref int offset)
public static ulong ReadQWORD(this byte[] content, ref long offset)
=> content.ReadUInt64(ref offset);
/// <summary>
/// Read a QWORD (8-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static ulong ReadQWORDBigEndian(this byte[] content, ref int offset)
public static ulong ReadQWORDBigEndian(this byte[] content, ref long offset)
=> content.ReadUInt64BigEndian(ref offset);
/// <summary>
/// Read a QWORD (8-byte) and increment the pointer to an array
/// </summary>
/// <remarks>Reads in little-endian format</remarks>
public static ulong ReadQWORDLittleEndian(this byte[] content, ref int offset)
public static ulong ReadQWORDLittleEndian(this byte[] content, ref long offset)
=> content.ReadUInt64LittleEndian(ref offset);
/// <summary>
/// Read a Double and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static double ReadDouble(this byte[] content, ref int offset)
public static double ReadDouble(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
return BitConverter.ToDouble(buffer, 0);
@@ -578,7 +578,7 @@ namespace SabreTools.IO.Extensions
/// Read a Double and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static double ReadDoubleBigEndian(this byte[] content, ref int offset)
public static double ReadDoubleBigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 8);
Array.Reverse(buffer);
@@ -589,7 +589,7 @@ namespace SabreTools.IO.Extensions
/// Read a Decimal and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static decimal ReadDecimal(this byte[] content, ref int offset)
public static decimal ReadDecimal(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
@@ -605,7 +605,7 @@ namespace SabreTools.IO.Extensions
/// Read a Decimal and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static decimal ReadDecimalBigEndian(this byte[] content, ref int offset)
public static decimal ReadDecimalBigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
Array.Reverse(buffer);
@@ -622,7 +622,7 @@ namespace SabreTools.IO.Extensions
/// Read a Guid and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static Guid ReadGuid(this byte[] content, ref int offset)
public static Guid ReadGuid(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
return new Guid(buffer);
@@ -632,7 +632,7 @@ namespace SabreTools.IO.Extensions
/// Read a Guid and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static Guid ReadGuidBigEndian(this byte[] content, ref int offset)
public static Guid ReadGuidBigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
Array.Reverse(buffer);
@@ -644,7 +644,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int128 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static Int128 ReadInt128(this byte[] content, ref int offset)
public static Int128 ReadInt128(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
return (Int128)new BigInteger(buffer);
@@ -654,7 +654,7 @@ namespace SabreTools.IO.Extensions
/// Read an Int128 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static Int128 ReadInt128BigEndian(this byte[] content, ref int offset)
public static Int128 ReadInt128BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
Array.Reverse(buffer);
@@ -665,7 +665,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt128 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in machine native format</remarks>
public static UInt128 ReadUInt128(this byte[] content, ref int offset)
public static UInt128 ReadUInt128(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
return (UInt128)new BigInteger(buffer);
@@ -675,7 +675,7 @@ namespace SabreTools.IO.Extensions
/// Read a UInt128 and increment the pointer to an array
/// </summary>
/// <remarks>Reads in big-endian format</remarks>
public static UInt128 ReadUInt128BigEndian(this byte[] content, ref int offset)
public static UInt128 ReadUInt128BigEndian(this byte[] content, ref long offset)
{
byte[] buffer = ReadExactlyToBuffer(content, ref offset, 16);
Array.Reverse(buffer);
@@ -686,7 +686,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a null-terminated string from the array
/// </summary>
public static string? ReadNullTerminatedString(this byte[] content, ref int offset, Encoding encoding)
public static string? ReadNullTerminatedString(this byte[] content, ref long offset, Encoding encoding)
{
// Short-circuit to explicit implementations
if (encoding.Equals(Encoding.ASCII))
@@ -717,7 +717,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a null-terminated ASCII string from the byte array
/// </summary>
public static string? ReadNullTerminatedAnsiString(this byte[] content, ref int offset)
public static string? ReadNullTerminatedAnsiString(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -729,7 +729,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a null-terminated UTF-8 string from the byte array
/// </summary>
public static string? ReadNullTerminatedUTF8String(this byte[] content, ref int offset)
public static string? ReadNullTerminatedUTF8String(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -741,7 +741,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a null-terminated UTF-16 (Unicode) string from the byte array
/// </summary>
public static string? ReadNullTerminatedUnicodeString(this byte[] content, ref int offset)
public static string? ReadNullTerminatedUnicodeString(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -753,7 +753,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a null-terminated UTF-32 string from the byte array
/// </summary>
public static string? ReadNullTerminatedUTF32String(this byte[] content, ref int offset)
public static string? ReadNullTerminatedUTF32String(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -765,7 +765,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a byte-prefixed ASCII string from the byte array
/// </summary>
public static string? ReadPrefixedAnsiString(this byte[] content, ref int offset)
public static string? ReadPrefixedAnsiString(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -781,7 +781,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a ushort-prefixed Unicode string from the byte array
/// </summary>
public static string? ReadPrefixedUnicodeString(this byte[] content, ref int offset)
public static string? ReadPrefixedUnicodeString(this byte[] content, ref long offset)
{
if (offset >= content.Length)
return null;
@@ -805,7 +805,7 @@ namespace SabreTools.IO.Extensions
/// - Arrays of the above are handled sequentially as above
/// - Inherited fields from parents are deserialized BEFORE fields in the child
/// </remarks>
public static T? ReadType<T>(this byte[] content, ref int offset)
public static T? ReadType<T>(this byte[] content, ref long offset)
=> (T?)content.ReadType(ref offset, typeof(T));
/// <summary>
@@ -819,7 +819,7 @@ namespace SabreTools.IO.Extensions
/// - Arrays of the above are handled sequentially as above
/// - Inherited fields from parents are deserialized BEFORE fields in the child
/// </remarks>
public static object? ReadType(this byte[] content, ref int offset, Type type)
public static object? ReadType(this byte[] content, ref long offset, Type type)
{
// Handle special struct cases
if (type == typeof(Guid))
@@ -846,7 +846,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a <paramref name="type"/> from the stream
/// </summary>
private static object? ReadNormalType(byte[] content, ref int offset, Type type)
private static object? ReadNormalType(byte[] content, ref long offset, Type type)
{
try
{
@@ -868,7 +868,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a <paramref name="type"/> from the stream
/// </summary>
private static object? ReadComplexType(byte[] content, ref int offset, Type type)
private static object? ReadComplexType(byte[] content, ref long offset, Type type)
{
try
{
@@ -883,7 +883,7 @@ namespace SabreTools.IO.Extensions
Encoding encoding = MarshalHelpers.DetermineEncoding(layoutAttr);
// Cache the current offset
int currentOffset = offset;
long currentOffset = offset;
// Generate the fields by parent first
var fields = MarshalHelpers.GetFields(type);
@@ -912,7 +912,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Set a single field on an object
/// </summary>
private static void SetField(byte[] content, ref int offset, Encoding encoding, FieldInfo[] fields, object instance, FieldInfo fi)
private static void SetField(byte[] content, ref long offset, Encoding encoding, FieldInfo[] fields, object instance, FieldInfo fi)
{
if (fi.FieldType.IsAssignableFrom(typeof(string)))
{
@@ -937,7 +937,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read an array type field for an object
/// </summary>
private static Array ReadArrayType(byte[] content, ref int offset, FieldInfo[] fields, object instance, FieldInfo fi)
private static Array ReadArrayType(byte[] content, ref long offset, FieldInfo[] fields, object instance, FieldInfo fi)
{
var marshalAsAttr = MarshalHelpers.GetAttribute<MarshalAsAttribute>(fi);
if (marshalAsAttr == null)
@@ -969,7 +969,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a string type field for an object
/// </summary>
private static string? ReadStringType(byte[] content, ref int offset, Encoding encoding, object instance, FieldInfo fi)
private static string? ReadStringType(byte[] content, ref long offset, Encoding encoding, object instance, FieldInfo fi)
{
var marshalAsAttr = MarshalHelpers.GetAttribute<MarshalAsAttribute>(fi);
@@ -1009,7 +1009,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read bytes until a 1-byte null terminator is found
/// </summary>
private static byte[] ReadUntilNull1Byte(byte[] content, ref int offset)
private static byte[] ReadUntilNull1Byte(byte[] content, ref long offset)
{
var bytes = new List<byte>();
while (offset < content.Length)
@@ -1027,7 +1027,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read bytes until a 2-byte null terminator is found
/// </summary>
private static byte[] ReadUntilNull2Byte(byte[] content, ref int offset)
private static byte[] ReadUntilNull2Byte(byte[] content, ref long offset)
{
var bytes = new List<byte>();
while (offset < content.Length)
@@ -1045,7 +1045,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read bytes until a 4-byte null terminator is found
/// </summary>
private static byte[] ReadUntilNull4Byte(byte[] content, ref int offset)
private static byte[] ReadUntilNull4Byte(byte[] content, ref long offset)
{
var bytes = new List<byte>();
while (offset < content.Length)
@@ -1063,7 +1063,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a number of bytes from the byte array to a buffer
/// </summary>
private static byte[] ReadExactlyToBuffer(byte[] content, ref int offset, int length)
private static byte[] ReadExactlyToBuffer(byte[] content, ref long offset, long length)
{
// If we have an invalid offset
if (offset < 0 || offset >= content.Length)

View File

@@ -27,7 +27,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a UInt8[] from the stream
/// </summary>
public static byte[] ReadBytes(this Stream stream, int count)
public static byte[] ReadBytes(this Stream stream, long count)
=> ReadExactlyToBuffer(stream, count);
/// <summary>
@@ -1047,7 +1047,7 @@ namespace SabreTools.IO.Extensions
/// <summary>
/// Read a number of bytes from the stream to a buffer
/// </summary>
private static byte[] ReadExactlyToBuffer(Stream stream, int length)
private static byte[] ReadExactlyToBuffer(Stream stream, long length)
{
// If we have an invalid length
if (length < 0)
@@ -1059,7 +1059,7 @@ namespace SabreTools.IO.Extensions
// Handle the general case, forcing a read of the correct length
byte[] buffer = new byte[length];
int read = stream.Read(buffer, 0, length);
int read = stream.Read(buffer, 0, (int)Math.Min(length, int.MaxValue));
if (read < length)
throw new EndOfStreamException($"Requested to read {length} bytes from {nameof(stream)}, {read} returned");