|
eolib-cpp 0.1.0-beta.7
Core C++ library for writing Endless Online applications
|
A class for writing EO data to a sequence of bytes. More...
#include <eolib/data/eo_writer.hpp>
Public Member Functions | |
| EoWriter ()=default | |
| Creates an empty writer. | |
| EoWriter (std::size_t capacity) | |
| Creates an empty writer with an initial buffer capacity. | |
| void | AddByte (int value) |
| Adds a raw byte to the writer data. | |
| void | AddBytes (const std::vector< std::uint8_t > &bytes) |
| Adds an array of raw bytes to the writer data. | |
| void | AddBytes (const std::uint8_t *bytes, std::size_t length) |
| Adds an array of raw bytes to the writer data. | |
| void | AddChar (int number) |
| Adds an encoded 1-byte integer to the writer data. | |
| void | AddShort (int number) |
| Adds an encoded 2-byte integer to the writer data. | |
| void | AddThree (int number) |
| Adds an encoded 3-byte integer to the writer data. | |
| void | AddInt (int number) |
| Adds an encoded 4-byte integer to the writer data. | |
| void | AddString (std::string_view str) |
| Adds a string to the writer data. | |
| void | AddFixedString (std::string_view str, int length, bool padded=false) |
| Adds a fixed-length string to the writer data. | |
| void | AddEncodedString (std::string_view str) |
| Adds an encoded string to the writer data. | |
| void | AddFixedEncodedString (std::string_view str, int length, bool padded=false) |
| Adds a fixed-length encoded string to the writer data. | |
| bool | GetStringSanitization () const noexcept |
| Gets the string sanitization mode for the writer. | |
| void | SetStringSanitization (bool string_sanitization) noexcept |
| Sets the string sanitization mode for the writer. | |
| int | Length () const noexcept |
| Gets the length of the writer data. | |
| std::vector< std::uint8_t > | ToByteArray () const & |
| Gets a copy of the writer data as a byte array. | |
| std::vector< std::uint8_t > | ToByteArray () && |
| Moves the writer data out as a byte array, avoiding a copy. | |
| std::string | ToByteString () const |
| Gets a copy of the writer data as a byte string. | |
| const std::vector< std::uint8_t > & | Data () const noexcept |
| Gets a read-only view of the writer data. | |
A class for writing EO data to a sequence of bytes.
Strings are treated as raw byte sequences (Windows-1252 in the official client). No transcoding is performed.
|
default |
Creates an empty writer.
|
explicit |
Creates an empty writer with an initial buffer capacity.
| capacity | the number of bytes to reserve. |
| void eolib::data::EoWriter::AddByte | ( | int | value | ) |
Adds a raw byte to the writer data.
| value | the byte value to add. |
| std::invalid_argument | if the value is negative or above 0xFF. |
| void eolib::data::EoWriter::AddBytes | ( | const std::vector< std::uint8_t > & | bytes | ) |
Adds an array of raw bytes to the writer data.
| bytes | the bytes to add. |
| void eolib::data::EoWriter::AddBytes | ( | const std::uint8_t * | bytes, |
| std::size_t | length ) |
Adds an array of raw bytes to the writer data.
| bytes | a pointer to the bytes to add. |
| length | the number of bytes to add from bytes. |
| void eolib::data::EoWriter::AddChar | ( | int | number | ) |
Adds an encoded 1-byte integer to the writer data.
| number | the number to encode and add. |
| std::invalid_argument | if the value is negative or not below EoNumericLimits::CharMax. |
| void eolib::data::EoWriter::AddShort | ( | int | number | ) |
Adds an encoded 2-byte integer to the writer data.
| number | the number to encode and add. |
| std::invalid_argument | if the value is negative or not below EoNumericLimits::ShortMax. |
| void eolib::data::EoWriter::AddThree | ( | int | number | ) |
Adds an encoded 3-byte integer to the writer data.
| number | the number to encode and add. |
| std::invalid_argument | if the value is negative or not below EoNumericLimits::ThreeMax. |
| void eolib::data::EoWriter::AddInt | ( | int | number | ) |
Adds an encoded 4-byte integer to the writer data.
| number | the number to encode and add. It is treated as an unsigned 32-bit integer, so values above INT_MAX may be passed as (wrapped) negative numbers. |
| std::invalid_argument | if the unsigned value is not below EoNumericLimits::IntMax. |
| void eolib::data::EoWriter::AddString | ( | std::string_view | str | ) |
Adds a string to the writer data.
| str | the string to add. |
| void eolib::data::EoWriter::AddFixedString | ( | std::string_view | str, |
| int | length, | ||
| bool | padded = false ) |
Adds a fixed-length string to the writer data.
| str | the string to add. |
| length | the expected length of the string. |
| padded | true if the string should be padded to the length with trailing 0xFF bytes. |
| std::invalid_argument | if the length is negative, or the string does not have the expected length (or is longer than it, if padded). |
| void eolib::data::EoWriter::AddEncodedString | ( | std::string_view | str | ) |
Adds an encoded string to the writer data.
| str | the string to encode and add. |
| void eolib::data::EoWriter::AddFixedEncodedString | ( | std::string_view | str, |
| int | length, | ||
| bool | padded = false ) |
Adds a fixed-length encoded string to the writer data.
| str | the string to encode and add. |
| length | the expected length of the string. |
| padded | true if the string should be padded to the length with trailing 0xFF bytes. |
| std::invalid_argument | if the length is negative, or the string does not have the expected length (or is longer than it, if padded). |
|
noexcept |
Gets the string sanitization mode for the writer.
With string sanitization enabled, the writer will switch 0xFF bytes in strings (ΓΏ) to 0x79 (y).
See: https://github.com/Cirras/eo-protocol/blob/master/docs/chunks.md#sanitization
|
noexcept |
Sets the string sanitization mode for the writer.
| string_sanitization | true to enable string sanitization. |
|
noexcept |
Gets the length of the writer data.
| std::vector< std::uint8_t > eolib::data::EoWriter::ToByteArray | ( | ) | const & |
Gets a copy of the writer data as a byte array.
| std::vector< std::uint8_t > eolib::data::EoWriter::ToByteArray | ( | ) | && |
Moves the writer data out as a byte array, avoiding a copy.
The writer is left empty.
Example: auto bytes = std::move(writer).ToByteArray();
| std::string eolib::data::EoWriter::ToByteString | ( | ) | const |
Gets a copy of the writer data as a byte string.
|
noexcept |
Gets a read-only view of the writer data.