aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/index.js')
-rw-r--r--src/node/index.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/node/index.js b/src/node/index.js
index 0b768edc6b..875756328d 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -67,10 +67,25 @@ function loadObject(value) {
/**
* Load a gRPC object from a .proto file.
* @param {string} filename The file to load
+ * @param {string=} format The file format to expect. Must be either 'proto' or
+ * 'json'. Defaults to 'proto'
* @return {Object<string, *>} The resulting gRPC object
*/
-function load(filename) {
- var builder = ProtoBuf.loadProtoFile(filename);
+function load(filename, format) {
+ if (!format) {
+ format = 'proto';
+ }
+ var builder;
+ switch(format) {
+ case 'proto':
+ builder = ProtoBuf.loadProtoFile(filename);
+ break;
+ case 'json':
+ builder = ProtoBuf.loadJsonFile(filename);
+ break;
+ default:
+ throw new Error('Unrecognized format "' + format + '"');
+ }
return loadObject(builder.ns);
}