<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/3.3.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Personal</title>
		<link>http://codeka.com/blogs/index.php</link>
		<atom:link rel="self" type="application/rss+xml" href="http://codeka.com/blogs/index.php?tempskin=_rss2" />
		<description>My personal blog</description>
		<language>en-AU</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=3.3.3"/>
		<ttl>60</ttl>
				<item>
			<title>Why you need to keep regular backups of your Subversion repository</title>
			<link>http://codeka.com/blogs/index.php/2010/04/26/why-you-need-to-keep-regular-backups-of-your-subversion-repository</link>
			<pubDate>Mon, 26 Apr 2010 07:40:45 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="alt">Personal</category>
<category domain="main">Technical</category>			<guid isPermaLink="false">293@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;Sometimes we assume that the software we use is infallible. It works most of the time, so we just think that it&amp;#8217;ll always work.&lt;/p&gt;

&lt;p&gt;Unfortunately, that&amp;#8217;s not always the case. Even if the software is 100% perfect, there are still things that can cause us problems. Disk drives are physical machines, and as with anything physical they wear out over time. Eventually, they break. And when that happens, you may find yourself in the same situation I was in yesterday: a broken Subversion repository&lt;/p&gt;

&lt;p&gt;I did an &lt;tt&gt;svnadmin verify&lt;/tt&gt; and it would return errors all over the place (in a different place each time, too). Eventually, I had to concede that the repository was un-recoverable.&lt;/p&gt;

&lt;p&gt;Luckily for me, I do weekly backups and my backup from last week was still usable. My backup strategy is actually very simple: &lt;a href=&quot;http://svnbook.red-bean.com/en/1.1/ch05s03.html#svn-ch-5-sect-3.6&quot;&gt;hot-backup.py&lt;/a&gt; every sunday night. Technically, I probably don&amp;#8217;t have to use &lt;tt&gt;hot-backup.py&lt;/tt&gt;, since it&amp;#8217;s unlikely that I&amp;#8217;m going to be doing anything at 4am on a Sunday morning, but you never know &lt;img src=&quot;http://codeka.com/blogs/rsc/smilies/icon_smile.gif&quot; alt=&quot;&amp;#58;&amp;#41;&quot; class=&quot;middle&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So I bought a new hard drive and kicked off the restore process. I don&amp;#8217;t have a &lt;em&gt;huge&lt;/em&gt; repository (~900 revisions [and counting!] and about 900MB.) - mostly the size comes from the fact that I&amp;#8217;ve got copies of a few open source projects in there&amp;#8230; I don&amp;#8217;t know why; I should probably tidy up my repository one of these days&amp;#8230;&lt;/p&gt;

&lt;p&gt;Anyway, the restore process is really simple: just bunzip the file that &lt;tt&gt;hot-backup.py&lt;/tt&gt; created last Sunday. It took a few minutes (a bit longer actually, cause I took the opportunity to upgrade to Subversion 1.6.11 while I was at it).&lt;/p&gt;

&lt;p&gt;The most annoying thing was that after it was all complete, my repository was complete only up until last Sunday: I had to take my current working directory and manually apply all the changes that I had made since then to get it back to what it was. Isn&amp;#8217;t there a corollary to Murphey&amp;#8217;s Law that states that when the worst thing that could happen happens, it happens &lt;em&gt;at the worst possible time&lt;/em&gt;? In my case, it was because my drive failed on a Sunday: just hours before the next backup would&amp;#8217;ve occurred and I had a full 7 days worth of changes to manually reapply.&lt;/p&gt;

&lt;p&gt;So it&amp;#8217;s always a good thing when a hardware failure shows that all your obsessive backing up is actually worthwhile, but even with the best plans in place, there&amp;#8217;s always a lesson to learn. In my case, I&amp;#8217;ve decided to augment my weekly backups with some daily &lt;em&gt;incremental&lt;/em&gt; backups. I&amp;#8217;ve borrowed &lt;a href=&quot;http://le-gall.net/pierrick/blog/index.php/2007/04/17/98-subversion-incremental-backup&quot;&gt;this script&lt;/a&gt; and set it up so that it backs up incrementally each night as well.&lt;/p&gt;

&lt;p&gt;I think the next step would be to do some off-site backups. I&amp;#8217;ve just got my backups happening to a different drive in the same computer (I was lucky, I guess, that only one drive failed). I really need to get my backups saved somewhere a little more isolated. But maybe I&amp;#8217;ll wait until the next failure precipitates it&amp;#8230;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2010/04/26/why-you-need-to-keep-regular-backups-of-your-subversion-repository&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Sometimes we assume that the software we use is infallible. It works most of the time, so we just think that it&#8217;ll always work.</p>

<p>Unfortunately, that&#8217;s not always the case. Even if the software is 100% perfect, there are still things that can cause us problems. Disk drives are physical machines, and as with anything physical they wear out over time. Eventually, they break. And when that happens, you may find yourself in the same situation I was in yesterday: a broken Subversion repository</p>

<p>I did an <tt>svnadmin verify</tt> and it would return errors all over the place (in a different place each time, too). Eventually, I had to concede that the repository was un-recoverable.</p>

<p>Luckily for me, I do weekly backups and my backup from last week was still usable. My backup strategy is actually very simple: <a href="http://svnbook.red-bean.com/en/1.1/ch05s03.html#svn-ch-5-sect-3.6">hot-backup.py</a> every sunday night. Technically, I probably don&#8217;t have to use <tt>hot-backup.py</tt>, since it&#8217;s unlikely that I&#8217;m going to be doing anything at 4am on a Sunday morning, but you never know <img src="http://codeka.com/blogs/rsc/smilies/icon_smile.gif" alt="&#58;&#41;" class="middle" /></p>

<p>So I bought a new hard drive and kicked off the restore process. I don&#8217;t have a <em>huge</em> repository (~900 revisions [and counting!] and about 900MB.) - mostly the size comes from the fact that I&#8217;ve got copies of a few open source projects in there&#8230; I don&#8217;t know why; I should probably tidy up my repository one of these days&#8230;</p>

<p>Anyway, the restore process is really simple: just bunzip the file that <tt>hot-backup.py</tt> created last Sunday. It took a few minutes (a bit longer actually, cause I took the opportunity to upgrade to Subversion 1.6.11 while I was at it).</p>

<p>The most annoying thing was that after it was all complete, my repository was complete only up until last Sunday: I had to take my current working directory and manually apply all the changes that I had made since then to get it back to what it was. Isn&#8217;t there a corollary to Murphey&#8217;s Law that states that when the worst thing that could happen happens, it happens <em>at the worst possible time</em>? In my case, it was because my drive failed on a Sunday: just hours before the next backup would&#8217;ve occurred and I had a full 7 days worth of changes to manually reapply.</p>

<p>So it&#8217;s always a good thing when a hardware failure shows that all your obsessive backing up is actually worthwhile, but even with the best plans in place, there&#8217;s always a lesson to learn. In my case, I&#8217;ve decided to augment my weekly backups with some daily <em>incremental</em> backups. I&#8217;ve borrowed <a href="http://le-gall.net/pierrick/blog/index.php/2007/04/17/98-subversion-incremental-backup">this script</a> and set it up so that it backs up incrementally each night as well.</p>

<p>I think the next step would be to do some off-site backups. I&#8217;ve just got my backups happening to a different drive in the same computer (I was lucky, I guess, that only one drive failed). I really need to get my backups saved somewhere a little more isolated. But maybe I&#8217;ll wait until the next failure precipitates it&#8230;</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2010/04/26/why-you-need-to-keep-regular-backups-of-your-subversion-repository">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2010/04/26/why-you-need-to-keep-regular-backups-of-your-subversion-repository#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=293</wfw:commentRss>
		</item>
				<item>
			<title>A step forward for R18+ classification for games in Australia</title>
			<link>http://codeka.com/blogs/index.php/2010/03/21/a-step-forward-for-r18-classification-for-games-in-australia</link>
			<pubDate>Sun, 21 Mar 2010 10:52:44 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">Personal</category>
<category domain="alt">Rants</category>			<guid isPermaLink="false">292@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;Well, I gotta say, this is something that I did not see coming.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.adelaidenow.com.au/news/in-depth/attorney-general-michael-atkinson-to-quit-front-bench/story-fn2sdwup-1225843341005&quot;&gt;South Australian Attorney General, Michael Atkinson has quit the front bench&lt;/a&gt;, and hence his post as South Australia&amp;#8217;s Attorney General.&lt;/p&gt;

&lt;p&gt;At &lt;a href=&quot;http://www.ecsa.sa.gov.au/election2010/&quot;&gt;current count&lt;/a&gt;, Gamers 4 Croydon has &amp;#8220;only&amp;#8221; received 3.7% of the vote in the seat of Croydon, and while that&amp;#8217;s a lot more than the &amp;#8220;less than 1 percent&amp;#8221; &lt;a href=&quot;http://au.gamespot.com/pages/news/story.php?sid=6246654&amp;amp;skipmc=1&quot;&gt;predicted by Mr. Atkinson&lt;/a&gt;, it&amp;#8217;s still pretty paltry.&lt;/p&gt;

