|
eolib 0.5.0
A core C library for writing applications related to Endless Online
|
EoWriter accumulates EO-encoded bytes into a dynamically-growing buffer. Call eo_writer_free() when finished to release the owned memory.
Basic usage:
Encoded (EO-transformed) strings:
Some packet fields use EO's string encoding, which byte-transforms and reverses the string. Use the _encoded_ variants for these fields:
String sanitization mode:
When string sanitization is enabled, any 0xFF byte in a string is replaced with 0x79 ('y'). This prevents chat or name strings from accidentally introducing chunk delimiters.
Number types and their byte widths:
| Function | Bytes written | Max value |
|---|---|---|
| eo_writer_add_byte() | 1 | 255 |
| eo_writer_add_char() | 1 | EO_CHAR_MAX |
| eo_writer_add_short() | 2 | EO_SHORT_MAX |
| eo_writer_add_three() | 3 | EO_THREE_MAX |
| eo_writer_add_int() | 4 | EO_INT_MAX |
Negative numbers:
Only eo_writer_add_int() supports negative int32_t values. eo_writer_add_char(), eo_writer_add_short(), and eo_writer_add_three() accept only non-negative values in their documented ranges.
Negative 4-byte EO ints are encoded from the value's 32-bit bit pattern. Because EO's 4-byte range stops at EO_INT_MAX (4097152081), not every negative int32_t is representable. The valid negative range is [INT32_MIN, -197815216].
In particular:
Pre-allocating with eo_get_size():
eo_get_size() dispatches through the vtable to return the exact number of bytes eo_serialize() will write for a given struct. Pass that value to eo_writer_init_with_capacity() to allocate the full buffer upfront and avoid repeated reallocations during serialization.
This is especially valuable when serializing large structures such as pub files or packets with long string arrays.
When serializing a collection of structs (e.g. building a pub file), sum the sizes first: