Closed snarlynarwhal closed 5 years ago
I handled this a slightly different way but will add documentation on how to use the way you've done it on top. Thanks a lot for doing Networker.Formatter.MessagePack, but please rename to new format Networker.Extensions.MessagePack and include in separate PR.
@MarkioE I'll take care of that later today!
Prototype code for Networker.Formatter.MessagePack and decoupling packet handlers from serialization so that a packet handler can process multiple packets.
This code makes use of MessagePack's Typeless serialization. I added:
The library modifications include:
IPacketHandler<T>
which extendsIPacketHandler
PacketHandlerBase
into a regular and generic versionAs is, this code works with MessagePack, but it won't for Protobuf or Zero Formatter since it relies of Typeless serialization. We can make it work for Prototbuf simply by passing in the Type. But since Zero Formatter relies strictly on generics, so I don't think it will work with it. That being said, Zero Formatter has been superseded by MessagePack so how important is it for Networker to support Zero Formatter?
Ideally, we would completely defer deserialization to the packet processor and just make
PacketHandlerBase<T>
an empty class that inheritsIPacketHandler<T>
to prevent breaking changes.Right now the
PacketHandlerBase.Handle
method makes use of reflection.. not sure if there's a better alternative. We can always cache a map of packet types to process methods and even precache on startup.What do you think?