OpenTTD Source 20250312-master-gcdcc6b491d
|
Owning byte buffer readable as a stream. More...
Public Member Functions | |
ByteBuffer (FileHandle &file, size_t len) | |
Construct buffer from data in a file. | |
bool | IsValid () const |
Return whether the buffer was constructed successfully. | |
bool | IsEnd () const |
Return whether reading has reached the end of the buffer. | |
bool | ReadByte (uint8_t &b) |
Read a single byte from the buffer. | |
bool | ReadVariableLength (uint32_t &res) |
Read a MIDI file variable length value. | |
bool | ReadBuffer (uint8_t *dest, size_t length) |
Read bytes into a buffer. | |
bool | ReadDataBlock (MidiFile::DataBlock *dest, size_t length) |
Read bytes into a MidiFile::DataBlock. | |
bool | Skip (size_t count) |
Skip over a number of bytes in the buffer. | |
bool | Rewind (size_t count) |
Go a number of bytes back to re-read. | |
Private Attributes | |
std::vector< uint8_t > | buf {} |
size_t | pos = 0 |
Owning byte buffer readable as a stream.
RAII-compliant to make teardown in error situations easier.
Definition at line 62 of file midifile.cpp.
|
inline |
Construct buffer from data in a file.
If file does not have sufficient bytes available, the object is constructed in an error state, that causes all further function calls to fail.
file | file to read from at current position |
len | number of bytes to read |
Definition at line 73 of file midifile.cpp.
|
inline |
Return whether reading has reached the end of the buffer.
Definition at line 95 of file midifile.cpp.
Referenced by ReadBuffer(), ReadByte(), ReadDataBlock(), ReadVariableLength(), and Skip().
|
inline |
Return whether the buffer was constructed successfully.
Definition at line 86 of file midifile.cpp.
|
inline |
Read bytes into a buffer.
[out] | dest | buffer to copy into |
length | number of bytes to read |
Definition at line 137 of file midifile.cpp.
References IsEnd().
|
inline |
Read a single byte from the buffer.
[out] | b | returns the read value |
Definition at line 105 of file midifile.cpp.
References IsEnd().
|
inline |
Read bytes into a MidiFile::DataBlock.
[out] | dest | DataBlock to copy into |
length | number of bytes to read |
Definition at line 152 of file midifile.cpp.
References MidiFile::DataBlock::data, and IsEnd().
|
inline |
Read a MIDI file variable length value.
Each byte encodes 7 bits of the value, most-significant bits are encoded first. If the most significant bit in a byte is set, there are further bytes encoding the value.
[out] | res | returns the read value |
Definition at line 119 of file midifile.cpp.
References IsEnd().
|
inline |
Go a number of bytes back to re-read.
count | number of bytes to go back |
Definition at line 179 of file midifile.cpp.
|
inline |
Skip over a number of bytes in the buffer.
count | number of bytes to skip over |
Definition at line 166 of file midifile.cpp.
References IsEnd().
|
private |
Definition at line 63 of file midifile.cpp.
|
private |
Definition at line 64 of file midifile.cpp.