diff options
author | 2017-03-17 13:45:15 -0700 | |
---|---|---|
committer | 2017-03-17 13:45:15 -0700 | |
commit | b1a02311b37c35b8813386d2d7fbb02e1e61d616 (patch) | |
tree | ee983e83b3f433e0cdc30494825bb9b9393c9498 /src/node/index.js | |
parent | b5b5f020a38c40e4753ead360151810479b8c664 (diff) |
Autodetect ProtoBuf.js version in grpc.loadObject
Diffstat (limited to 'src/node/index.js')
-rw-r--r-- | src/node/index.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/node/index.js b/src/node/index.js index 43a4a54dd8..e41664ebf3 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -58,12 +58,17 @@ var protobuf_js_6_common = require('./src/protobuf_js_6_common'); grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii')); exports.loadObject = function loadObject(value, options) { - options = _.defaults(options, {'protobufjs_version': 5}); - switch (options.protobufjs_version) { - case 5: return protobuf_js_5_common.loadObject(value, options); - case 6: return protobuf_js_6_common.loadObject(value, options); - default: throw new Error('Unrecognized protobufjs_version:', - options.protobufjs_version); + options = _.defaults(options, common.defaultGrpcOptions); + if (value instanceof ProtoBuf.ReflectionObject) { + return protobuf_js_6_common.loadObject(value, options); + } else { + /* If value is not a ProtoBuf.js 6 reflection object, we assume that it is + a ProtoBuf.js 5 reflection object, for backwards compatibility */ + var deprecation_message = 'Calling grpc.loadObject with an object ' + + 'generated by ProtoBuf.js 5 is deprecated. Please upgrade to ' + + 'ProtoBuf.js 6.'; + common.log(grpc.logVerbosity.INFO, deprecation_message); + return protobuf_js_5_common.loadObject(value, options); } }; @@ -108,7 +113,6 @@ exports.load = function load(filename, format, options) { still the possibility of adding other formats that would be loaded differently */ options = _.defaults(options, common.defaultGrpcOptions); - options.protobufjs_version = 6; var root = new ProtoBuf.Root(); var parse_options = {keepCase: !options.convertFieldsToCamelCase}; return loadObject(root.loadSync(applyProtoRoot(filename, root), |