serial.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta name="description" content="">
  8. <title>serial | Casey DeLorme's Portfolio / caseydelorme.com</title>
  9. <link rel="icon" type="image/x-icon" href="https://d2xxklvztqk0jd.cloudfront.net/favicon.ico" />
  10. <link rel="stylesheet" type="text/css" href="/css/main.css#9eb699d">
  11. </head>
  12. <body>
  13. <header class="group">
  14. <h1><a href='/'>Casey DeLorme</a></h1>
  15. <nav>
  16. <ul>
  17. <li><a href="/projects">Projects</a></li>
  18. <li><a href="/resume.html">Resume</a></li>
  19. </ul>
  20. </nav>
  21. </header>
  22. <div class="content group">
  23. <h3><a href="https://github.com/cdelorme/serial">serial</a></h3>
  24. <p>I began reading some interesting articles by <a href="http://gafferongames.com/">Glenn Fiedler</a>, who had a particular series about writing a custom UDP protocol.</p>
  25. <p>At one point he expressed the concern for sending data over the network, stating that json is massive, and a binary serialization pattern that exposes a bidirectional workflow for both reading and writing works best.</p>
  26. <p>I decided to give a try writing it in go, and at first I followed strict syntax rules, but since the binary documentation is very good I eventually went back to a much simpler project implementation with no attempt to handle variable sized types.</p>
  27. <p>I also created a set of benchmarks to compare both the performance, memory management, and byte size between this system, <a href="https://github.com/tinylib/msgp">msgp</a>, and the <a href="https://golang.org/pkg/encoding/gob/">gob package</a>. _This is a proof-of-concept, so I am not attempting to <a href="https://github.com/alecthomas/go_serialization_benchmarks">compete</a>._</p>
  28. <p>While mine is not the fastest, it is by far the smallest, which proves that a very simple thin wrapper to abstract read and write behavior, and extra effort to write your own byte conversion logic, can be extremely beneficial in situations where every byte counts.</p>
  29. <p><em>I also concluded that while the gain is significant, for a first-draft msgp is substantially easier to wield and might be worth the trade-off if you are dealing with a large number of structures and don&rsquo;t have time to write binary serialization for each.</em></p>
  30. <p>One major complexity with the go implementation that I couldn&rsquo;t quite deal with was variable-sized data. Anytime an nondeterministic slice or string are written, extra effort must be made to keep tabs on the size when restoring it. <em>While I had written a solution to do this, it was crappy and limited to strings only.</em></p>
  31. <p>This project also helped me realize the significance between big and little endian encoding, as well as 32 vs 64 bit consistency. The fact that go abstracts endianness and optimizes little endian is awesome, but abstracted <code>int</code> types with variable size make for a hell of a mess when trying to connect a 32-bit client to a 64-bit server without having to add a myriad of casting for any case where you used a generic <code>int</code> (<em>since data loss can occur when sending an <code>int</code> from a 64 bit service to a 32 bit service</em>).</p>
  32. <p><strong><em>written on 2017-04-13</em></strong></p>
  33. </div>
  34. <footer class="group">
  35. <a href='https://www.facebook.com/CaseyRDeLorme' class='link facebook'></a>
  36. <a href='https://www.linkedin.com/in/cdelorme' class='link linkedin'></a>
  37. <a href='https://www.youtube.com/user/LordOfElm' class='link youtube'></a>
  38. <a href='https://github.com/cdelorme' class='link github'></a>
  39. <a href='skype:casey.delorme?chat' class='link skype'></a>
  40. <div class="scripts">
  41. <script type="text/javascript" src="/js/main.js#9eb699d" async></script>
  42. </div>
  43. </footer>
  44. </body>
  45. </html>