|
eolib 0.5.0
A core C library for writing applications related to Endless Online
|
Every generated protocol struct and packet type implements the EoSerialize interface (and packets also implement EoPacket). This gives a uniform API for all ~400 generated types without individual exported serialize/deserialize/free symbols per type.
Every type has a static inline TypeName_init() function declared in protocol.h. It returns a zero-initialized struct with its internal vtable pointer already set:
All operations go through the EoSerialize vtable via the following inline dispatch helpers declared in data.h:
| Function | Description |
|---|---|
| eo_deserialize() | Read fields from an EoReader |
| eo_serialize() | Write fields to an EoWriter |
| eo_get_size() | Return the exact serialized byte count |
| eo_free() | Release any heap-allocated fields |
All four accept a pointer-to-EoSerialize as their first argument. Cast any generated struct or packet to (EoSerialize *) (or (const EoSerialize *) for read-only operations):
Packet types additionally implement EoPacket, which carries a second vtable with get_family and get_action slots. Use the packet dispatch helpers to query the hard-coded family/action values without inspecting enum constants manually:
Because every struct shares the EoSerialize base, you can write helpers that operate on any struct without knowing its concrete type:
The C "inheritance by first-member" rule guarantees the casts above are safe. The generated struct layout is:
Since _eo is always the first member, a pointer to the struct and a pointer to its _eo field have the same address. For packets the chain is LoginRequestClientPacket → EoPacket → EoSerialize, so (EoSerialize *)&pkt resolves all three levels correctly.