Files
UnrealEngineUWP/Engine/Source/Programs/MemoryProfiler2/BinaryReaderBigEndian.cs
Ben Marsh 149375b14b Update copyright notices to 2015.
[CL 2379638 by Ben Marsh in Main branch]
2014-12-07 19:09:38 -05:00

100 lines
1.9 KiB
C#

/**
* Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
*/
using System;
using System.IO;
namespace MemoryProfiler2
{
/**
* Big endian version of binary reader.
*/
public class BinaryReaderBigEndian : BinaryReader
{
byte[] SwappedBytes = new byte[8];
/**
* Constructor, passing arguments to base class.
*/
public BinaryReaderBigEndian(Stream Input)
: base(Input, System.Text.Encoding.ASCII)
{
}
/**
* Reads & swaps bytes array of size count.
*/
private byte[] ReadSwappedBytes(int Count)
{
for (int i = Count - 1; i >= 0; i--)
{
SwappedBytes[i] = ReadByte();
}
return SwappedBytes;
}
/**
* Reads an UInt16 from stream and returns it.
*/
public override ushort ReadUInt16()
{
return BitConverter.ToUInt16(ReadSwappedBytes(2), 0);
}
/**
* Reads an Int16 from stream and returns it.
*/
public override short ReadInt16()
{
return BitConverter.ToInt16(ReadSwappedBytes(2), 0);
}
/**
* Reads an UInt32 from stream and returns it.
*/
public override int ReadInt32()
{
return BitConverter.ToInt32(ReadSwappedBytes(4), 0);
}
/**
* Reads an Int32 from stream and returns it.
*/
public override uint ReadUInt32()
{
return BitConverter.ToUInt32(ReadSwappedBytes(4), 0);
}
/**
* Reads an UInt64 from stream and returns it.
*/
public override long ReadInt64()
{
return BitConverter.ToInt64(ReadSwappedBytes(8), 0);
}
/**
* Reads an Int64 from stream and returns it.
*/
public override ulong ReadUInt64()
{
return BitConverter.ToUInt64(ReadSwappedBytes(8), 0);
}
/**
* Reads a float from stream and returns it.
*/
public override float ReadSingle()
{
return BitConverter.ToSingle(ReadSwappedBytes(4), 0);
}
/**
* Reads a double from stream and returns it.
*/
public override double ReadDouble()
{
return BitConverter.ToDouble(ReadSwappedBytes(8), 0);
}
}
}