OpenTTD Source 20250428-master-g68ba2735ea
ByteReader Class Reference

Class to read from a NewGRF file. More...

#include <newgrf_bytereader.h>

Public Member Functions

 ByteReader (const uint8_t *data, size_t len)
 
const uint8_t * ReadBytes (size_t size)
 
uint8_t ReadByte ()
 Read a single byte (8 bits).
 
uint16_t ReadWord ()
 Read a single Word (16 bits).
 
uint16_t ReadExtendedByte ()
 Read a single Extended Byte (8 or 16 bits).
 
uint32_t ReadDWord ()
 Read a single DWord (32 bits).
 
uint32_t PeekDWord ()
 Read a single DWord (32 bits).
 
uint32_t ReadVarSize (uint8_t size)
 Read a value of the given number of bytes.
 
std::string_view ReadString ()
 Read a NUL-terminated string.
 
size_t Remaining () const
 
bool HasData (size_t count=1) const
 
void Skip (size_t len)
 

Private Attributes

StringConsumer consumer
 

Detailed Description

Class to read from a NewGRF file.

Definition at line 18 of file newgrf_bytereader.h.

Constructor & Destructor Documentation

◆ ByteReader()

ByteReader::ByteReader ( const uint8_t *  data,
size_t  len 
)
inline

Definition at line 21 of file newgrf_bytereader.h.

Member Function Documentation

◆ HasData()

bool ByteReader::HasData ( size_t  count = 1) const
inline

Definition at line 102 of file newgrf_bytereader.h.

◆ PeekDWord()

uint32_t ByteReader::PeekDWord ( )
inline

Read a single DWord (32 bits).

Note
The buffer is NOT advanced.
Returns
Value read from buffer.

Definition at line 78 of file newgrf_bytereader.h.

References StringConsumer::PeekUint32LE().

Referenced by StationChangeInfo().

◆ ReadByte()

◆ ReadBytes()

const uint8_t * ByteReader::ReadBytes ( size_t  size)
inline

Definition at line 23 of file newgrf_bytereader.h.

◆ ReadDWord()

◆ ReadExtendedByte()

uint16_t ByteReader::ReadExtendedByte ( )
inline

Read a single Extended Byte (8 or 16 bits).

Returns
Value read from buffer.

Definition at line 56 of file newgrf_bytereader.h.

References ReadByte(), and ReadWord().

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and StationChangeInfo().

◆ ReadString()

std::string_view ByteReader::ReadString ( )
inline

Read a NUL-terminated string.

Returns
String read from the buffer.

Definition at line 91 of file newgrf_bytereader.h.

References StringConsumer::ReadUntilChar(), and StringConsumer::SKIP_ONE_SEPARATOR.

Referenced by ChangeGRFParamValueNames(), FeatureTownName(), GlobalVarChangeInfo(), HandleNode(), SkipUnknownInfo(), and TranslateGRFStrings().

◆ ReadVarSize()

uint32_t ByteReader::ReadVarSize ( uint8_t  size)

Read a value of the given number of bytes.

Returns
Value read from buffer.

Definition at line 21 of file newgrf_bytereader.cpp.

References ReadByte(), ReadDWord(), and ReadWord().

◆ ReadWord()

◆ Remaining()

size_t ByteReader::Remaining ( ) const
inline

Definition at line 97 of file newgrf_bytereader.h.

◆ Skip()

void ByteReader::Skip ( size_t  len)
inline

Definition at line 107 of file newgrf_bytereader.h.

Field Documentation

◆ consumer

StringConsumer ByteReader::consumer
private

Definition at line 19 of file newgrf_bytereader.h.


The documentation for this class was generated from the following files: