TooTallNate/node-spotify-web — pull request #57 by adammw (2013-12-03 10:27:51+00:00)
Title: Protobuf.js (again)

Follows on from #30, #31.
cc @silvinci, @mauimauer, @TooTallNate

This PR allows the use of either protobufjs or protobuf (default) depending on what's on the system, and moves protobuf to an optional dependency.

Protobuf and protobufjs work in rather different ways, schema.js has been rewritten as a kind of abstraction layer / wrapper. Rather than getting the Message objects out of an object map, they are now retrieved via a `schemas.build(package, message)` call.

Protobufjs works with the field names as specified in the proto files, ie. written with_underscores as opposed to the camelCase conversion that protobuf does automatically, so in the parse and serialize wrapper functions (that are meant to emulate protobuf's equivilants), it changes around the key names. Protobufjs seems to support the import declarations, so they are used to load multiple files for the playlist protobuf files. To implement the same thing on protobuf, it instead uses a dumb loop trying each of the files until it finds one that works.

As protobuf and protobufjs work on different files (ie. protobuf works on the compiled .desc files and protobufjs works on the uncompiled .proto files) we will need to ensure that they stay in sync.

All in all, although it can be done, it may end up being easier to drop protobuf completely (as was first suggested many months ago) in favour of using protobufjs's api directly.