elm-city-craftworks/course-001 — pull request #7 by eregon (2014-04-21 09:44:54+00:00)
Title: A quite extensive implementation of msgpack

This is based on #6 but handle things much more cleanly.
It implements a large part of the msgpack types, and most notably implement most of the types which are constants of Object (see `tests.rb`).

It also does it quite efficiently in terms of space, by having a fixed number of elements to dump for a given extended type, and dumping them sequentially.
Each element keeps its type header (which is really needed for int and varying-length types), except in the case the type can be represented as a single String (with `#to_s`), in which case the String bytes are directly the extended type data, making the overhead of only 2 bytes (the extended type and the size (which would be required if str.length > 31)).

The implementation also tries to use `fixext` 1,2,4,8,16 when possible.
Unfortunately, as msgpack allows `fixext` only for power-of-2 sizes, this is not possible for example with a fixext of contents size 3.

Note the packing of extended types is nicely expressed in a declarative way.