eolib-cpp 0.1.0-beta.7
Core C++ library for writing Endless Online applications
Loading...
Searching...
No Matches
eolib::data::NumberEncoder Class Reference

Encodes and decodes EO numbers. More...

#include <eolib/data/number_encoder.hpp>

Public Member Functions

 NumberEncoder ()=delete

Static Public Member Functions

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.

Detailed Description

Constructor & Destructor Documentation

◆ NumberEncoder()

eolib::data::NumberEncoder::NumberEncoder ( )
delete

Member Function Documentation

◆ EncodeNumber()

std::array< std::uint8_t, 4 > eolib::data::NumberEncoder::EncodeNumber ( int number)
staticnoexcept

Encodes a number to a sequence of 4 bytes.

Parameters
numberthe 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
bytesa pointer to the encoded bytes.
lengththe 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
bytesthe 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.