41 static constexpr bool m_kNeedsSwap = std::endian::native != std::endian::little;
55 "Seek past end of file: offset %zu exceeds file size %zu", aPos,
m_size ) );
66 "Skip past end of file at offset %zu",
m_pos ) );
85 "Failed to read requested %zu bytes at offset %zu (file size %zu)",
97 static_assert( std::is_fundamental_v<T>,
"Read() only works for fundamental types" );
115 "ReadString at invalid offset %zu (file size %zu)",
m_pos,
m_size ) );
123 "Unterminated string at offset %zu",
m_pos ) );
126 const uint8_t*
end =
static_cast<const uint8_t*
>( found );
130 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
132 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
144 "Failed to read fixed string of %zu bytes at offset %zu (file size %zu)",
148 const char* start =
reinterpret_cast<const char*
>(
m_data +
m_pos );
149 size_t strLen = strnlen( start, aLen );
150 std::string str( start, strLen );
153 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
155 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
181 template <
typename T>
184 char* bytes =
reinterpret_cast<char*
>( &value );
185 std::reverse( bytes, bytes +
sizeof(
T ) );
static constexpr bool m_kNeedsSwap
void ReadBytes(void *aDest, size_t aSize)
Read a number of bytes from the stream into the destination buffer.
FILE_STREAM(const uint8_t *aData, size_t aSize)
std::string ReadString(bool aRoundToNextU32)
bool GetU8(uint8_t &value)
static void swapBytes(T &value)
std::string ReadStringFixed(size_t aLen, bool aRoundToNextU32)
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE