Add traits that enable object like parsing/serializing of game query packets#148
Draft
Douile wants to merge 8 commits intogamedig:mainfrom
Draft
Add traits that enable object like parsing/serializing of game query packets#148Douile wants to merge 8 commits intogamedig:mainfrom
Douile wants to merge 8 commits intogamedig:mainfrom
Conversation
9d2fabb to
20a30bb
Compare
Add a few StringEncoder implementations as examples and implement them for writing Unreal2 packets. Also make sure to reserve capacity in the output buffer when writing both strings and bytes.
20a30bb to
39b0929
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a draft implementation of what #104 could look like.
It adds 3 traits:
ToPacket- to encode a struct as aVec<u8>for sending over the networkFromPacket- to create a struct from&[u8]ExtendFromPacket- to extend the data in a struct from&[u8], this is useful when responses come in multiple packets e.g. player responsesTo help with implementing the
ToPackettraitWriteBufferwas also added, this functions very similarly toBufferbut is instead for writing data into a buffer.These traits can be used by the query implementations to create packets:
In unreal 2 the old send request was implemented as
this becomes
where PacketRequest is an exact representation of the raw packet bytes:
They can also be used to parse packets:
For the unreal2 implementation the packets all have a common outer header part, using these traits the can be represented using an outer
ResponsePackettype that is generic over the inner body. I think this is quite a nice abstraction as it allows for a blanket implementation for encoding/decoding all packets where the inner body implements theToPacketorFromPackettraits. Although there is a bit of added complexity.Here the Packet structs are also raw representation of the bytes.
Positives of moving to this architecture:
Downsides:
My thoughts:
#[repr(C)]) in these cases it could be a lot faster to just cast the struct to a slice of bytes rather than using aWriteBuffer.ToPacketcould takeWriteBufferas a parameter directly to avoid allocating aVec.I'll probably think of more benefits/downsides in the future but I think this is in a place where its ready for other people to give their thoughts on.