Protocol buffers for JavaScript?

Is there a way to do protocol buffers in JavaScript?

Why for .js?

If you think about sciencey requirements for a moment, situations pop up where you might want to send a large block of data to the client. With CRUD-style it doesn’t really matter so much what you use. With sciencey stuff it does matter (at least I think it does).


  • protobuffs balances compactness, serialize and deserialize speeds well.

  • text based protocols (xml / json) have a larger message size… but with javascript I wonder which is more effective.


Additional references provided by community (see below for more context):

Google makes heavy use of Protocol Buffers in JS (GMail, etc.) through their Closure Library, generating JS code with a (unfortunately non-open-sourced) modified protoc (it would probably have to be ported to a protoc extension before being open-sourced).

Apache Wave (whose client webapp is built with GWT) also uses Protocol Buffers for its communications with the server, generating Java code by reflecting on the Java classes produced by protoc (this is the PST, aka protobuf-stringtemplate, subproject).
Previously, Wave was using protostuff (and I don’t know why they switched to their own solution, I suspect PST is derived from what the original Google Wave was using, and protostuff was only an intermediate step during the move to open-source).

As a side note, I started exploring using Protocol Buffers on the browser side a while ago: & with some almost-working code at that you might want to resurrect.

Read More:   How create static functions/objects in javascript/nodejs (ES6)

Finally, there’s work underway to make GWT RequestFactory proxies compatible with the server-side Java classes generated by protoc (and you could use a protoc extension or a similar approach to Wave’s PST to generate your RequestFactory proxies). It should already be possible, provided you use builders all the way on the server-side (which is not quite how the Protocol Buffers Java API was designed).

Historically javascript made working with binary a pain, which probably in part explains a relative lack of tooling – but with javascript typed arrays it could well be a lot easier now. I kinda agree that if you have to get the same volume of data (via some format), using less bandwidth is a plus – but before embarking on anything you’d need to check that bandwidth / processing was an actual bottleneck (and if bandwidth: have you tried gzip/deflate first).

I’m a fan of protobuf – and I’d happily see stronger browser-side tooling for it, but json is so ubiquitous that you’d need a compelling reason to challenge the status-quo. Also; think “jsonp”.

I have been looking for protobuf for javascript. There is a project here:

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts