|
eolib-cpp 0.1.0-beta.7
Core C++ library for writing Endless Online applications
|
A class for reading EO data from a sequence of bytes. More...
#include <eolib/data/eo_reader.hpp>
Public Member Functions | |
| EoReader (std::vector< std::uint8_t > data) | |
| Creates a reader over the specified data. | |
| EoReader (std::string_view data) | |
| Creates a reader over a copy of the specified data. | |
| EoReader (const std::uint8_t *data, std::size_t length) | |
| Creates a reader over a copy of the specified data. | |
| EoReader (const EoReader &other)=default | |
| Creates a reader that shares this reader's data, with an independent copy of its position and chunked reading state. | |
| EoReader (EoReader &&other) noexcept | |
| Creates a reader that takes over another reader's data and state. | |
| EoReader & | operator= (const EoReader &other)=default |
| Replaces this reader's data and state with a copy of another reader's. | |
| EoReader & | operator= (EoReader &&other) noexcept |
| Replaces this reader's data and state with another reader's. | |
| ~EoReader ()=default | |
| EoReader | Slice () const |
| Creates a new reader from a slice of this reader's data, starting at the current position. | |
| EoReader | Slice (int index) const |
| Creates a new reader from a slice of this reader's data, starting at the specified index. | |
| EoReader | Slice (int index, int length) const |
| Creates a new reader from a slice of this reader's data, with the specified index and length. | |
| int | GetByte () |
| Reads a raw byte from the input data. | |
| std::vector< std::uint8_t > | GetBytes (int length) |
| Reads an array of raw bytes from the input data. | |
| int | GetChar () |
| Reads an encoded 1-byte integer from the input data. | |
| int | GetShort () |
| Reads an encoded 2-byte integer from the input data. | |
| int | GetThree () |
| Reads an encoded 3-byte integer from the input data. | |
| int | GetInt () |
| Reads an encoded 4-byte integer from the input data. | |
| std::string | GetString () |
| Reads a string from the input data. | |
| std::string | GetFixedString (int length, bool padded=false) |
| Reads a fixed-length string from the input data. | |
| std::string | GetEncodedString () |
| Reads an encoded string from the input data. | |
| std::string | GetFixedEncodedString (int length, bool padded=false) |
| Reads a fixed-length encoded string from the input data. | |
| bool | GetChunkedReadingMode () const noexcept |
| Gets the chunked reading mode for the reader. | |
| void | SetChunkedReadingMode (bool chunked_reading_mode) noexcept |
| Sets the chunked reading mode for the reader. | |
| void | NextChunk () |
| Moves the reader position to the start of the next chunk. | |
| int | Remaining () const noexcept |
| Gets the number of bytes remaining in the input data. | |
| int | Position () const noexcept |
| Gets the current position in the input data. | |
Static Public Member Functions | |
| static EoReader | View (std::string_view data) noexcept |
| Creates a reader that refers to the specified data without copying it. | |
| static EoReader | View (const std::uint8_t *data, std::size_t length) noexcept |
| Creates a reader that refers to the specified data without copying it. | |
| static EoReader | View (const std::vector< std::uint8_t > &data) noexcept |
| Creates a reader that refers to the specified data without copying it. | |
| static EoReader | View (std::vector< std::uint8_t > &&data)=delete |
| Deleted to prevent creating a view over a temporary, which would dangle. Use the constructor instead. | |
A class for reading EO data from a sequence of bytes.
EoReader features a chunked reading mode, which is important for accurate emulation of the official game client.
Reads past the end of the data (or the current chunk) do not throw; numeric reads return 0 and string/byte reads return truncated results.
Encoded numbers are returned as int. Malformed data can decode to negative or out-of-range values (a 0x00 byte decodes as -1), and 4-byte values above INT_MAX wrap to negative numbers, so code reading untrusted data must validate the values it reads.
A reader either owns its data (the constructors, which copy or take the data) or refers to data owned by the caller (View, which doesn't copy). Copies and slices of a reader share its data, and are views if it is a view.
See: https://github.com/Cirras/eo-protocol/blob/master/docs/chunks.md
|
explicit |
Creates a reader over the specified data.
| data | the data to read. |
|
explicit |
Creates a reader over a copy of the specified data.
| data | the data to read, as a byte string. |
| eolib::data::EoReader::EoReader | ( | const std::uint8_t * | data, |
| std::size_t | length ) |
Creates a reader over a copy of the specified data.
| data | a pointer to the data to read. |
| length | the number of bytes to read from data. |
|
default |
Creates a reader that shares this reader's data, with an independent copy of its position and chunked reading state.
| other | the reader to copy. |
|
noexcept |
Creates a reader that takes over another reader's data and state.
The other reader is left empty.
| other | the reader to move from. |
|
default |
|
staticnoexcept |
Creates a reader that refers to the specified data without copying it.
The data must outlive the reader, and all copies and slices of it. Generated types copy their fields out of the reader, so the data only needs to live until deserialization is complete.
| data | the data to read, as a byte string. |
|
staticnoexcept |
Creates a reader that refers to the specified data without copying it.
The data must outlive the reader, and all copies and slices of it. Generated types copy their fields out of the reader, so the data only needs to live until deserialization is complete.
| data | a pointer to the data to read. |
| length | the number of bytes to read from data. |
|
staticnoexcept |
Creates a reader that refers to the specified data without copying it.
The data must outlive the reader, and all copies and slices of it. Generated types copy their fields out of the reader, so the data only needs to live until deserialization is complete.
| data | the data to read. |
|
staticdelete |
Deleted to prevent creating a view over a temporary, which would dangle. Use the constructor instead.
Replaces this reader's data and state with a copy of another reader's.
The data is shared.
| other | the reader to copy. |
Replaces this reader's data and state with another reader's.
The other reader is left empty.
| other | the reader to move from. |
| EoReader eolib::data::EoReader::Slice | ( | ) | const |
Creates a new reader from a slice of this reader's data, starting at the current position.
The new reader shares the underlying data but has independent position and chunked reading state.
| EoReader eolib::data::EoReader::Slice | ( | int | index | ) | const |
Creates a new reader from a slice of this reader's data, starting at the specified index.
The new reader shares the underlying data but has independent position and chunked reading state.
| index | the index in this reader's data where the slice starts. Indexes past the end produce an empty reader. |
index to the end. | std::invalid_argument | if the index is negative. |
| EoReader eolib::data::EoReader::Slice | ( | int | index, |
| int | length ) const |
Creates a new reader from a slice of this reader's data, with the specified index and length.
The new reader shares the underlying data but has independent position and chunked reading state.
| index | the index in this reader's data where the slice starts. |
| length | the length of the slice. The slice is truncated if it extends past the end of the data. |
| std::invalid_argument | if the index or length is negative. |
| int eolib::data::EoReader::GetByte | ( | ) |
Reads a raw byte from the input data.
| std::vector< std::uint8_t > eolib::data::EoReader::GetBytes | ( | int | length | ) |
Reads an array of raw bytes from the input data.
| length | the number of bytes to read. |
length if there isn't enough data remaining. | int eolib::data::EoReader::GetChar | ( | ) |
Reads an encoded 1-byte integer from the input data.
| int eolib::data::EoReader::GetShort | ( | ) |
Reads an encoded 2-byte integer from the input data.
| int eolib::data::EoReader::GetThree | ( | ) |
Reads an encoded 3-byte integer from the input data.
| int eolib::data::EoReader::GetInt | ( | ) |
Reads an encoded 4-byte integer from the input data.
INT_MAX wrap to negative numbers. | std::string eolib::data::EoReader::GetString | ( | ) |
Reads a string from the input data.
| std::string eolib::data::EoReader::GetFixedString | ( | int | length, |
| bool | padded = false ) |
Reads a fixed-length string from the input data.
| length | the length of the string. |
| padded | true if the string is padded with trailing 0xFF bytes, which are removed. |
length if there isn't enough data remaining. | std::invalid_argument | if the length is negative. |
| std::string eolib::data::EoReader::GetEncodedString | ( | ) |
Reads an encoded string from the input data.
| std::string eolib::data::EoReader::GetFixedEncodedString | ( | int | length, |
| bool | padded = false ) |
Reads a fixed-length encoded string from the input data.
| length | the length of the string. |
| padded | true if the string is padded with trailing 0xFF bytes, which are removed. |
length if there isn't enough data remaining. | std::invalid_argument | if the length is negative. |
|
noexcept |
Gets the chunked reading mode for the reader.
|
noexcept |
Sets the chunked reading mode for the reader.
In chunked reading mode, the reader will treat 0xFF bytes as the boundaries between chunks of data.
| chunked_reading_mode | true to enable chunked reading mode. |
| void eolib::data::EoReader::NextChunk | ( | ) |
Moves the reader position to the start of the next chunk.
| std::logic_error | if not in chunked reading mode. |
|
noexcept |
Gets the number of bytes remaining in the input data.
|
noexcept |
Gets the current position in the input data.