Encodes and decodes EO numbers.
More...
#include <eolib/data/number_encoder.hpp>
|
| static std::array< std::uint8_t, 4 > | EncodeNumber (int number) noexcept |
| | Encodes a number to a sequence of 4 bytes.
|
| static int | DecodeNumber (const std::uint8_t *bytes, std::size_t length) noexcept |
| | Decodes a number from a sequence of up to 4 bytes.
|
| static int | DecodeNumber (const std::vector< std::uint8_t > &bytes) noexcept |
| | Decodes a number from a sequence of up to 4 bytes.
|
◆ NumberEncoder()
| eolib::data::NumberEncoder::NumberEncoder |
( |
| ) |
|
|
delete |
◆ EncodeNumber()
| std::array< std::uint8_t, 4 > eolib::data::NumberEncoder::EncodeNumber |
( |
int | number | ) |
|
|
staticnoexcept |
Encodes a number to a sequence of 4 bytes.
- Parameters
-
| number | the number to encode. It is treated as an unsigned 32-bit integer, so values up to EoNumericLimits::IntMax - 1 may be passed as (wrapped) negative numbers. |
- Returns
- the encoded bytes. Unused high-order bytes are
0xFE.
◆ DecodeNumber() [1/2]
| int eolib::data::NumberEncoder::DecodeNumber |
( |
const std::uint8_t * | bytes, |
|
|
std::size_t | length ) |
|
staticnoexcept |
Decodes a number from a sequence of up to 4 bytes.
- Parameters
-
| bytes | a pointer to the encoded bytes. |
| length | the number of bytes in bytes. Only the first 4 bytes are decoded. |
- Returns
- the decoded number. Values above
INT_MAX wrap to negative numbers, and malformed 0x00 bytes decode as -1.
◆ DecodeNumber() [2/2]
| int eolib::data::NumberEncoder::DecodeNumber |
( |
const std::vector< std::uint8_t > & | bytes | ) |
|
|
staticnoexcept |
Decodes a number from a sequence of up to 4 bytes.
- Parameters
-
| bytes | the encoded bytes. Only the first 4 bytes are decoded. |
- Returns
- the decoded number. Values above
INT_MAX wrap to negative numbers, and malformed 0x00 bytes decode as -1.