lucaspoffo / renet

Server/Client network library for multiplayer games with authentication and connection management made with Rust
Apache License 2.0
662 stars 68 forks source link

Allow to send en empty messages #60

Closed Shatur closed 1 year ago

Shatur commented 1 year ago

Currently, if I send an empty message, it will not be received. But it's an issue for non-self-describing formats such as bincode. For example, the following struct results into an empty Vec:

#[derive(Deserialize, Serialize)]
struct MyEvent;

It would be great if we could send empty messages. In such formats the following deserializes successfully:

let event: MyEvent = bincode::deserialize(&[]).unwrap();

I discovered this issue after an attempt to switch from rmp_serde to bincode. With rmp_serde it works because it is self-describing format and never serializes into an empty Vec.

lucaspoffo commented 1 year ago

This was a bad assumption of mine that empty messages are an error. Some serialization methods may create empty messages. Reverted this change in 1e287018c7201ec339406a8dd6483714ade7f0ba