diff --git a/SabreTools.IO.Test/Extensions/BinaryReaderExtensionsTests.cs b/SabreTools.IO.Test/Extensions/BinaryReaderExtensionsTests.cs
index b194e72..68030ba 100644
--- a/SabreTools.IO.Test/Extensions/BinaryReaderExtensionsTests.cs
+++ b/SabreTools.IO.Test/Extensions/BinaryReaderExtensionsTests.cs
@@ -153,6 +153,7 @@ namespace SabreTools.IO.Test.Extensions
#endif
// TODO: Add byte[], char[] tests
+ // TODO: Add decimal tests
// TODO: Add string reading tests
}
}
\ No newline at end of file
diff --git a/SabreTools.IO.Test/Extensions/ByteArrayExtensionsTests.cs b/SabreTools.IO.Test/Extensions/ByteArrayExtensionsTests.cs
index e7c236e..2777d8c 100644
--- a/SabreTools.IO.Test/Extensions/ByteArrayExtensionsTests.cs
+++ b/SabreTools.IO.Test/Extensions/ByteArrayExtensionsTests.cs
@@ -244,6 +244,7 @@ namespace SabreTools.IO.Test.Extensions
}
#endif
+ // TODO: Add decimal tests
// TODO: Add string reading tests
}
}
\ No newline at end of file
diff --git a/SabreTools.IO.Test/Extensions/StreamExtensionsTests.cs b/SabreTools.IO.Test/Extensions/StreamExtensionsTests.cs
index 713eb36..2754b05 100644
--- a/SabreTools.IO.Test/Extensions/StreamExtensionsTests.cs
+++ b/SabreTools.IO.Test/Extensions/StreamExtensionsTests.cs
@@ -238,6 +238,7 @@ namespace SabreTools.IO.Test.Extensions
}
#endif
+ // TODO: Add decimal tests
// TODO: Add string reading tests
}
}
\ No newline at end of file
diff --git a/SabreTools.IO/Extensions/ByteArrayExtensions.cs b/SabreTools.IO/Extensions/ByteArrayExtensions.cs
index 519f294..808350b 100644
--- a/SabreTools.IO/Extensions/ByteArrayExtensions.cs
+++ b/SabreTools.IO/Extensions/ByteArrayExtensions.cs
@@ -220,6 +220,38 @@ namespace SabreTools.IO.Extensions
return BitConverter.ToDouble(buffer, 0);
}
+ ///
+ /// Read a Decimal and increment the pointer to an array
+ ///
+ public static decimal ReadDecimal(this byte[] content, ref int offset)
+ {
+ byte[] buffer = ReadToBuffer(content, ref offset, 16);
+
+ int i1 = BitConverter.ToInt32(buffer, 0);
+ int i2 = BitConverter.ToInt32(buffer, 4);
+ int i3 = BitConverter.ToInt32(buffer, 8);
+ int i4 = BitConverter.ToInt32(buffer, 12);
+
+ return new decimal([i1, i2, i3, i4]);
+ }
+
+ ///
+ /// Read a Decimal and increment the pointer to an array
+ ///
+ /// Reads in big-endian format
+ public static decimal ReadDecimalBigEndian(this byte[] content, ref int offset)
+ {
+ byte[] buffer = ReadToBuffer(content, ref offset, 16);
+ Array.Reverse(buffer);
+
+ int i1 = BitConverter.ToInt32(buffer, 0);
+ int i2 = BitConverter.ToInt32(buffer, 4);
+ int i3 = BitConverter.ToInt32(buffer, 8);
+ int i4 = BitConverter.ToInt32(buffer, 12);
+
+ return new decimal([i1, i2, i3, i4]);
+ }
+
///
/// Read a Guid and increment the pointer to an array
///
diff --git a/SabreTools.IO/Extensions/StreamExtensions.cs b/SabreTools.IO/Extensions/StreamExtensions.cs
index 26af225..7b78b49 100644
--- a/SabreTools.IO/Extensions/StreamExtensions.cs
+++ b/SabreTools.IO/Extensions/StreamExtensions.cs
@@ -55,8 +55,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read an Int16 from the stream in big-endian format
+ /// Read an Int16 from the stream
///
+ /// Reads in big-endian format
public static short ReadInt16BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 2);
@@ -74,8 +75,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a UInt16 from the stream in big-endian format
+ /// Read a UInt16 from the stream
///
+ /// Reads in big-endian format
public static ushort ReadUInt16BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 2);
@@ -93,8 +95,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read an Int32 from the stream in big-endian format
+ /// Read an Int32 from the stream
///
+ /// Reads in big-endian format
public static int ReadInt32BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 4);
@@ -112,8 +115,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a UInt32 from the stream in big-endian format
+ /// Read a UInt32 from the stream
///
+ /// Reads in big-endian format
public static uint ReadUInt32BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 4);
@@ -131,8 +135,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a Single from the stream in big-endian format
+ /// Read a Single from the stream
///
+ /// Reads in big-endian format
public static float ReadSingleBigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 4);
@@ -150,8 +155,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read an Int64 from the stream in big-endian format
+ /// Read an Int64 from the stream
///
+ /// Reads in big-endian format
public static long ReadInt64BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 8);
@@ -169,8 +175,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a UInt64 from the stream in big-endian format
+ /// Read a UInt64 from the stream
///
+ /// Reads in big-endian format
public static ulong ReadUInt64BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 8);
@@ -188,8 +195,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a Double from the stream in big-endian format
+ /// Read a Double from the stream
///
+ /// Reads in big-endian format
public static double ReadDoubleBigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 8);
@@ -197,6 +205,38 @@ namespace SabreTools.IO.Extensions
return BitConverter.ToDouble(buffer, 0);
}
+ ///
+ /// Read a Decimal from the stream
+ ///
+ public static decimal ReadDecimal(this Stream stream)
+ {
+ byte[] buffer = ReadToBuffer(stream, 16);
+
+ int i1 = BitConverter.ToInt32(buffer, 0);
+ int i2 = BitConverter.ToInt32(buffer, 4);
+ int i3 = BitConverter.ToInt32(buffer, 8);
+ int i4 = BitConverter.ToInt32(buffer, 12);
+
+ return new decimal([i1, i2, i3, i4]);
+ }
+
+ ///
+ /// Read a Decimal from the stream
+ ///
+ /// Reads in big-endian format
+ public static decimal ReadDecimalBigEndian(this Stream stream)
+ {
+ byte[] buffer = ReadToBuffer(stream, 16);
+ Array.Reverse(buffer);
+
+ int i1 = BitConverter.ToInt32(buffer, 0);
+ int i2 = BitConverter.ToInt32(buffer, 4);
+ int i3 = BitConverter.ToInt32(buffer, 8);
+ int i4 = BitConverter.ToInt32(buffer, 12);
+
+ return new decimal([i1, i2, i3, i4]);
+ }
+
///
/// Read a Guid from the stream
///
@@ -207,8 +247,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a Guid from the stream in big-endian format
+ /// Read a Guid from the stream
///
+ /// Reads in big-endian format
public static Guid ReadGuidBigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 16);
@@ -228,8 +269,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read an Int128 from the stream in big-endian format
+ /// Read an Int128 from the stream
///
+ /// Reads in big-endian format
public static Int128 ReadInt128BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 16);
@@ -247,8 +289,9 @@ namespace SabreTools.IO.Extensions
}
///
- /// Read a UInt128 from the stream in big-endian format
+ /// Read a UInt128 from the stream
///
+ /// Reads in big-endian format
public static UInt128 ReadUInt128BigEndian(this Stream stream)
{
byte[] buffer = ReadToBuffer(stream, 16);