&lt;p&gt;They&amp;#8217;ve also only received 0.8% of the vote for the Legislative Council. Now, I know very little of how this stuff works, but I&amp;#8217;m pretty sure that&amp;#8217;s well short of what is required to win a seat. Which is a shame, because it&amp;#8217;d have been nice to have at least &lt;em&gt;one&lt;/em&gt; person from that party representing gamers in South Australia. But maybe preferences will come their way? &lt;a href=&quot;http://www.gamers4croydon.org/images/preferenceflow.png&quot;&gt;Of course, I&amp;#8217;ve got no hope of deciphering how the preferences flow&amp;#8230;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But never-the-less, Mr Atkinson&amp;#8217;s resignation is a big step forward and hopefully Australia will (finally) be able to move into the 21&lt;sup&gt;st&lt;/sup&gt; centry and introduce an R18+ category after the next meeting of the Attorney Generals (slated for April). We&amp;#8217;ll see, I guess. If the outcome is good, it seems we can be pretty confident that it actually &lt;em&gt;was&lt;/em&gt; Mr Atkinson who was vetoing the change, &lt;a href=&quot;http://au.gamespot.com/news/6208497.html&quot;&gt;dispite the fact that he&amp;#8217;s said he&amp;#8217;s not the only one opposed&lt;/a&gt;.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2010/03/21/a-step-forward-for-r18-classification-for-games-in-australia&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Well, I gotta say, this is something that I did not see coming.</p>

<p><a href="http://www.adelaidenow.com.au/news/in-depth/attorney-general-michael-atkinson-to-quit-front-bench/story-fn2sdwup-1225843341005">South Australian Attorney General, Michael Atkinson has quit the front bench</a>, and hence his post as South Australia&#8217;s Attorney General.</p>

<p>At <a href="http://www.ecsa.sa.gov.au/election2010/">current count</a>, Gamers 4 Croydon has &#8220;only&#8221; received 3.7% of the vote in the seat of Croydon, and while that&#8217;s a lot more than the &#8220;less than 1 percent&#8221; <a href="http://au.gamespot.com/pages/news/story.php?sid=6246654&amp;skipmc=1">predicted by Mr. Atkinson</a>, it&#8217;s still pretty paltry.</p>

<p>They&#8217;ve also only received 0.8% of the vote for the Legislative Council. Now, I know very little of how this stuff works, but I&#8217;m pretty sure that&#8217;s well short of what is required to win a seat. Which is a shame, because it&#8217;d have been nice to have at least <em>one</em> person from that party representing gamers in South Australia. But maybe preferences will come their way? <a href="http://www.gamers4croydon.org/images/preferenceflow.png">Of course, I&#8217;ve got no hope of deciphering how the preferences flow&#8230;</a></p>

<p>But never-the-less, Mr Atkinson&#8217;s resignation is a big step forward and hopefully Australia will (finally) be able to move into the 21<sup>st</sup> centry and introduce an R18+ category after the next meeting of the Attorney Generals (slated for April). We&#8217;ll see, I guess. If the outcome is good, it seems we can be pretty confident that it actually <em>was</em> Mr Atkinson who was vetoing the change, <a href="http://au.gamespot.com/news/6208497.html">dispite the fact that he&#8217;s said he&#8217;s not the only one opposed</a>.</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2010/03/21/a-step-forward-for-r18-classification-for-games-in-australia">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2010/03/21/a-step-forward-for-r18-classification-for-games-in-australia#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=292</wfw:commentRss>
		</item>
				<item>
			<title>Pathfinding in Starcraft 2</title>
			<link>http://codeka.com/blogs/index.php/2010/03/04/pathfinding-in-starcraft-2</link>
			<pubDate>Thu, 04 Mar 2010 04:33:49 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">.NET General</category>			<guid isPermaLink="false">291@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;While I&amp;#8217;ve been working on the &lt;a href=&quot;http://codeka.com/war-worlds/index.php/2010/01/21/pathfinding&quot;&gt;pathfinding in War Worlds&lt;/a&gt;, I&amp;#8217;ve also been looking around at ways other games have been doing it. Check out the video below for an example of what I&amp;#8217;d consider state-of-the-art. It&amp;#8217;s the pathfinding in the upcoming Starcraft 2:&lt;/p&gt;

&lt;center&gt;
  &lt;object width=&quot;560&quot; height=&quot;340&quot;&gt;
    &lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/RfNrgymu41w&amp;amp;hl=en_GB&amp;amp;fs=1&quot; /&gt;
    &lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;
    &lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot; /&gt;
    &lt;embed src=&quot;http://www.youtube.com/v/RfNrgymu41w&amp;amp;hl=en_GB&amp;amp;fs=1&quot;
           type=&quot;application/x-shockwave-flash&quot;
           allowscriptaccess=&quot;always&quot;
           allowfullscreen=&quot;true&quot;
           width=&quot;560&quot;
           height=&quot;340&quot; /&gt;
  &lt;/object&gt;
&lt;/center&gt;

&lt;p&gt;It&amp;#8217;s a long video, but some of the stuff there really blows me away (I especially like right at the end where the zerg swarm over the base, destroying it in seconds)&lt;/p&gt;

&lt;p&gt;So how do they do it? Obviously I don&amp;#8217;t know, but I can guess.&lt;/p&gt;

&lt;p&gt;The feature that makes it look like it does is the flocking behaviour. Now flocking is a &lt;a href=&quot;http://www.red3d.com/cwr/boids/&quot;&gt;fairly well-studied&lt;/a&gt; topic, and while Starcraft 2&amp;#8217;s implement has some nice features, I don&amp;#8217;t think it&amp;#8217;s totally revolutionary. The main feature that I like about their flocking is the way that units in a big group like will &amp;#8220;stream out&amp;#8221; towards the goal in a long line, rather than trying to all stay in formation. Depending on the style of game, you might &lt;em&gt;want&lt;/em&gt; them to stay in formation, but for what is basically a swarm of insects, the behaviour in SC2 looks really nice.&lt;/p&gt;

&lt;p&gt;The main problem is how do you define the group so that flocking works, but not so that units get stuck. For example, imagine a situation like the one in the diagram below:&lt;/p&gt;

&lt;p class=&quot;center&quot;&gt;&lt;img src=&quot;http://codeka.com/blogs/media/blogs/personal/ravine.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;400&quot; height=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you imagine you select both the red and blue units and click where the green &amp;#8220;X&amp;#8221; is. You would expect the red units to flock together and the blue units to flock together, but obviously, they would follow different paths.&lt;/p&gt;

&lt;p&gt;Now, I don&amp;#8217;t know how Starcraft does it, but to me this is a situation where a polygonal navmesh would shine. Basically, you define all units that are on the same polygon in the mesh as being in a single &amp;#8220;flock&amp;#8221; (and perhaps some additional logic to account for adjacent polygons) and then find a single path for the whole flock. Then the units would use a flocking/path-following algorithm (e.g. something like &lt;a href=&quot;http://www.red3d.com/cwr/steer/CrowdPath.html&quot;&gt;this&lt;/a&gt;) to make it look &amp;#8220;natural&quot;.&lt;/p&gt;

