Dynamic Packets - A clean, elegant, efficient solution

08/10/2012 01:43 InfamousNoone#1
Dynamic packets have always been a problem in regards to how to create and define them in terms of code. I've always knew this was possible, but John (of ConquerAI) recently coded something similar so I thought I would improve it.

What is a dynamic packet?
A dynamic packet is a packet that varies in size due to unfixed sizes. An example of a dynamic packet is any packet that uses the CNetStringPacker, such as the chat packet.

Why are they a problem?
Back in I believe 2009, or 2010, I introduced to the community the idea of defining packets are structures and accessing fields and writing to them via pointer-logic. While this was amazingly fast and easy to maintain, problems quickly began to arose due to two things:
1. Structure alignment causing fields to have unexpected sizes
2. Dynamic packets

As a result, tedious code would have to be written for these packets to parse fields, and write them. I've noticed even in newer sources, people have gone back to the method of using a writer instead of structures (which I can understand why, many people are "afraid" of pointers) -- but once again, you end up writing tedious code.

Using Reflection.Emit, I have created a way of dynamically creating a writer/reader method for packet-types at run time, and cacheing them so they don't impede performance. They are as efficient as if they were coded and compiled originally -- thus they remove the need to manually ever code parsers again.

Here's the project SVN for those that are interested, there's a sample to see how to use it, and define custom-marshalers as well:
[Only registered and activated users can see links. Click Here To Register...]

Sample usuage/code:
[Only registered and activated users can see links. Click Here To Register...]

Comment/feedback is appreciated.
08/10/2012 02:41 phize#2
Neat :)
08/10/2012 03:09 ImFlamedCOD#3
Very clean , *thumbs up*
08/10/2012 07:24 InfamousNoone#4
Added support for enums, structures and unions. Provided an example. Will add support for arrays of structures (and primtives) later...

Added support for arrays (but chose to write my packer as a List<T> for simplicity sake)
05/29/2013 13:16 Super Aids#5
I think this deserves more attention. Surprised I've never come across this. Wish I had in earlier state of my development, considering rewriting all my packets using something like this.
05/29/2013 18:16 InfamousNoone#6
Planned on using it in V3, decided it didn't call for it and used something a little more light weight but yeah this comes from a time when I was heavily playing around with IL.
05/29/2013 18:43 Super Aids#7
Yeah, was not exactly thinking of using this, but just a similar technology :p
05/30/2013 20:12 _DreadNought_#8
Quote:
Originally Posted by InfProCodez
var chat = new MsgChat("Hybrid", "ALL", "YOLO!", 1000);
I shall avenge all 'yolo' speakers.
05/31/2013 00:22 .Kinshi#9
This is a super interesting library you made.
Two thumbs up.