mapbox/geobuf — pull request #17 by brendan-ward (2014-11-17 06:44:13+00:00)
Title: Switched to protocol-buffers, consolidated duplicate code in loops

This PR resolves #10 and #16. In my own tests, this is faster than the prior implementation but produces files a little bigger.

The API for protocol-buffers is a bit different than for ```protobufjs```; this required rewriting most of the touch points to objects created via ```protobufjs```.

The biggest change required was the addition of an enum-based field to ```geobuf.proto``` to track the value type of a property's value. This is because ```protocol-buffers``` returns default values for all value types (e.g., ```''``` for strings and ```0``` for numeric types instead of ```null```), which made it much more difficult to introspect the values themselves to determine type (because ```''``` may indicate the actual value if it was originally a string type but blank, and not just indicate default). This adds a bit of extra size to the final geobuf. I've got some ideas on how this could be handled but will save those for future PRs (some ideas require bigger changes to ```geobuf.proto```). Right now it is marked as ```optional``` but is expected for decoding (so effectively ```required```). I did not add a shim for decoding geobufs that lack this.

While I was at it, I consolidated duplicate code used in the loops over coordinates.

I updated the tests, but did not push updates to ```bench.js``` (it seemed wrapped around a pretty specific benchmark).

Overall I tried to stick to the overall code style already in use.