eolib 0.5.0
A core C library for writing applications related to Endless Online
Loading...
Searching...
No Matches
Reading Data

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:

// Data buffer owned by the caller.
const uint8_t *buf = ...;
size_t buf_len = ...;
EoReader reader = eo_reader_init(buf, buf_len);
int32_t action;
int32_t family;
if (eo_reader_get_byte(&reader, (uint8_t *)&action) != EO_SUCCESS ||
eo_reader_get_byte(&reader, (uint8_t *)&family) != EO_SUCCESS) {
// handle error
}
int32_t player_id;
eo_reader_get_short(&reader, &player_id);
char *name = NULL;
eo_reader_get_string(&reader, &name);
// ... use name ...
free(name);
EoResult eo_reader_get_string(EoReader *reader, char **out_value)
Definition data.c:1073
EoResult eo_reader_get_short(EoReader *reader, int32_t *out_value)
Definition data.c:985
EoReader eo_reader_init(const uint8_t *data, size_t length)
Definition data.c:834
EoResult eo_reader_get_byte(EoReader *reader, uint8_t *out_value)
Definition data.c:931
@ EO_SUCCESS
Definition result.h:14

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.

EoReader reader = eo_reader_init(buf, buf_len);
// Read fields from the first chunk.
int32_t val;
eo_reader_get_char(&reader, &val);
// Advance to the second chunk.
char *str = NULL;
eo_reader_get_string(&reader, &str);
free(str);
void eo_reader_set_chunked_reading_mode(EoReader *reader, bool enabled)
Definition data.c:851
EoResult eo_reader_next_chunk(EoReader *reader)
Definition data.c:889
EoResult eo_reader_get_char(EoReader *reader, int32_t *out_value)
Definition data.c:958

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.