45 static constexpr bool m_kNeedsSwap = std::endian::native != std::endian::little;
59 "Seek past end of file: offset %zu exceeds file size %zu", aPos,
m_size ) );
70 "Skip past end of file at offset %zu",
m_pos ) );
89 "Failed to read requested %zu bytes at offset %zu (file size %zu)",
101 static_assert( std::is_fundamental_v<T>,
"Read() only works for fundamental types" );
119 "ReadString at invalid offset %zu (file size %zu)",
m_pos,
m_size ) );
127 "Unterminated string at offset %zu",
m_pos ) );
130 const uint8_t*
end =
static_cast<const uint8_t*
>( found );
134 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
136 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
148 "Failed to read fixed string of %zu bytes at offset %zu (file size %zu)",
152 const char* start =
reinterpret_cast<const char*
>(
m_data +
m_pos );
153 size_t strLen = strnlen( start, aLen );
154 std::string str( start, strLen );
157 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
159 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
185 template <
typename T>
188 char* bytes =
reinterpret_cast<char*
>( &value );
189 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