41 static constexpr bool m_kNeedsSwap = std::endian::native != std::endian::little;
57 "Seek past end of file: offset %zu exceeds file size %zu", aPos,
m_size ) );
68 "Skip past end of file at offset %zu",
m_pos ) );
87 "Failed to read requested %zu bytes at offset %zu (file size %zu)",
99 static_assert( std::is_fundamental_v<T>,
"Read() only works for fundamental types" );
117 "ReadString at invalid offset %zu (file size %zu)",
m_pos,
m_size ) );
125 "Unterminated string at offset %zu",
m_pos ) );
128 const uint8_t*
end =
static_cast<const uint8_t*
>( found );
132 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
134 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
146 "Failed to read fixed string of %zu bytes at offset %zu (file size %zu)",
150 const char* start =
reinterpret_cast<const char*
>(
m_data +
m_pos );
151 size_t strLen = strnlen( start, aLen );
152 std::string str( start, strLen );
155 if( aRoundToNextU32 &&
m_pos %
sizeof( uint32_t ) != 0 )
157 const size_t padding =
sizeof( uint32_t ) - (
m_pos %
sizeof( uint32_t ) );
183 template <
typename T>
186 char* bytes =
reinterpret_cast<char*
>( &value );
187 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