&lt;p&gt;Obviously, the path-finding in War Worlds is extremely basic compared to all of this (I don&amp;#8217;t even use navmeshes yet!) but one day&amp;#8230;&lt;/p&gt;

&lt;p&gt;(Special thanks to &lt;a href=&quot;http://www.gamedev.net/community/forums/topic.asp?topic_id=563819&quot;&gt;this thread on gamedev.net&lt;/a&gt; for some of my ideas)&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2010/03/04/pathfinding-in-starcraft-2&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>While I&#8217;ve been working on the <a href="http://codeka.com/war-worlds/index.php/2010/01/21/pathfinding">pathfinding in War Worlds</a>, I&#8217;ve also been looking around at ways other games have been doing it. Check out the video below for an example of what I&#8217;d consider state-of-the-art. It&#8217;s the pathfinding in the upcoming Starcraft 2:</p>

<center>
  <object width="560" height="340">
    <param name="movie" value="http://www.youtube.com/v/RfNrgymu41w&amp;hl=en_GB&amp;fs=1" />
    <param name="allowFullScreen" value="true" />
    <param name="allowscriptaccess" value="always" />
    <embed src="http://www.youtube.com/v/RfNrgymu41w&amp;hl=en_GB&amp;fs=1"
           type="application/x-shockwave-flash"
           allowscriptaccess="always"
           allowfullscreen="true"
           width="560"
           height="340" />
  </object>
</center>

<p>It&#8217;s a long video, but some of the stuff there really blows me away (I especially like right at the end where the zerg swarm over the base, destroying it in seconds)</p>

<p>So how do they do it? Obviously I don&#8217;t know, but I can guess.</p>

<p>The feature that makes it look like it does is the flocking behaviour. Now flocking is a <a href="http://www.red3d.com/cwr/boids/">fairly well-studied</a> topic, and while Starcraft 2&#8217;s implement has some nice features, I don&#8217;t think it&#8217;s totally revolutionary. The main feature that I like about their flocking is the way that units in a big group like will &#8220;stream out&#8221; towards the goal in a long line, rather than trying to all stay in formation. Depending on the style of game, you might <em>want</em> them to stay in formation, but for what is basically a swarm of insects, the behaviour in SC2 looks really nice.</p>

<p>The main problem is how do you define the group so that flocking works, but not so that units get stuck. For example, imagine a situation like the one in the diagram below:</p>

<p class="center"><img src="http://codeka.com/blogs/media/blogs/personal/ravine.png" alt="" title="" width="400" height="300" /></p>

<p>If you imagine you select both the red and blue units and click where the green &#8220;X&#8221; is. You would expect the red units to flock together and the blue units to flock together, but obviously, they would follow different paths.</p>

<p>Now, I don&#8217;t know how Starcraft does it, but to me this is a situation where a polygonal navmesh would shine. Basically, you define all units that are on the same polygon in the mesh as being in a single &#8220;flock&#8221; (and perhaps some additional logic to account for adjacent polygons) and then find a single path for the whole flock. Then the units would use a flocking/path-following algorithm (e.g. something like <a href="http://www.red3d.com/cwr/steer/CrowdPath.html">this</a>) to make it look &#8220;natural".</p>

<p>Obviously, the path-finding in War Worlds is extremely basic compared to all of this (I don&#8217;t even use navmeshes yet!) but one day&#8230;</p>

<p>(Special thanks to <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=563819">this thread on gamedev.net</a> for some of my ideas)</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2010/03/04/pathfinding-in-starcraft-2">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2010/03/04/pathfinding-in-starcraft-2#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=291</wfw:commentRss>
		</item>
				<item>
			<title>SA politician admit they're a bunch of out-of-touch old fogeys</title>
			<link>http://codeka.com/blogs/index.php/2010/02/03/sa-politician-admit-they-re-a-bunch-of-out-of-touch-old-fogeys</link>
			<pubDate>Tue, 02 Feb 2010 22:50:46 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">.NET General</category>			<guid isPermaLink="false">290@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;It&amp;#8217;s bizzare. I don&amp;#8217;t usually post political stuff, so hopefully you&amp;#8217;ll forgive this indulgence &lt;img src=&quot;http://codeka.com/blogs/rsc/smilies/icon_smile.gif&quot; alt=&quot;&amp;#58;&amp;#41;&quot; class=&quot;middle&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Just yesterday, &lt;a href=&quot;http://www.zdnet.com.au/news/communications/soa/SA-bans-anonymous-online-commentary/0,130061791,339300744,00.htm&quot;&gt;we hear&lt;/a&gt; that our favourite Attorney-General, South Australian AG Michael Atkinson had a law passed saying that nobody would be &amp;#8220;allowed&amp;#8221; to post comments on South Australian websites without giving their full name and address, and that the first name and postcode needed to be published along with the comment.&lt;/p&gt;

&lt;p&gt;From some of &lt;a href=&quot;http://www.heraldsun.com.au/news/breaking-news/attorney-general-cracks-down-on-sewer-internet-election-comment/story-e6frf7jx-1225825769940&quot;&gt;his comments&lt;/a&gt;, you really get the impression that he&amp;#8217;s starting to lose his grip on reality:&lt;/p&gt;

&lt;blockquote&gt;&amp;#8220;The AdelaideNow website is not just a sewer of criminal defamation, it is a sewer of identity theft and fraud.&amp;#8221;&lt;br /&gt;&lt;br /&gt;

&amp;#8220;You will publish false stories about me, invent things about me to punish me.&amp;#8221;&lt;/blockquote&gt;

&lt;p&gt;So, &lt;em&gt;of course&lt;/em&gt; there was an &lt;a href=&quot;http://www.adelaidenow.com.au/news/in-depth/labor-gags-internet-debate/story-fn2sdwup-1225825708827&quot;&gt;internet backlash&lt;/a&gt;. Now, I&amp;#8217;ve only lived in this world for some 30 years, so I don&amp;#8217;t have the &amp;#8220;experience&amp;#8221; of people like Mr. Atkinson, but let&amp;#8217;s be honest here&amp;#8230; if you didn&amp;#8217;t see this coming, you&amp;#8217;d have to have your head up your arse.&lt;/p&gt;

&lt;p&gt;Then today, we hear that the law will be &lt;a href=&quot;http://news.smh.com.au/breaking-news-national/atkinson-to-repeal-internet-law-20100203-nbmt.html&quot;&gt;retroactively repealled&lt;/a&gt; (after the election). But still the bizarre comments from Atkinson continue:&lt;/p&gt;

&lt;blockquote&gt;&amp;#8220;From the feedback we&amp;#8217;ve received&amp;#8230; the blogging generation believes that the law supported by all MPs and all political parties is unduly restrictive&amp;#8221;&lt;br /&gt;&lt;br /&gt;&amp;#8220;I miscalculated the strength of feeling among teenagers and people in their 20s who have grown up with the internet and blogging and I underestimated their desire to have as a right the ability to make political commentary in the election period anonymously or under an assumed name.&amp;#8221;&lt;/blockquote&gt;

&lt;p&gt;That first one, he&amp;#8217;s basically saying &amp;#8220;all us politicians are so out-of-touch that we had no idea that this would even register as a blip on the radar!&amp;#8221; And as if it&amp;#8217;s only &amp;#8220;teenagers and people in their 20s&amp;#8221; - who are &lt;a href=&quot;http://www.kotaku.com.au/2010/01/atkinson-gamers-4-croydon-will-provide-a-real-contest/&quot;&gt;all criminals&lt;/a&gt; anyway, right Mr. Atkinson? - as if they&amp;#8217;re the only ones who care about being censored&amp;#8230;&lt;/p&gt;

&lt;p&gt;There is &lt;a href=&quot;http://www.abc.net.au/news/stories/2010/02/03/2808495.htm?section=justin&quot;&gt;some evidence&lt;/a&gt; that &amp;#8220;all MPs&amp;#8221; who supported the bill were misled (presumably by Atkinson) into believeing that the laws were not as broad-ranging as they actually were (though you&amp;#8217;ve got to wonder if anybody actually &lt;em&gt;reads&lt;/em&gt; what they&amp;#8217;re voting for?). Says the shadow attorney-general Vickie Chapman:&lt;/p&gt;

&lt;blockquote&gt;&amp;#8220;He clearly wanted to use this legislation to hunt down any of those who criticised him or the Government and that was made absolutely clear yesterday by his statements and behaviour&amp;#8221;&lt;/blockquote&gt;

&lt;p&gt;Which seems very much inline with some of the other stuff that Atkinson has been doing over the last few months&lt;/p&gt;

&lt;p&gt;This whole thing is really wierd, in my opinion. Atkinson seems to have this bizzare persecution complex&amp;#8230; anyway, it&amp;#8217;ll be interesting to see what happens in March.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2010/02/03/sa-politician-admit-they-re-a-bunch-of-out-of-touch-old-fogeys&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>It&#8217;s bizzare. I don&#8217;t usually post political stuff, so hopefully you&#8217;ll forgive this indulgence <img src="http://codeka.com/blogs/rsc/smilies/icon_smile.gif" alt="&#58;&#41;" class="middle" /></p>

<p>Just yesterday, <a href="http://www.zdnet.com.au/news/communications/soa/SA-bans-anonymous-online-commentary/0,130061791,339300744,00.htm">we hear</a> that our favourite Attorney-General, South Australian AG Michael Atkinson had a law passed saying that nobody would be &#8220;allowed&#8221; to post comments on South Australian websites without giving their full name and address, and that the first name and postcode needed to be published along with the comment.</p>

<p>From some of <a href="http://www.heraldsun.com.au/news/breaking-news/attorney-general-cracks-down-on-sewer-internet-election-comment/story-e6frf7jx-1225825769940">his comments</a>, you really get the impression that he&#8217;s starting to lose his grip on reality:</p>

<blockquote>&#8220;The AdelaideNow website is not just a sewer of criminal defamation, it is a sewer of identity theft and fraud.&#8221;<br /><br />

&#8220;You will publish false stories about me, invent things about me to punish me.&#8221;</blockquote>

<p>So, <em>of course</em> there was an <a href="http://www.adelaidenow.com.au/news/in-depth/labor-gags-internet-debate/story-fn2sdwup-1225825708827">internet backlash</a>. Now, I&#8217;ve only lived in this world for some 30 years, so I don&#8217;t have the &#8220;experience&#8221; of people like Mr. Atkinson, but let&#8217;s be honest here&#8230; if you didn&#8217;t see this coming, you&#8217;d have to have your head up your arse.</p>

<p>Then today, we hear that the law will be <a href="http://news.smh.com.au/breaking-news-national/atkinson-to-repeal-internet-law-20100203-nbmt.html">retroactively repealled</a> (after the election). But still the bizarre comments from Atkinson continue:</p>

<blockquote>&#8220;From the feedback we&#8217;ve received&#8230; the blogging generation believes that the law supported by all MPs and all political parties is unduly restrictive&#8221;<br /><br />&#8220;I miscalculated the strength of feeling among teenagers and people in their 20s who have grown up with the internet and blogging and I underestimated their desire to have as a right the ability to make political commentary in the election period anonymously or under an assumed name.&#8221;</blockquote>

<p>That first one, he&#8217;s basically saying &#8220;all us politicians are so out-of-touch that we had no idea that this would even register as a blip on the radar!&#8221; And as if it&#8217;s only &#8220;teenagers and people in their 20s&#8221; - who are <a href="http://www.kotaku.com.au/2010/01/atkinson-gamers-4-croydon-will-provide-a-real-contest/">all criminals</a> anyway, right Mr. Atkinson? - as if they&#8217;re the only ones who care about being censored&#8230;</p>

<p>There is <a href="http://www.abc.net.au/news/stories/2010/02/03/2808495.htm?section=justin">some evidence</a> that &#8220;all MPs&#8221; who supported the bill were misled (presumably by Atkinson) into believeing that the laws were not as broad-ranging as they actually were (though you&#8217;ve got to wonder if anybody actually <em>reads</em> what they&#8217;re voting for?). Says the shadow attorney-general Vickie Chapman:</p>

<blockquote>&#8220;He clearly wanted to use this legislation to hunt down any of those who criticised him or the Government and that was made absolutely clear yesterday by his statements and behaviour&#8221;</blockquote>

<p>Which seems very much inline with some of the other stuff that Atkinson has been doing over the last few months</p>

<p>This whole thing is really wierd, in my opinion. Atkinson seems to have this bizzare persecution complex&#8230; anyway, it&#8217;ll be interesting to see what happens in March.</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2010/02/03/sa-politician-admit-they-re-a-bunch-of-out-of-touch-old-fogeys">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2010/02/03/sa-politician-admit-they-re-a-bunch-of-out-of-touch-old-fogeys#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=290</wfw:commentRss>
		</item>
				<item>
			<title>War Worlds packet structure</title>
			<link>http://codeka.com/blogs/index.php/2010/01/19/war-worlds-packet-structure</link>
			<pubDate>Tue, 19 Jan 2010 07:36:02 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">War Worlds</category>			<guid isPermaLink="false">287@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;I thought today I would take some time to describe the method I&amp;#8217;m using for building, serialising and deserialising the network packets in War Worlds. I am using &lt;a href=&quot;http://enet.bespin.org/&quot;&gt;ENet&lt;/a&gt; as the underlying network protocol, which means the War Worlds networking system is based on UDP.&lt;/p&gt;

&lt;p&gt;I won&amp;#8217;t go into too much detail on how connections and such are managed, since a lot of that stuff is handled pretty well by ENet already. What ENet &lt;em&gt;doesn&amp;#8217;t&lt;/em&gt; handle, though, is how you structure your packets - from ENet&amp;#8217;s point of view, you just get an array of bytes. But that&amp;#8217;s not much use to us, since we think in terms of objects and fields. So the question is, how do we map between our objects and a simple byte array and back again?&lt;/p&gt;

&lt;p&gt;When I started doing this stuff, I looked into &lt;a href=&quot;http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/index.html&quot;&gt;Boost.Serialization&lt;/a&gt;, but I found it to be rather too much for the relatively simple requirements that I had. I decided that I could implement it myself in a short enough time and have full control over the serialised format.&lt;/p&gt;

&lt;p&gt;The first part of solution comes from the &lt;tt&gt;packet_buffer&lt;/tt&gt; class which works much like a SC++L stream (though much simplified) and lets us build up the binary data in a fairly easy and intuitive way. A basic outline of it&amp;#8217;s implementation is below (I&amp;#8217;ve omitted the implementation of the more obvious methods):&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C++:&lt;/div&gt;&lt;div class=&quot;code-block code-cpp code-long&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; packet_buffer&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;bool&lt;/span&gt; flushed_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt; value_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;stringstream&lt;/span&gt; buffer_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint16_t packet_type_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; flush&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; packet_buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint16_t packet_type&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; packet_buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;bytes, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; ~packet_buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; add_bytes&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;bytes, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; offset, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; get_bytes&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;bytes, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; offset, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;get_buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; get_size&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint16_t get_packet_type&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; packet_type_; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; packet_buffer&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;add_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;bytes, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; offset, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; flushed_ &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer_.&lt;span style=&quot;color: #007788;&quot;&gt;write&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;bytes &lt;span style=&quot;color: #000040;&quot;&gt;+&lt;/span&gt; offset, n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; packet_buffer&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;get_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;bytes, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; offset, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer_.&lt;span style=&quot;color: #007788;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;bytes &lt;span style=&quot;color: #000040;&quot;&gt;+&lt;/span&gt; offset, n&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; packet_buffer&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;flush&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;flushed_&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer_.&lt;span style=&quot;color: #007788;&quot;&gt;flush&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; value_ &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; buffer_.&lt;span style=&quot;color: #007788;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; flushed_ &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;packet_buffer&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;get_buffer&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; flush&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; value_.&lt;span style=&quot;color: #007788;&quot;&gt;c_str&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;size_t&lt;/span&gt; packet_buffer&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;get_size&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; flush&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; value_.&lt;span style=&quot;color: #007788;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This provides the basic implementation of the &amp;#8220;buffer&amp;#8221;. As you can see, it&amp;#8217;s a pretty basic wrapper around &lt;tt&gt;std::stringstream&lt;/tt&gt; (though we could&amp;#8217;ve used &lt;tt&gt;std::vector&amp;lt;uint8_t&amp;gt;&lt;/tt&gt; or something as well). The slightly more interesting aspect is the following helpers:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C++:&lt;/div&gt;&lt;div class=&quot;code-block code-cpp code-long&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, int32_t rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;add_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, int32_t &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;get_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #666666;&quot;&gt;// (more here for int16_t, uint32_t, etc...&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, vector &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;add_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;rhs.&lt;span style=&quot;color: #007788;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, vector &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;get_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;rhs.&lt;span style=&quot;color: #007788;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, colour &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint32_t rgba &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; rhs.&lt;span style=&quot;color: #007788;&quot;&gt;to_rgba&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;add_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rgba&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint32_t&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, colour &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint32_t rgba;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;get_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rgba&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint32_t&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; rhs &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;colour&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;rgba&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #666666;&quot;&gt;// strings are length-prefixed&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint16_t length &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;static_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;uint16_t&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;rhs.&lt;span style=&quot;color: #007788;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; length;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;add_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;rhs.&lt;span style=&quot;color: #007788;&quot;&gt;c_str&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, length&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;operator &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;lhs, std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;rhs&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; uint16_t length;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; length;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;value &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;_malloca&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;length&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; lhs.&lt;span style=&quot;color: #007788;&quot;&gt;get_bytes&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;value, &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;, length&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; rhs &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;value, length&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; lhs;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So as you can see, these functions are what actually make it easy to serialise things. Want to serialise a string? Just use &lt;tt&gt;operator &amp;lt;&amp;lt;&lt;/tt&gt; to stream it in. An example of one of my packet classes is below, to show you the basic usage of my class:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C++:&lt;/div&gt;&lt;div class=&quot;code-block code-cpp code-long&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #666666;&quot;&gt;// this packet is sent from the server when you connect to it&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; join_response_packet &lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt; map_name_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;vector&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;uint32_t&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; other_users_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;colour&lt;/span&gt; my_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;colour&lt;/span&gt; your_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; serialise&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_buffer&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; deserialise&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_buffer&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; join_response_packet&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; ~join_response_packet&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #666666;&quot;&gt;// etc...&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #666666;&quot;&gt;// (I'll get to these in a second)&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; identifier &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;123&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; uint16_t get_identifier&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; identifier; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; join_response_packet&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;serialise&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_buffer&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; map_name_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; other_users_.&lt;span style=&quot;color: #007788;&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; BOOST_FOREACH&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint32_t sess_id, other_users_&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; sess_id;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; my_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; your_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; join_response_packet&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;deserialise&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_buffer&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buffer&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;typedef&lt;/span&gt; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;vector&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;size_type&lt;/span&gt; size_type;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; map_name_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; size_type num_other_users;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; num_other_users;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;size_type i &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;; i &lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt; num_other_users; i&lt;span style=&quot;color: #000040;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uint32_t other_user;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; other_user;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; other_users_.&lt;span style=&quot;color: #007788;&quot;&gt;push_back&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;other_user&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; my_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; buffer &lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; your_colour_;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As you can see, when you join a new game, the server sends to you the current name of the map (a string), the session identifiers for all the other connected players (integers) and the &amp;#8220;colour&amp;#8221; of yourself and the server (this is used to differentiate between players in the game: red vs. blue, etc).&lt;/p&gt;

&lt;p&gt;The final difficulty comes when you receive a &amp;#8220;bunch of bytes&amp;#8221; from your peer. How do you know &lt;em&gt;which&lt;/em&gt; class to deserialize? This is the only place where a bit of macro magic happens (and that&amp;#8217;s really just to save a bit of typing). First of all, the header file:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C++:&lt;/div&gt;&lt;div class=&quot;code-block code-cpp code-short&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #666666;&quot;&gt;// this macro is used by the packet class to &amp;quot;register&amp;quot; itself&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#define PACKET_REGISTER(type) \&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; shared_ptr&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; create_ &lt;span style=&quot;color: #339900;&quot;&gt;## type () { \&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; shared_ptr&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; type&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt; \&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; fw&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_registrar&lt;/span&gt; reg_ &lt;span style=&quot;color: #339900;&quot;&gt;## type(type::identifier, create_ ## type)&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #666666;&quot;&gt;// this is what you call to create an instance of a packet from a packet_buffer&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;shared_ptr&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;packet&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; create_packet&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buff&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;typedef&lt;/span&gt; shared_ptr&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;packet&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;create_packet_fn&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; packet_registrar&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; packet_registrar&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint16_t id, create_packet_fn fn&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And the corresponding .cpp file:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C++:&lt;/div&gt;&lt;div class=&quot;code-block code-cpp code-short&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;uint16_t, create_packet_fn&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;packet_registry &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;shared_ptr&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;packet&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt; create_packet&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_buffer &lt;span style=&quot;color: #000040;&quot;&gt;&amp;amp;&lt;/span&gt;buff&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; create_packet_fn fn &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;packet_registry&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#91;&lt;/span&gt;buff.&lt;span style=&quot;color: #007788;&quot;&gt;get_packet_type&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;fn &lt;span style=&quot;color: #000080;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #666666;&quot;&gt;// error!&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; fn&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;packet_registrar&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;packet_registrar&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;uint16_t id, create_packet_fn fn&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;packet_registry &lt;span style=&quot;color: #000080;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color:#800080;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; packet_registry &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; std&lt;span style=&quot;color: #008080;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #007788;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #000080;&quot;&gt;&amp;lt;&lt;/span&gt;uint16_t, create_packet_fn&lt;span style=&quot;color: #000080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000040;&quot;&gt;*&lt;/span&gt;packet_registry&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#91;&lt;/span&gt;id&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000080;&quot;&gt;=&lt;/span&gt; fn;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-0&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So at the top of the .cpp for the packet, we just call the &lt;tt&gt;PACKET_REGISTER(packet_type)&lt;/tt&gt; macro and it&amp;#8217;ll register itself with the system. This is what the &lt;tt&gt;identifier&lt;/tt&gt; member of the packet class is for: it&amp;#8217;s used by the &lt;tt&gt;PACKET_REGISTER&lt;/tt&gt; macro to assign an integer to that packet type which we put into the packet_buffer when sending it to the other side.&lt;/p&gt;

&lt;p&gt;For the time being, I&amp;#8217;m just manually giving each packet type a unique identifier by hand. It&amp;#8217;s not that much trouble (and there&amp;#8217;s not a whole lot of packet types to do anyway). I&amp;#8217;ve also got some error checking code in my &lt;tt&gt;packet_registrar::packet_registrar&lt;/tt&gt; method so that if two classes have the same identifier, it logs the error so I can fix it.&lt;/p&gt;

&lt;p&gt;And so, that&amp;#8217;s basically it. The system is very simple, doesn&amp;#8217;t take much to maintain and it will allow me (in the future) to handle some more advanced scenarios with relative ease (for example, I could use a variable-length encoding for integers to save space, I could implement compression, or I could add packet coalescing).&lt;/p&gt;

&lt;p&gt;Next time, I&amp;#8217;ll hopefully have some more screenshots or videos to show. I&amp;#8217;m in the process of implementing some basic pathfinding, which has been fun and gives the units some much more &amp;#8220;intelligent&amp;#8221; (looking) behaviour&amp;#8230;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2010/01/19/war-worlds-packet-structure&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I thought today I would take some time to describe the method I&#8217;m using for building, serialising and deserialising the network packets in War Worlds. I am using <a href="http://enet.bespin.org/">ENet</a> as the underlying network protocol, which means the War Worlds networking system is based on UDP.</p>

<p>I won&#8217;t go into too much detail on how connections and such are managed, since a lot of that stuff is handled pretty well by ENet already. What ENet <em>doesn&#8217;t</em> handle, though, is how you structure your packets - from ENet&#8217;s point of view, you just get an array of bytes. But that&#8217;s not much use to us, since we think in terms of objects and fields. So the question is, how do we map between our objects and a simple byte array and back again?</p>

<p>When I started doing this stuff, I looked into <a href="http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/index.html">Boost.Serialization</a>, but I found it to be rather too much for the relatively simple requirements that I had. I decided that I could implement it myself in a short enough time and have full control over the serialised format.</p>

<p>The first part of solution comes from the <tt>packet_buffer</tt> class which works much like a SC++L stream (though much simplified) and lets us build up the binary data in a fairly easy and intuitive way. A basic outline of it&#8217;s implementation is below (I&#8217;ve omitted the implementation of the more obvious methods):</p>

<div class="code-name">C++:</div><div class="code-block code-cpp code-long"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">class</span> packet_buffer<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #0000ff;">private</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">bool</span> flushed_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> value_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code>&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">stringstream</span> buffer_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint16_t packet_type_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">void</span> flush<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; packet_buffer<span style="color: #008000;">&#40;</span>uint16_t packet_type<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; packet_buffer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span>bytes, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> n<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; ~packet_buffer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">void</span> add_bytes<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span>bytes, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> offset, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> n<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">void</span> get_bytes<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>bytes, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> offset, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> n<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span>get_buffer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> get_size<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint16_t get_packet_type<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> packet_type_; <span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #0000ff;">void</span> packet_buffer<span style="color: #008080;">::</span><span style="color: #007788;">add_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span>bytes, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> offset, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> n<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; flushed_ <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer_.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span>bytes <span style="color: #000040;">+</span> offset, n<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #0000ff;">void</span> packet_buffer<span style="color: #008080;">::</span><span style="color: #007788;">get_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>bytes, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> offset, std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> n<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer_.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span>bytes <span style="color: #000040;">+</span> offset, n<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-3"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #0000ff;">void</span> packet_buffer<span style="color: #008080;">::</span><span style="color: #007788;">flush</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>flushed_<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-3"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer_.<span style="color: #007788;">flush</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; value_ <span style="color: #000080;">=</span> buffer_.<span style="color: #007788;">str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; flushed_ <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span>packet_buffer<span style="color: #008080;">::</span><span style="color: #007788;">get_buffer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; flush<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> value_.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-5"></div></td><td class="code-code"><code>std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> packet_buffer<span style="color: #008080;">::</span><span style="color: #007788;">get_size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-5"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; flush<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> value_.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-5"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span></code></td></tr>
</table></div>

<p>This provides the basic implementation of the &#8220;buffer&#8221;. As you can see, it&#8217;s a pretty basic wrapper around <tt>std::stringstream</tt> (though we could&#8217;ve used <tt>std::vector&lt;uint8_t&gt;</tt> or something as well). The slightly more interesting aspect is the following helpers:</p>

<div class="code-name">C++:</div><div class="code-block code-cpp code-long"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&lt;&lt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, int32_t rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">add_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&gt;&gt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, int32_t <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">get_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #666666;">// (more here for int16_t, uint32_t, etc...</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-1"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&lt;&lt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, vector <span style="color: #0000ff;">const</span> <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">add_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>rhs.<span style="color: #007788;">data</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-2"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&gt;&gt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, vector <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">get_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>rhs.<span style="color: #007788;">data</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-2"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&lt;&lt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, colour <span style="color: #0000ff;">const</span> <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint32_t rgba <span style="color: #000080;">=</span> rhs.<span style="color: #007788;">to_rgba</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">add_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>rgba<span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>uint32_t<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-3"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-3"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&gt;&gt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, colour <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint32_t rgba;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">get_bytes</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>rgba<span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>uint32_t<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; rhs <span style="color: #000080;">=</span> fw<span style="color: #008080;">::</span><span style="color: #007788;">colour</span><span style="color: #008000;">&#40;</span>rgba<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-4"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&lt;&lt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #666666;">// strings are length-prefixed</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint16_t length <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span>uint16_t<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>rhs.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs <span style="color: #000080;">&lt;&lt;</span> length;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">add_bytes</span><span style="color: #008000;">&#40;</span>rhs.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0</span>, length<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-5"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-5"></div></td><td class="code-code"><code>packet_buffer <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">&gt;&gt;</span><span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>lhs, std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000040;">&amp;</span>rhs<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-5"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; uint16_t length;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs <span style="color: #000080;">&gt;&gt;</span> length;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-5"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>value <span style="color: #000080;">=</span> <span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>_malloca<span style="color: #008000;">&#40;</span>length<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; lhs.<span style="color: #007788;">get_bytes</span><span style="color: #008000;">&#40;</span>value, <span style="color:#800080;">0</span>, length<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; rhs <span style="color: #000080;">=</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#40;</span>value, length<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-5"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-6"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> lhs;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-6"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span></code></td></tr>
</table></div>

<p>So as you can see, these functions are what actually make it easy to serialise things. Want to serialise a string? Just use <tt>operator &lt;&lt;</tt> to stream it in. An example of one of my packet classes is below, to show you the basic usage of my class:</p>

<div class="code-name">C++:</div><div class="code-block code-cpp code-long"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #666666;">// this packet is sent from the server when you connect to it</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #0000ff;">class</span> join_response_packet <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #0000ff;">private</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> map_name_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code>&nbsp; &nbsp; std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span>uint32_t<span style="color: #000080;">&gt;</span> other_users_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code>&nbsp; &nbsp; fw<span style="color: #008080;">::</span><span style="color: #007788;">colour</span> my_colour_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code>&nbsp; &nbsp; fw<span style="color: #008080;">::</span><span style="color: #007788;">colour</span> your_colour_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> serialise<span style="color: #008000;">&#40;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet_buffer</span> <span style="color: #000040;">&amp;</span>buffer<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> deserialise<span style="color: #008000;">&#40;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet_buffer</span> <span style="color: #000040;">&amp;</span>buffer<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; join_response_packet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">virtual</span> ~join_response_packet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #666666;">// etc...</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #666666;">// (I'll get to these in a second)</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> identifier <span style="color: #000080;">=</span> <span style="color: #0000dd;">123</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">virtual</span> uint16_t get_identifier<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> identifier; <span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #0000ff;">void</span> join_response_packet<span style="color: #008080;">::</span><span style="color: #007788;">serialise</span><span style="color: #008000;">&#40;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet_buffer</span> <span style="color: #000040;">&amp;</span>buffer<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&lt;&lt;</span> map_name_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&lt;&lt;</span> other_users_.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; BOOST_FOREACH<span style="color: #008000;">&#40;</span>uint32_t sess_id, other_users_<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; buffer <span style="color: #000080;">&lt;&lt;</span> sess_id;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&lt;&lt;</span> my_colour_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&lt;&lt;</span> your_colour_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-3"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #0000ff;">void</span> join_response_packet<span style="color: #008080;">::</span><span style="color: #007788;">deserialise</span><span style="color: #008000;">&#40;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet_buffer</span> <span style="color: #000040;">&amp;</span>buffer<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-3"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">typedef</span> std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">size_type</span> size_type;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&gt;&gt;</span> map_name_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; size_type num_other_users;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&gt;&gt;</span> num_other_users;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>size_type i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;</span> num_other_users; i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; uint32_t other_user;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; buffer <span style="color: #000080;">&gt;&gt;</span> other_user;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; other_users_.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>other_user<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&gt;&gt;</span> my_colour_;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; buffer <span style="color: #000080;">&gt;&gt;</span> your_colour_;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-5"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span></code></td></tr>
</table></div>

<p>As you can see, when you join a new game, the server sends to you the current name of the map (a string), the session identifiers for all the other connected players (integers) and the &#8220;colour&#8221; of yourself and the server (this is used to differentiate between players in the game: red vs. blue, etc).</p>

<p>The final difficulty comes when you receive a &#8220;bunch of bytes&#8221; from your peer. How do you know <em>which</em> class to deserialize? This is the only place where a bit of macro magic happens (and that&#8217;s really just to save a bit of typing). First of all, the header file:</p>

<div class="code-name">C++:</div><div class="code-block code-cpp code-short"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #666666;">// this macro is used by the packet class to &quot;register&quot; itself</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #339900;">#define PACKET_REGISTER(type) \</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; shared_ptr<span style="color: #000080;">&lt;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet</span><span style="color: #000080;">&gt;</span> create_ <span style="color: #339900;">## type () { \</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> shared_ptr<span style="color: #000080;">&lt;</span>fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> type<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>; <span style="color: #008000;">&#125;</span> \<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; fw<span style="color: #008080;">::</span><span style="color: #007788;">net</span><span style="color: #008080;">::</span><span style="color: #007788;">packet_registrar</span> reg_ <span style="color: #339900;">## type(type::identifier, create_ ## type)</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code><span style="color: #666666;">// this is what you call to create an instance of a packet from a packet_buffer</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code>shared_ptr<span style="color: #000080;">&lt;</span>packet<span style="color: #000080;">&gt;</span> create_packet<span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>buff<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">typedef</span> shared_ptr<span style="color: #000080;">&lt;</span>packet<span style="color: #000080;">&gt;</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>create_packet_fn<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">class</span> packet_registrar<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; packet_registrar<span style="color: #008000;">&#40;</span>uint16_t id, create_packet_fn fn<span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span>;</code></td></tr>
</table></div>

<p>And the corresponding .cpp file:</p>

<div class="code-name">C++:</div><div class="code-block code-cpp code-short"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0000ff;">static</span> std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>uint16_t, create_packet_fn<span style="color: #000080;">&gt;</span> <span style="color: #000040;">*</span>packet_registry <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>shared_ptr<span style="color: #000080;">&lt;</span>packet<span style="color: #000080;">&gt;</span> create_packet<span style="color: #008000;">&#40;</span>packet_buffer <span style="color: #000040;">&amp;</span>buff<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; create_packet_fn fn <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>packet_registry<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span>buff.<span style="color: #007788;">get_packet_type</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>fn <span style="color: #000080;">==</span> <span style="color:#800080;">0</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// error!</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-1"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">return</span> fn<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div><div class="code-line-1"></div></td><td class="code-code"><code>packet_registrar<span style="color: #008080;">::</span><span style="color: #007788;">packet_registrar</span><span style="color: #008000;">&#40;</span>uint16_t id, create_packet_fn fn<span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #008000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>packet_registry <span style="color: #000080;">==</span> <span style="color:#800080;">0</span><span style="color: #008000;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; packet_registry <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>uint16_t, create_packet_fn<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div><div class="code-line-1"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div><div class="code-line-1"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>packet_registry<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span>id<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> fn;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-0"></div><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #008000;">&#125;</span></code></td></tr>
</table></div>

<p>So at the top of the .cpp for the packet, we just call the <tt>PACKET_REGISTER(packet_type)</tt> macro and it&#8217;ll register itself with the system. This is what the <tt>identifier</tt> member of the packet class is for: it&#8217;s used by the <tt>PACKET_REGISTER</tt> macro to assign an integer to that packet type which we put into the packet_buffer when sending it to the other side.</p>

<p>For the time being, I&#8217;m just manually giving each packet type a unique identifier by hand. It&#8217;s not that much trouble (and there&#8217;s not a whole lot of packet types to do anyway). I&#8217;ve also got some error checking code in my <tt>packet_registrar::packet_registrar</tt> method so that if two classes have the same identifier, it logs the error so I can fix it.</p>

<p>And so, that&#8217;s basically it. The system is very simple, doesn&#8217;t take much to maintain and it will allow me (in the future) to handle some more advanced scenarios with relative ease (for example, I could use a variable-length encoding for integers to save space, I could implement compression, or I could add packet coalescing).</p>

<p>Next time, I&#8217;ll hopefully have some more screenshots or videos to show. I&#8217;m in the process of implementing some basic pathfinding, which has been fun and gives the units some much more &#8220;intelligent&#8221; (looking) behaviour&#8230;</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2010/01/19/war-worlds-packet-structure">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2010/01/19/war-worlds-packet-structure#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=287</wfw:commentRss>
		</item>
				<item>
			<title>AI in War Worlds</title>
			<link>http://codeka.com/blogs/index.php/2009/12/22/ai-in-war-worlds</link>
			<pubDate>Tue, 22 Dec 2009 10:40:21 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">War Worlds</category>			<guid isPermaLink="false">286@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;It&amp;#8217;s been a while since I blogged about War Worlds, and there&amp;#8217;s a good reason for that&amp;#8230; but I can&amp;#8217;t say too much about it for now &lt;img src=&quot;http://codeka.com/blogs/rsc/smilies/icon_smile.gif&quot; alt=&quot;&amp;#58;&amp;#41;&quot; class=&quot;middle&quot; /&gt; Anyway, I&amp;#8217;ve done a little bit more work on it recently, and so I thought I&amp;#8217;d just blog a little about what I&amp;#8217;ve been doing.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been working a little on the AI which, &lt;a href=&quot;http://codeka.com/blogs/index.php/2009/11/10/luabind-and-the-raw-policy&quot;&gt;as I blogged about before&lt;/a&gt;, is being done in Lua.&lt;/p&gt;

&lt;p&gt;Now, there&amp;#8217;s two main functions in the War Worlds AI which make up the bulk of the API. The first is the one I blogged about before, &lt;tt&gt;self:find_units&lt;/tt&gt;. The other one is &lt;tt&gt;self:issue_order&lt;/tt&gt; (note: &amp;#8220;self&amp;#8221; in these function calls refers to the AI&amp;#8217;s &amp;#8220;player&amp;#8221; object, kind of like &amp;#8220;this&amp;#8221; in C++). With these two APIs combined, you should be able to do pretty much any AI.&lt;/p&gt;

&lt;p&gt;Obviously, there was quite a bit of plumbing in the back-end that needed to go into it all before these could work, and they&amp;#8217;re still not the &lt;em&gt;only&lt;/em&gt; thing you&amp;#8217;ll ever call, but it&amp;#8217;s a nice start.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example of some Lua from one of the test scripts I&amp;#8217;ve written:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;Lua:&lt;/div&gt;&lt;div class=&quot;code-block code-lua code-short&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;function&lt;/span&gt; check_attack&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;local&lt;/span&gt; units &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; self:find_units&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; unit_type&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;factory&amp;quot;&lt;/span&gt;, build_state&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;idle&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; self:issue_order&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;units, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; order&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;build&amp;quot;&lt;/span&gt;, build_unit&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;simple-tank&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; self:timer&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;, check_attack&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So, line 2 of that snippet looks for all &amp;#8220;factory&amp;#8221; units whose &amp;#8220;build_state&amp;#8221; is &amp;#8220;idle&amp;#8221; (that is, all factories that are not currently building anything). The &lt;tt&gt;self:find_units&lt;/tt&gt; function returns a collection of units - you can iterate them and do stuff like that if you like, but we just want to issue them a &amp;#8220;build&amp;#8221; order to build the &amp;#8220;simple-tank&amp;#8221; unit type, which is what we do in line 3.&lt;/p&gt;

&lt;p&gt;On line 5, we call the &lt;tt&gt;self:timer&lt;/tt&gt; function to schedule ourselves to run again in 10 seconds.&lt;/p&gt;

&lt;p&gt;This is the basic way that the AI will be implemented for the initial release. I&amp;#8217;m hoping to make the AI interface generic enough that people will feel compelled to write their own AI for the game. Who knows? Maybe we could set up tournaments specifically for the AIs that people have developed!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2009/12/22/ai-in-war-worlds&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I blogged about War Worlds, and there&#8217;s a good reason for that&#8230; but I can&#8217;t say too much about it for now <img src="http://codeka.com/blogs/rsc/smilies/icon_smile.gif" alt="&#58;&#41;" class="middle" /> Anyway, I&#8217;ve done a little bit more work on it recently, and so I thought I&#8217;d just blog a little about what I&#8217;ve been doing.</p>

<p>I&#8217;ve been working a little on the AI which, <a href="http://codeka.com/blogs/index.php/2009/11/10/luabind-and-the-raw-policy">as I blogged about before</a>, is being done in Lua.</p>

<p>Now, there&#8217;s two main functions in the War Worlds AI which make up the bulk of the API. The first is the one I blogged about before, <tt>self:find_units</tt>. The other one is <tt>self:issue_order</tt> (note: &#8220;self&#8221; in these function calls refers to the AI&#8217;s &#8220;player&#8221; object, kind of like &#8220;this&#8221; in C++). With these two APIs combined, you should be able to do pretty much any AI.</p>

<p>Obviously, there was quite a bit of plumbing in the back-end that needed to go into it all before these could work, and they&#8217;re still not the <em>only</em> thing you&#8217;ll ever call, but it&#8217;s a nice start.</p>

<p>Here&#8217;s an example of some Lua from one of the test scripts I&#8217;ve written:</p>

<div class="code-name">Lua:</div><div class="code-block code-lua code-short"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #b1b100;">function</span> check_attack<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #b1b100;">local</span> units <span style="color: #66cc66;">=</span> self:find_units<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> unit_type<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;factory&quot;</span>, build_state<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;idle&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; self:issue_order<span style="color: #66cc66;">&#40;</span>units, <span style="color: #66cc66;">&#123;</span> order<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;build&quot;</span>, build_unit<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;simple-tank&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; self:timer<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>, check_attack<span style="color: #66cc66;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code><span style="color: #b1b100;">end</span></code></td></tr>
</table></div>

<p>So, line 2 of that snippet looks for all &#8220;factory&#8221; units whose &#8220;build_state&#8221; is &#8220;idle&#8221; (that is, all factories that are not currently building anything). The <tt>self:find_units</tt> function returns a collection of units - you can iterate them and do stuff like that if you like, but we just want to issue them a &#8220;build&#8221; order to build the &#8220;simple-tank&#8221; unit type, which is what we do in line 3.</p>

<p>On line 5, we call the <tt>self:timer</tt> function to schedule ourselves to run again in 10 seconds.</p>

<p>This is the basic way that the AI will be implemented for the initial release. I&#8217;m hoping to make the AI interface generic enough that people will feel compelled to write their own AI for the game. Who knows? Maybe we could set up tournaments specifically for the AIs that people have developed!</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2009/12/22/ai-in-war-worlds">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2009/12/22/ai-in-war-worlds#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=286</wfw:commentRss>
		</item>
				<item>
			<title>"The Application object is being shut down"</title>
			<link>http://codeka.com/blogs/index.php/2009/12/20/the-application-object-is-being-shut-down</link>
			<pubDate>Sun, 20 Dec 2009 04:14:52 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">.NET General</category>			<guid isPermaLink="false">285@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;As I mentioned before, I&amp;#8217;ve been doing some work in WPF recently (actually, I &lt;em&gt;was&lt;/em&gt; doing it in Silverlight, but I abandoned that due to some of the security limitations - I wanted to be able to launch Word from my app and then communicate between my Silverlight app and a Word add-in I was developing, but that wasn&amp;#8217;t possible [you can&amp;#8217;t start processes from Silverlight], so I&amp;#8217;ve switched to a WPF app deployed via ClickOnce which is probably close enough.)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Aaaaanyway&lt;/em&gt; (that was a rather long set up for the rest of my post which is actually pretty to-the-point!), my Word add-in is also WPF and I am using the hosting feature of WinForms to link my VSTO add-in to the WPF controls and so on. So far, it&amp;#8217;s been a magical experience, but I ran into a problem when trying to create a &amp;#8220;theme&amp;#8221; for my app (the default WPF theme is fugly!).&lt;/p&gt;

&lt;p&gt;I found &lt;a href=&quot;http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/&quot;&gt;this post&lt;/a&gt; on Dr. WPF&amp;#8217;s blog, and it explained one way to get application-level resources in a hosted environment (you basically just have to create the &lt;b&gt;Application&lt;/b&gt; object yourself).&lt;/p&gt;

&lt;p&gt;The only problem was that one of the buttons I have in my Ribbon opens a WPF window. If you then closed that window and clicked the button to open it again, you would get the following exception:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;Text:&lt;/div&gt;&lt;div class=&quot;code-block code-text code-short&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;An exception occured while calling function &amp;quot;ButtonClick&amp;quot;. The exception message is:&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;Thrown exception of type System.InvalidOperationException with message:&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;quot;The Application object is being shut down.&amp;quot;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;Stack trace:&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp;at System.Windows.Application.GetResourcePackage(Uri packageUri)&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-7&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp;at System.Windows.Application.GetResourceOrContentPart(Uri uri)&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-8&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp;at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-9&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp;...&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The fix was actually on that post that I linked to, but since it was in the comments, way down the bottom, I missed it on my first look. Anyway, the answer was that I had to set the ShutdownMode correctly on the application, like so:&lt;/p&gt;

&lt;div class=&quot;code-name&quot;&gt;C#:&lt;/div&gt;&lt;div class=&quot;code-block code-csharp code-short&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-1&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Windows&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Application&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Current&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-2&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-3&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Windows&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Application&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-4&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ShutdownMode &lt;span style=&quot;color: #008000;&quot;&gt;=&lt;/span&gt; ShutdownMode.&lt;span style=&quot;color: #0000FF;&quot;&gt;OnExplicitShutdown&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-odd&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-5&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;code-even&quot;&gt;&lt;td class=&quot;code-line&quot;&gt;&lt;div class=&quot;code-line-6&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code-code&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(The fully-qualified type names are required since VSTO has an &lt;b&gt;Application&lt;/b&gt; &lt;em&gt;property&lt;/em&gt; that was otherwise interfering)&lt;/p&gt;

&lt;p&gt;If you don&amp;#8217;t set ShutdownMode correctly, the default action is that the first window to be opened is designated as the &amp;#8220;main&amp;#8221; window, and so when the main window closes, WPF will shut down the Application object as well. By setting it to OnExplicitShutdown, you have to remember to explcitly call Application.Shutdown, but at least we have explicit control over when it happens.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2009/12/20/the-application-object-is-being-shut-down&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>As I mentioned before, I&#8217;ve been doing some work in WPF recently (actually, I <em>was</em> doing it in Silverlight, but I abandoned that due to some of the security limitations - I wanted to be able to launch Word from my app and then communicate between my Silverlight app and a Word add-in I was developing, but that wasn&#8217;t possible [you can&#8217;t start processes from Silverlight], so I&#8217;ve switched to a WPF app deployed via ClickOnce which is probably close enough.)</p>

<p><em>Aaaaanyway</em> (that was a rather long set up for the rest of my post which is actually pretty to-the-point!), my Word add-in is also WPF and I am using the hosting feature of WinForms to link my VSTO add-in to the WPF controls and so on. So far, it&#8217;s been a magical experience, but I ran into a problem when trying to create a &#8220;theme&#8221; for my app (the default WPF theme is fugly!).</p>

<p>I found <a href="http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/">this post</a> on Dr. WPF&#8217;s blog, and it explained one way to get application-level resources in a hosted environment (you basically just have to create the <b>Application</b> object yourself).</p>

<p>The only problem was that one of the buttons I have in my Ribbon opens a WPF window. If you then closed that window and clicked the button to open it again, you would get the following exception:</p>

<div class="code-name">Text:</div><div class="code-block code-text code-short"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code>An exception occured while calling function &quot;ButtonClick&quot;. The exception message is:<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>Thrown exception of type System.InvalidOperationException with message:<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp;&quot;The Application object is being shut down.&quot;<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>Stack trace:<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code>&nbsp; &nbsp;at System.Windows.Application.GetResourcePackage(Uri packageUri)<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-7"></div></td><td class="code-code"><code>&nbsp; &nbsp;at System.Windows.Application.GetResourceOrContentPart(Uri uri)<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-8"></div></td><td class="code-code"><code>&nbsp; &nbsp;at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)<br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-9"></div></td><td class="code-code"><code>&nbsp; &nbsp;...</code></td></tr>
</table></div>

<p>The fix was actually on that post that I linked to, but since it was in the comments, way down the bottom, I missed it on my first look. Anyway, the answer was that I had to set the ShutdownMode correctly on the application, like so:</p>

<div class="code-name">C#:</div><div class="code-block code-csharp code-short"><table cellpadding="0" cellspacing="0"><tr class="code-odd"><td class="code-line"><div class="code-line-1"></div></td><td class="code-code"><code><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Application</span>.<span style="color: #0000FF;">Current</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-2"></div></td><td class="code-code"><code><span style="color: #000000;">&#123;</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-3"></div></td><td class="code-code"><code>&nbsp; &nbsp; <span style="color: #008000;">new</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Application</span> <span style="color: #000000;">&#123;</span><br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-4"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShutdownMode <span style="color: #008000;">=</span> ShutdownMode.<span style="color: #0000FF;">OnExplicitShutdown</span><br /></code></td></tr>
<tr class="code-odd"><td class="code-line"><div class="code-line-5"></div></td><td class="code-code"><code>&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span>;<br /></code></td></tr>
<tr class="code-even"><td class="code-line"><div class="code-line-6"></div></td><td class="code-code"><code><span style="color: #000000;">&#125;</span></code></td></tr>
</table></div>

<p>(The fully-qualified type names are required since VSTO has an <b>Application</b> <em>property</em> that was otherwise interfering)</p>

<p>If you don&#8217;t set ShutdownMode correctly, the default action is that the first window to be opened is designated as the &#8220;main&#8221; window, and so when the main window closes, WPF will shut down the Application object as well. By setting it to OnExplicitShutdown, you have to remember to explcitly call Application.Shutdown, but at least we have explicit control over when it happens.</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2009/12/20/the-application-object-is-being-shut-down">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2009/12/20/the-application-object-is-being-shut-down#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=285</wfw:commentRss>
		</item>
				<item>
			<title>How to write programs in Silverlight</title>
			<link>http://codeka.com/blogs/index.php/2009/11/23/how-to-write-programs-in-silverlight</link>
			<pubDate>Mon, 23 Nov 2009 07:27:52 +0000</pubDate>			<dc:creator>Dean Harding</dc:creator>
			<category domain="main">Technical</category>
<category domain="alt">Rants</category>
<category domain="alt">.NET General</category>			<guid isPermaLink="false">284@http://codeka.com/blogs/</guid>
						<description>&lt;p&gt;I&amp;#8217;ve been playing around with Silverlight recently, and I&amp;#8217;ve discovered that my method of programming in Silverlight is slightly different to programming with any other framework that I&amp;#8217;ve used in the past.&lt;/p&gt;

&lt;p&gt;Normally, I&amp;#8217;ll read an &amp;#8220;introduction&amp;#8221; or &amp;#8220;getting started&amp;#8221; style guide, which will usually get you a basic &amp;#8220;hello world&amp;#8221; or whatever, and then it&amp;#8217;s usually a fairly simple matter of adding functionality to that until I get whatever I was trying to do in the first place.&lt;/p&gt;

&lt;p&gt;For example, my recent forays into &lt;a href=&quot;http://codeka.com/blogs/index.php/2009/11/10/luabind-and-the-raw-policy&quot;&gt;Lua and Luabind&lt;/a&gt; were like that. I started off reading the &amp;#8220;&lt;a href=&quot;http://www.lua.org/pil/&quot;&gt;Programming in Lua&lt;/a&gt;&amp;#8221; book, which gave an overview of the language itself, then I used the fantastic &lt;a href=&quot;http://www.rasterbar.com/products/luabind/docs.html&quot;&gt;Luabind documentation&lt;/a&gt; to fill in the gaps of how to integrate it with my game.&lt;/p&gt;

&lt;p&gt;Now, I did struggle a bit with one or two things (as you can see my blog post), but for the most part it was exceedingly simple and I was up and running in about 3 days.&lt;/p&gt;

&lt;p&gt;But Silverlight has been different. The way I&amp;#8217;ve been programming in Silverlight is:&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;Decide what I want to do next&lt;/li&gt;&lt;li&gt;Fumble around with the classes, properties and methods I can see in the Intellisense list&lt;/li&gt;&lt;li&gt;Give up and google search&lt;/li&gt;&lt;li&gt;Find a post on the Silverlight forums, Stack Overflow, or something like that&lt;/li&gt;&lt;li&gt;Do whatever it says to get stuff to work&lt;/li&gt;&lt;li&gt;Go to step #1&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;I don&amp;#8217;t know if it&amp;#8217;s just because the Silverlight framework is so huge (though I never had this problem with Win Forms or ASP.NET, I&amp;#8217;m sure) maybe it&amp;#8217;s just because in the past, when I&amp;#8217;ve started on a new technology, it&amp;#8217;s usually been by starting with an existing codebase (that is, when I start a new job), or whether it&amp;#8217;s just because Silverlight really is that confusing and inconsistent.&lt;/p&gt;

&lt;p&gt;Anyway, I&amp;#8217;ll stick with it, and hopefully I&amp;#8217;ll have that &amp;#8220;aha!&amp;#8221; moment when it&amp;#8217;ll all start to fall into place and I&amp;#8217;m no longer just fumbling around in the dark&amp;#8230; we&amp;#8217;ll see.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://codeka.com/blogs/index.php/2009/11/23/how-to-write-programs-in-silverlight&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with Silverlight recently, and I&#8217;ve discovered that my method of programming in Silverlight is slightly different to programming with any other framework that I&#8217;ve used in the past.</p>

<p>Normally, I&#8217;ll read an &#8220;introduction&#8221; or &#8220;getting started&#8221; style guide, which will usually get you a basic &#8220;hello world&#8221; or whatever, and then it&#8217;s usually a fairly simple matter of adding functionality to that until I get whatever I was trying to do in the first place.</p>

<p>For example, my recent forays into <a href="http://codeka.com/blogs/index.php/2009/11/10/luabind-and-the-raw-policy">Lua and Luabind</a> were like that. I started off reading the &#8220;<a href="http://www.lua.org/pil/">Programming in Lua</a>&#8221; book, which gave an overview of the language itself, then I used the fantastic <a href="http://www.rasterbar.com/products/luabind/docs.html">Luabind documentation</a> to fill in the gaps of how to integrate it with my game.</p>

<p>Now, I did struggle a bit with one or two things (as you can see my blog post), but for the most part it was exceedingly simple and I was up and running in about 3 days.</p>

<p>But Silverlight has been different. The way I&#8217;ve been programming in Silverlight is:</p>

<ol><li>Decide what I want to do next</li><li>Fumble around with the classes, properties and methods I can see in the Intellisense list</li><li>Give up and google search</li><li>Find a post on the Silverlight forums, Stack Overflow, or something like that</li><li>Do whatever it says to get stuff to work</li><li>Go to step #1</li></ol>

<p>I don&#8217;t know if it&#8217;s just because the Silverlight framework is so huge (though I never had this problem with Win Forms or ASP.NET, I&#8217;m sure) maybe it&#8217;s just because in the past, when I&#8217;ve started on a new technology, it&#8217;s usually been by starting with an existing codebase (that is, when I start a new job), or whether it&#8217;s just because Silverlight really is that confusing and inconsistent.</p>

<p>Anyway, I&#8217;ll stick with it, and hopefully I&#8217;ll have that &#8220;aha!&#8221; moment when it&#8217;ll all start to fall into place and I&#8217;m no longer just fumbling around in the dark&#8230; we&#8217;ll see.</p><div class="item_footer"><p><small><a href="http://codeka.com/blogs/index.php/2009/11/23/how-to-write-programs-in-silverlight">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
								<comments>http://codeka.com/blogs/index.php/2009/11/23/how-to-write-programs-in-silverlight#comments</comments>
			<wfw:commentRss>http://codeka.com/blogs/index.php?tempskin=_rss2&#38;disp=comments&#38;p=284</wfw:commentRss>
		</item>
			</channel>
</rss>
