aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/index.js
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanley.cheung@gmail.com>2017-05-18 07:59:24 -0700
committerGravatar GitHub <noreply@github.com>2017-05-18 07:59:24 -0700
commitff0e4296726f1d3727a1188bd6d2ce9480e857d6 (patch)
tree081efa07000a954efcc2fa4df070b5340bf5b300 /src/node/index.js
parent8c9c1c1a8d0d484fcf96799f0caf44c84729376a (diff)
parent646677216d5195768453c65ca291250dd5fb5161 (diff)
Merge pull request #11198 from stanley-cheung/upmerge-v1_3_2-to-master
Upmerge v1.3.x branch to master
Diffstat (limited to 'src/node/index.js')
-rw-r--r--src/node/index.js55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/node/index.js b/src/node/index.js
index 0da3440eb7..2da77c3eae 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -70,8 +70,6 @@ grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii'));
* Buffers. Defaults to false
* - longsAsStrings: deserialize long values as strings instead of objects.
* Defaults to true
- * - enumsAsStrings: deserialize enum values as strings instead of numbers.
- * Defaults to true
* - deprecatedArgumentOrder: Use the beta method argument order for client
* methods, with optional arguments after the callback. Defaults to false.
* This option is only a temporary stopgap measure to smooth an API breakage.
@@ -105,10 +103,6 @@ exports.loadObject = function loadObject(value, options) {
switch (protobufjsVersion) {
case 6: return protobuf_js_6_common.loadObject(value, options);
case 5:
- 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);
default:
throw new Error('Unrecognized protobufjsVersion', protobufjsVersion);
@@ -117,19 +111,6 @@ exports.loadObject = function loadObject(value, options) {
var loadObject = exports.loadObject;
-function applyProtoRoot(filename, root) {
- if (_.isString(filename)) {
- return filename;
- }
- filename.root = path.resolve(filename.root) + '/';
- root.resolvePath = function(originPath, importPath, alreadyNormalized) {
- return ProtoBuf.util.path.resolve(filename.root,
- importPath,
- alreadyNormalized);
- };
- return filename.file;
-}
-
/**
* Load a gRPC object from a .proto file. The options object can provide the
* following options:
@@ -139,8 +120,6 @@ function applyProtoRoot(filename, root) {
* Buffers. Defaults to false
* - longsAsStrings: deserialize long values as strings instead of objects.
* Defaults to true
- * - enumsAsStrings: deserialize enum values as strings instead of numbers.
- * Defaults to true
* - deprecatedArgumentOrder: Use the beta method argument order for client
* methods, with optional arguments after the callback. Defaults to false.
* This option is only a temporary stopgap measure to smooth an API breakage.
@@ -152,17 +131,31 @@ function applyProtoRoot(filename, root) {
* @return {Object<string, *>} The resulting gRPC object
*/
exports.load = function load(filename, format, options) {
- /* Note: format is currently unused, because the API for loading a proto
- file or a JSON file is identical in Protobuf.js 6. In the future, there is
- 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),
- parse_options),
- options);
+ options.protobufjsVersion = 5;
+ if (!format) {
+ format = 'proto';
+ }
+ var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
+ if(options && options.hasOwnProperty('convertFieldsToCamelCase')) {
+ ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
+ }
+ var builder;
+ try {
+ switch(format) {
+ case 'proto':
+ builder = ProtoBuf.loadProtoFile(filename);
+ break;
+ case 'json':
+ builder = ProtoBuf.loadJsonFile(filename);
+ break;
+ default:
+ throw new Error('Unrecognized format "' + format + '"');
+ }
+ } finally {
+ ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
+ }
+ return loadObject(builder.ns, options);
};
var log_template = _.template(