Custom Serialization
fixes #15 .
Adds custom serialization which allows users to supply custom serialization functions for messages to utilize different serialization formats with minimal change to current user ergonomics.
Changes
Networkis now a system param, Network was changed toNetworkInstance. Users need to interact with the network through the Network system param now.- Sending messages now utilizes observers to enable different serialization functions for each message type.
recv_loopandsend_loopnow take a hashmap of serialization functions to enable serialization and deserialization of messages according to different settings.- messages must be registered on BOTH the sender and the receiver
listen_for_messageis nowregister_messagelisten_for_request_messageis nowregister_receive_request_messagelisten_for_response_messageis nowregister_send_request_message
Custom Serialization
See BEMW JSON for an example. Recommend making a trait to help with registration. You need a generic serialization and deserialization function each and then one each for serializing and deserializing network packets. See BEMW for an example of how it should be implemented.
Limitations
- Crate only supports sending
TextorBinaryover the network. - Mixing different serialization methods works rn on native but between wasm and native is intermittently working (Might be more of a BEMW issue but its weird enough that it might be on eventworks side messing up registrations for messages or something).
Todo
- [ ] Cleanup
- [ ] Add docs to serialization
- [ ] Make sure Readme and stuff is updated to new format
- [ ] Fix different serialization methods not working on Wasm
- [ ] I accidentally made this branch off an older 0.13 branch :( (I need to update everything so it matches main or rebase it. Probably override main since I'm allergic to rebasing.)
BEMW branch: https://github.com/NoahShomette/bevy_eventwork_mod_websockets/tree/serialization
@davi4046 If you are still using this and the custom serialization can you test if this works for you?
@mraof I saw you forked the custom serialization repos also so can you test this and see if it works for you as well?
I will try to have a look at it tommorow👍
I have two errors when attempting to make this work.
Firstly, bevy::tasks::TaskPool is said to not implement bevy_eventwork:Runtime.
Secondly, the registration functions are not available on App in the example you provided. I guess it's because at the point of implementation, the app has not had the necessary plugins added yet.
Let me know if I'm doing anything wrong and I'll try again.
Just to make sure are you on bevy 0.14? I forgot you were working from 0.13 so that might be a pain for you to test sorry :(
I have two errors when attempting to make this work.
Firstly,
bevy::tasks::TaskPoolis said to not implementbevy_eventwork:Runtime.
Secondly, the registration functions are not available on App in the example you provided. I guess it's because at the point of implementation, the app has not had the necessary plugins added yet.
Let me know if I'm doing anything wrong and I'll try again.
Ah, I totally forgot about the bevy version. Compilation errors are gone now, thanks!
Unfortunately I get bevy_eventwork_mod_websockets::native_websocket: Failed to decode network packet. No deserialization fn found when sending a message to the server.
Server to client seems to work fine, although I had to change how the client handles received messages.
I might still be doing something wrong, sorry. You can have a look at the repo: https://github.com/davi4046/bevy_eventwork_websocket_json_demo
Thanks for the link to the repo that is very helpful! It's unfortunately running into some issues that I couldn't resolve over the weekend so theres definitely a good amount of more work to fix this pr up