protobuf.js version: 6.3.1
Going by the API doc, the only load functions available are Root.load and Root.loadSync, who take filename, options and callback as arguments, with options being a ParseOptions object (permitting for example to specify you don't want camelCase conversion). Going by the example and these docs, I expected to be able to do the following:
var Protobuf = require('protobufjs'),
fs = require("fs");
var folder = fs.readdirSync(__dirname + '/proto'); // folder containing proto files
var schema = Protobuf.loadSync(folder.map(filename => __dirname + '/proto/' + filename), {keepCase: true}); // Produces error
However, when passing an options object, a stacktrace is generated implying that the options object is taken as a Root object on which load is invoked...
Stack trace:
/home/ubuntu/workspace/node_modules/protobufjs/src/index.js:64
return root.loadSync(filename);
^
TypeError: root.loadSync is not a function
at Object.loadSync (/home/ubuntu/workspace/node_modules/protobufjs/src/index.js:64:17)
at Object.<anonymous> (/home/ubuntu/workspace/poc_proto.js:6:23)
at Module._compile (module.js:571:32)
When going through the source, I saw that index.js exports itself undocumented load and loadSync functions, who take a different set of parameters, namely filename, root and callback. These functions check if a root parameter is present and if so invoke load/loadSync on this object, with the given filename and callback as arguments. If no root argument is given, a new Root object is generated and load/loadSync are called on this new object. This leads to the terribly confusing situation where, if you don't want to specify options, you can just follow the example using the exported functions, however, when you want to specify options, you need to first create a Root object yourself and use this object instead (thus effectively re-implementing the exported load/loadSync functions, but this time taking into account the options.
Is this intended behavior of the library? If so, it might be necessary to perhaps modify the docs to make this distinction clear..
protobuf.js version: 6.3.1
Going by the API doc, the only load functions available are
Root.loadandRoot.loadSync, who take filename, options and callback as arguments, with options being aParseOptionsobject (permitting for example to specify you don't want camelCase conversion). Going by the example and these docs, I expected to be able to do the following:However, when passing an options object, a stacktrace is generated implying that the options object is taken as a
Rootobject on which load is invoked...Stack trace:
When going through the source, I saw that
index.jsexports itself undocumentedloadandloadSyncfunctions, who take a different set of parameters, namelyfilename,rootandcallback. These functions check if a root parameter is present and if so invokeload/loadSyncon this object, with the givenfilenameandcallbackas arguments. If no root argument is given, a newRootobject is generated andload/loadSyncare called on this new object. This leads to the terribly confusing situation where, if you don't want to specify options, you can just follow the example using the exported functions, however, when you want to specify options, you need to first create aRootobject yourself and use this object instead (thus effectively re-implementing the exportedload/loadSyncfunctions, but this time taking into account the options.Is this intended behavior of the library? If so, it might be necessary to perhaps modify the docs to make this distinction clear..