OpenTTD Source: ByteReader Class Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Private Attributes
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()

uint8_t ByteReader::ReadByte | ( |  | ) |
| inline

Read a single byte (8 bits).

Returns
  Value read from buffer.

Definition at line 34 of file newgrf_bytereader.h.

References StringConsumer::TryReadUint8().

Referenced by AircraftVehicleChangeInfo(), AirportChangeInfo(), CanalChangeInfo(), CargoReserveInfo(), ChangeGRFBlitter(), ChangeGRFNumUsedParams(), ChangeGRFPalette(), ChangeGRFParamMask(), ChangeGRFParamType(), ChangeGRFParamValueNames(), CommonVehicleChangeInfo(), DefineGotoLabel(), FeatureTownName(), GlobalVarChangeInfo(), HandleNode(), HandleNodes(), HandleParameterInfo(), IgnoreIndustryProperty(), IgnoreIndustryTileProperty(), IgnoreObjectProperty(), IgnoreRoadStopProperty(), IgnoreTownHouseProperty(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), LoadFontGlyph(), ObjectChangeInfo(), ParamSet(), RailTypeChangeInfo(), RailVehicleChangeInfo(), ReadDWordAsString(), ReadExtendedByte(), ReadSpriteLayout(), ReadSpriteLayoutRegisters(), ReadVarSize(), RoadTypeChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), SkipAct12(), SkipUnknownInfo(), SoundEffectChangeInfo(), StationChangeInfo(), TownHouseChangeInfo(), and TranslateGRFStrings().

## ◆ ReadBytes()

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

Definition at line 23 of file newgrf_bytereader.h.

## ◆ ReadDWord()

uint32_t ByteReader::ReadDWord | ( |  | ) |
| inline

Read a single DWord (32 bits).

Returns
  Value read from buffer.

Definition at line 66 of file newgrf_bytereader.h.

References StringConsumer::TryReadUint32LE().

Referenced by AircraftVehicleChangeInfo(), AirportChangeInfo(), CargoReserveInfo(), ChangeGRFMinVersion(), ChangeGRFParamDefault(), ChangeGRFParamLimits(), ChangeGRFParamValueNames(), ChangeGRFVersion(), GlobalVarChangeInfo(), HandleNodes(), HandleParameterInfo(), IgnoreIndustryProperty(), IgnoreObjectProperty(), IgnoreRoadStopProperty(), IgnoreTownHouseProperty(), IndustriesChangeInfo(), LoadTranslationTable(), ObjectChangeInfo(), ParamSet(), RailTypeChangeInfo(), RailVehicleChangeInfo(), ReadVarSize(), RoadTypeChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), SkipUnknownInfo(), StationChangeInfo(), TownHouseChangeInfo(), and TranslateGRFStrings().

## ◆ 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(), IgnoreRoadStopProperty(), 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 20 of file newgrf_bytereader.cpp.

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

## ◆ ReadWord()

uint16_t ByteReader::ReadWord | ( |  | ) |
| inline

Read a single Word (16 bits).

Returns
  Value read from buffer.

Definition at line 45 of file newgrf_bytereader.h.

References StringConsumer::TryReadUint16LE().

Referenced by AircraftVehicleChangeInfo(), AirportChangeInfo(), CargoReserveInfo(), CommonVehicleChangeInfo(), GlobalVarChangeInfo(), HandleNode(), IgnoreIndustryProperty(), IgnoreIndustryTileProperty(), IgnoreObjectProperty(), IgnoreRoadStopProperty(), IgnoreTownHouseProperty(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), LoadFontGlyph(), ObjectChangeInfo(), RailTypeChangeInfo(), RailVehicleChangeInfo(), ReadBadgeList(), ReadExtendedByte(), ReadSpriteLayoutSprite(), ReadVarSize(), RoadTypeChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), SkipAct12(), SkipBadgeList(), SkipUnknownInfo(), StationChangeInfo(), TownHouseChangeInfo(), and TranslateGRFStrings().

## ◆ 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:

- src/newgrf/newgrf_bytereader.h
- src/newgrf/newgrf_bytereader.cpp