|
eolib 0.5.0
A core C library for writing applications related to Endless Online
|
EoReader provides a cursor over a caller-owned byte buffer and exposes methods for reading EO-encoded values. The reader does not take ownership of the underlying data.
Basic usage:
Chunked reading mode:
EO packets use 0xFF bytes as chunk delimiters. Enable chunked reading mode to respect these boundaries automatically. While in chunked mode, eo_reader_remaining() and all get_* functions operate only within the current chunk. Call eo_reader_next_chunk() to advance past the next 0xFF delimiter.
Number types and their byte widths:
| Function | Bytes read | Max value |
|---|---|---|
| eo_reader_get_byte() | 1 | 255 |
| eo_reader_get_char() | 1 | EO_CHAR_MAX |
| eo_reader_get_short() | 2 | EO_SHORT_MAX |
| eo_reader_get_three() | 3 | EO_THREE_MAX |
| eo_reader_get_int() | 4 | EO_INT_MAX |
Negative numbers:
EO number encoding is not sign-aware. eo_reader_get_int() decodes the four EO bytes into a 32-bit bit pattern and returns it as int32_t.
For values in the range [0, INT32_MAX], this behaves like an ordinary positive integer read. When the decoded 32-bit pattern is at least 2^31, the returned int32_t becomes negative on typical two's-complement systems.
For example, the EO bytes A8 B5 9A 85 decode to the bit pattern 2147483648, which is returned as INT32_MIN.
Only 4-byte EO ints can produce negative results this way. eo_reader_get_char(), eo_reader_get_short(), and eo_reader_get_three() always return non-negative values because their decoded ranges never reach the sign bit.