DiscIO: Unify CBlobBigEndianReader

This commit is contained in:
JosJuice
2015-10-03 13:42:26 +02:00
parent c7e747d775
commit c01265db34
3 changed files with 31 additions and 43 deletions

View File

@ -17,6 +17,7 @@
#include <array>
#include <memory>
#include <string>
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
namespace DiscIO
@ -77,6 +78,36 @@ private:
std::array<u64, CACHE_SIZE> m_cache_tags;
};
class CBlobBigEndianReader
{
public:
CBlobBigEndianReader(IBlobReader& reader) : m_reader(reader) {}
u32 Read32(u64 offset) const
{
u32 temp;
m_reader.Read(offset, sizeof(u32), reinterpret_cast<u8*>(&temp));
return Common::swap32(temp);
}
u16 Read16(u64 offset) const
{
u16 temp;
m_reader.Read(offset, sizeof(u16), reinterpret_cast<u8*>(&temp));
return Common::swap16(temp);
}
u8 Read8(u64 offset) const
{
u8 temp;
m_reader.Read(offset, sizeof(u8), &temp);
return temp;
}
private:
IBlobReader& m_reader;
};
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename);