10#ifndef NEWGRF_BYTEREADER_H
11#define NEWGRF_BYTEREADER_H
13#include "../core/string_consumer.hpp"
21 ByteReader(
const uint8_t *data,
size_t len) : consumer(std::string_view{
reinterpret_cast<const char *
>(data), len}) { }
23 const uint8_t *ReadBytes(
size_t size)
25 auto result = this->consumer.
Read(size);
27 return reinterpret_cast<const uint8_t *
>(result.data());
59 return val == 0xFF ? this->
ReadWord() : val;
97 size_t Remaining()
const
102 bool HasData(
size_t count = 1)
const
107 void Skip(
size_t len)
109 auto result = this->consumer.
Read(len);
Class to read from a NewGRF file.
uint32_t PeekDWord()
Read a single DWord (32 bits).
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
std::string_view ReadString()
Read a NUL-terminated string.
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint32_t ReadVarSize(uint8_t size)
Read a value of the given number of bytes.
uint8_t ReadByte()
Read a single byte (8 bits).
Parse data from a string / buffer.
std::optional< uint32_t > TryReadUint32LE()
Try to read binary uint32, and then advance reader.
std::string_view ReadUntilChar(char c, SeparatorUsage sep)
Read data until the first occurrence of 8-bit char 'c', and advance reader.
@ SKIP_ONE_SEPARATOR
Read and discard one separator, do not include it in the result.
std::optional< uint32_t > PeekUint32LE() const
Peek binary uint32 using little endian.
std::optional< uint16_t > TryReadUint16LE()
Try to read binary uint16, and then advance reader.
size_type GetBytesLeft() const noexcept
Get number of bytes left to read.
std::optional< uint8_t > TryReadUint8()
Try to read binary uint8, and then advance reader.
std::string_view Read(size_type len)
Read the next 'len' bytes, and advance reader.