JavaScript still supported?

42 views
Skip to first unread message

Ottmar Zittlau

unread,
Nov 29, 2020, 8:27:53 AM11/29/20
to Protocol Buffers

I'm trying to parse a protobuf-packet in the browser and while trying to get this working encountered several questions:

1. Is it possible to use protobuf without node and the closure library?

2. When I use the closure-builder to build a javascript-file that I can run in the browser I encounter the error "depstree.NamespaceNotFoundError: Namespace "jspb.BinaryReader" never provided."
When I grep for this thing, I see two things

    a. The npm-installed "google-protobuf"-module contains multiple usages but no file that contains "goog.provide('jspb.BinaryReader')"

    b. The manually downloaded protobuf-repository contains the file "js/binary/reader.js" that apparently contains the definition.

2. The fact that the protobuf-repository version contains the "jsbp.BinaryReader" made me play around with this option.
After playing around for a while, I figured out, that it is necessary to run "npm install" before "gulp dist" as pointed out in the documentation (https://developers.google.com/protocol-buffers/docs/reference/javascript-generated). This generates the "google-protobuf.js" file.

Is this the correct way? Does this answer my first question with "no" - as this step requires node?

3. I now tried to run the "closure-builder" again (I use the closure library version that was installed in the previous step):
./protobuf/js/node_modules/google-closure-library/closure/bin/build/closurebuilder.py \
--root="protobuf/js" \
--root="testJS/" \
--namespace="proto.test"
The folder "testJS" contains the javascript-files produced by protoc.

This produces the error:

depstree.MultipleProvideError: Namespace "protobuf.runtime.KernelTest" provided more than once in sources:
PathSource protobuf/js/experimental/runtime/kernel/kernel_repeated_test.js
PathSource protobuf/js/experimental/runtime/kernel/kernel_test.js

My next idea was to include only the subfolders of "protobuf/js" that I need - however, this doesn't work, as I need to include "protobuf/js/message.js" because this file contains "goog.provide('jspb.Message')" - the definition of "jsbp.Message".

How can I handle this? Do I need to include all files individually with the "-i" option? I have noticed, that there is an exclude option on the current master of protobuf (which seems to break the "closure-builder" on the current master branch - but apparently there is already a fix underway) - do I need to use this option?

4. Final question - does all this stuff make sense? Is anybody using a similar approach or is there a different, simpler way to get protobuf working in a browser?

Thanks
ou
Reply all
Reply to author
Forward
0 new messages