veloren / veloren

An open world, open source voxel RPG inspired by Dwarf Fortress and Cube World. This repository is a mirror. Please submit all PRs and issues on our GitLab page.

Home Page:https://www.veloren.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Separate Packet Serialization/Deserialization to allow custom format.

terahlunah opened this issue · comments

Currently the packet are just a big enum serialized as-is which limits the way we can craft packet.

For example it's hard to have packet with conditional data.

You could use an Option at the moment but :

  • if things get's nested heavily it's gonna be unreadable
  • if the packet contains a hundred conditional fields like the EntityUpdate will contains later (sending only changed fields), the packet will be twice the size it needs to be because of the way the serializer works with enums, and given the frequency and size of EntityUpdate, it's really bad.

A good idea would be to separate thing out like this :

  • A packet struct containing the pure data
  • A packet serializer/deserializer (which could use the
  • A packet handler to fill/do things with the pure data

Interestingly, I believe Serde only serializes the exact enum variant required. If an enum variant requires less data than others to store, Serde will only store the minimum necessary to do so. More information here: serde-rs/serde#251

This would suggest that using serialized enums to send data is still relatively efficient.

I had a look at serde, you're right, it should be fine