From 273e3cfb79f639623bdfc25a2186bedc71e03506 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 5 Nov 2020 11:24:27 -0800 Subject: [PATCH] Update Node examples to use @grpc/grpc-js --- .../node/dynamic_codegen/greeter_client.js | 2 +- .../node/dynamic_codegen/greeter_server.js | 7 +- .../route_guide/route_guide_client.js | 2 +- .../route_guide/route_guide_server.js | 19 +- examples/node/package-lock.json | 570 +++++++++++++++++ examples/node/package.json | 4 +- examples/node/static_codegen/README.md | 4 +- .../node/static_codegen/greeter_client.js | 2 +- .../node/static_codegen/greeter_server.js | 7 +- .../node/static_codegen/helloworld_grpc_pb.js | 28 +- examples/node/static_codegen/helloworld_pb.js | 163 +++-- .../route_guide/route_guide_client.js | 2 +- .../route_guide/route_guide_grpc_pb.js | 114 ++-- .../route_guide/route_guide_pb.js | 594 ++++++++++-------- .../route_guide/route_guide_server.js | 35 +- 15 files changed, 1075 insertions(+), 478 deletions(-) create mode 100644 examples/node/package-lock.json diff --git a/examples/node/dynamic_codegen/greeter_client.js b/examples/node/dynamic_codegen/greeter_client.js index c289f501ee1..849376b6a9e 100644 --- a/examples/node/dynamic_codegen/greeter_client.js +++ b/examples/node/dynamic_codegen/greeter_client.js @@ -18,7 +18,7 @@ var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var protoLoader = require('@grpc/proto-loader'); var packageDefinition = protoLoader.loadSync( PROTO_PATH, diff --git a/examples/node/dynamic_codegen/greeter_server.js b/examples/node/dynamic_codegen/greeter_server.js index 023257ecf08..c606cd8cc36 100644 --- a/examples/node/dynamic_codegen/greeter_server.js +++ b/examples/node/dynamic_codegen/greeter_server.js @@ -18,7 +18,7 @@ var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var protoLoader = require('@grpc/proto-loader'); var packageDefinition = protoLoader.loadSync( PROTO_PATH, @@ -44,8 +44,9 @@ function sayHello(call, callback) { function main() { var server = new grpc.Server(); server.addService(hello_proto.Greeter.service, {sayHello: sayHello}); - server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); - server.start(); + server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { + server.start(); + }); } main(); diff --git a/examples/node/dynamic_codegen/route_guide/route_guide_client.js b/examples/node/dynamic_codegen/route_guide/route_guide_client.js index 34a44bd6a9e..3af8858ae85 100644 --- a/examples/node/dynamic_codegen/route_guide/route_guide_client.js +++ b/examples/node/dynamic_codegen/route_guide/route_guide_client.js @@ -23,7 +23,7 @@ var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var protoLoader = require('@grpc/proto-loader'); var packageDefinition = protoLoader.loadSync( PROTO_PATH, diff --git a/examples/node/dynamic_codegen/route_guide/route_guide_server.js b/examples/node/dynamic_codegen/route_guide/route_guide_server.js index 106491c1a10..b464538e36c 100644 --- a/examples/node/dynamic_codegen/route_guide/route_guide_server.js +++ b/examples/node/dynamic_codegen/route_guide/route_guide_server.js @@ -22,7 +22,7 @@ var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var protoLoader = require('@grpc/proto-loader'); var packageDefinition = protoLoader.loadSync( PROTO_PATH, @@ -230,14 +230,15 @@ function getServer() { if (require.main === module) { // If this is run as a script, start a server on an unused port var routeServer = getServer(); - routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); - var argv = parseArgs(process.argv, { - string: 'db_path' - }); - fs.readFile(path.resolve(argv.db_path), function(err, data) { - if (err) throw err; - feature_list = JSON.parse(data); - routeServer.start(); + routeServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { + var argv = parseArgs(process.argv, { + string: 'db_path' + }); + fs.readFile(path.resolve(argv.db_path), function(err, data) { + if (err) throw err; + feature_list = JSON.parse(data); + routeServer.start(); + }); }); } diff --git a/examples/node/package-lock.json b/examples/node/package-lock.json new file mode 100644 index 00000000000..24dcc6731c9 --- /dev/null +++ b/examples/node/package-lock.json @@ -0,0 +1,570 @@ +{ + "name": "grpc-examples", + "version": "0.1.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@grpc/grpc-js": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.1.8.tgz", + "integrity": "sha512-64hg5rmEm6F/NvlWERhHmmgxbWU8nD2TMWE+9TvG7/WcOrFT3fzg/Uu631pXRFwmJ4aWO/kp9vVSlr8FUjBDLA==", + "requires": { + "@grpc/proto-loader": "^0.6.0-pre14", + "@types/node": "^12.12.47", + "google-auth-library": "^6.0.0", + "semver": "^6.2.0" + }, + "dependencies": { + "@grpc/proto-loader": { + "version": "0.6.0-pre9", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.6.0-pre9.tgz", + "integrity": "sha512-oM+LjpEjNzW5pNJjt4/hq1HYayNeQT+eGrOPABJnYHv7TyNPDNzkQ76rDYZF86X5swJOa4EujEMzQ9iiTdPgww==", + "requires": { + "@types/long": "^4.0.1", + "lodash.camelcase": "^4.3.0", + "long": "^4.0.0", + "protobufjs": "^6.9.0", + "yargs": "^15.3.1" + } + }, + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + } + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + } + } + } + }, + "@grpc/proto-loader": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.5.5.tgz", + "integrity": "sha512-WwN9jVNdHRQoOBo9FDH7qU+mgfjPc8GygPYms3M+y3fbQLfnCe/Kv/E01t7JRgnrsOHH8euvSbed3mIalXhwqQ==", + "requires": { + "lodash.camelcase": "^4.3.0", + "protobufjs": "^6.8.6" + } + }, + "@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha1-m4sMxmPWaafY9vXQiToU00jzD78=" + }, + "@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + }, + "@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + }, + "@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha1-NVy8mLr61ZePntCV85diHx0Ga3A=" + }, + "@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=", + "requires": { + "@protobufjs/aspromise": "^1.1.1", + "@protobufjs/inquire": "^1.1.0" + } + }, + "@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=" + }, + "@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=" + }, + "@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=" + }, + "@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=" + }, + "@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=" + }, + "@types/long": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz", + "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" + }, + "@types/node": { + "version": "12.19.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.3.tgz", + "integrity": "sha512-8Jduo8wvvwDzEVJCOvS/G6sgilOLvvhn1eMmK3TW8/T217O7u1jdrK6ImKLv80tVryaPSVeKu6sjDEiFjd4/eg==" + }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "requires": { + "event-target-shim": "^5.0.0" + } + }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "requires": { + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "requires": { + "ms": "2.1.2" + } + } + } + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "arrify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", + "integrity": "sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==" + }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + }, + "base64-js": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" + }, + "bignumber.js": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz", + "integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==" + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "fast-text-encoding": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz", + "integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig==" + }, + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "gaxios": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.0.1.tgz", + "integrity": "sha512-jOin8xRZ/UytQeBpSXFqIzqU7Fi5TqgPNLlUsSB8kjJ76+FiGBfImF8KJu++c6J4jOldfJUtt0YmkRj2ZpSHTQ==", + "requires": { + "abort-controller": "^3.0.0", + "extend": "^3.0.2", + "https-proxy-agent": "^5.0.0", + "is-stream": "^2.0.0", + "node-fetch": "^2.3.0" + } + }, + "gcp-metadata": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-4.2.1.tgz", + "integrity": "sha512-tSk+REe5iq/N+K+SK1XjZJUrFPuDqGZVzCy2vocIHIGmPlTGsa8owXMJwGkrXr73NO0AzhPW4MF2DEHz7P2AVw==", + "requires": { + "gaxios": "^4.0.0", + "json-bigint": "^1.0.0" + } + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "google-auth-library": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-6.1.3.tgz", + "integrity": "sha512-m9mwvY3GWbr7ZYEbl61isWmk+fvTmOt0YNUfPOUY2VH8K5pZlAIWJjxEi0PqR3OjMretyiQLI6GURMrPSwHQ2g==", + "requires": { + "arrify": "^2.0.0", + "base64-js": "^1.3.0", + "ecdsa-sig-formatter": "^1.0.11", + "fast-text-encoding": "^1.0.0", + "gaxios": "^4.0.0", + "gcp-metadata": "^4.2.0", + "gtoken": "^5.0.4", + "jws": "^4.0.0", + "lru-cache": "^6.0.0" + } + }, + "google-p12-pem": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.0.3.tgz", + "integrity": "sha512-wS0ek4ZtFx/ACKYF3JhyGe5kzH7pgiQ7J5otlumqR9psmWMYc+U9cErKlCYVYHoUaidXHdZ2xbo34kB+S+24hA==", + "requires": { + "node-forge": "^0.10.0" + } + }, + "google-protobuf": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.13.0.tgz", + "integrity": "sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw==" + }, + "gtoken": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-5.0.5.tgz", + "integrity": "sha512-wvjkecutFh8kVfbcdBdUWqDRrXb+WrgD79DBDEYf1Om8S1FluhylhtFjrL7Tx69vNhh259qA3Q1P4sPtb+kUYw==", + "requires": { + "gaxios": "^4.0.0", + "google-p12-pem": "^3.0.3", + "jws": "^4.0.0", + "mime": "^2.2.0" + } + }, + "https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "requires": { + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "requires": { + "ms": "2.1.2" + } + } + } + }, + "is-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==" + }, + "json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "requires": { + "bignumber.js": "^9.0.0" + } + }, + "jwa": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.0.tgz", + "integrity": "sha512-jrZ2Qx916EA+fq9cEAeCROWPTfCwi1IVHqT2tapuqLEVVDKFDENFw1oL+MwrTvH6msKxsd1YTDVw6uKEcsrLEA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz", + "integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==", + "requires": { + "jwa": "^2.0.0", + "safe-buffer": "^5.0.1" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "requires": { + "p-locate": "^4.1.0" + } + }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" + }, + "lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" + }, + "long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + }, + "dependencies": { + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, + "mime": { + "version": "2.4.6", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz", + "integrity": "sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==" + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, + "node-forge": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz", + "integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==" + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "requires": { + "p-limit": "^2.2.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + }, + "protobufjs": { + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.10.1.tgz", + "integrity": "sha512-pb8kTchL+1Ceg4lFd5XUpK8PdWacbvV5SK2ULH2ebrYtl4GjJmS24m6CKME67jzV53tbJxHlnNOSqQHbTsR9JQ==", + "requires": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.4", + "@protobufjs/eventemitter": "^1.1.0", + "@protobufjs/fetch": "^1.1.0", + "@protobufjs/float": "^1.0.2", + "@protobufjs/inquire": "^1.1.0", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.0", + "@types/long": "^4.0.1", + "@types/node": "^13.7.0", + "long": "^4.0.0" + }, + "dependencies": { + "@types/node": { + "version": "13.13.30", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.30.tgz", + "integrity": "sha512-HmqFpNzp3TSELxU/bUuRK+xzarVOAsR00hzcvM0TXrMlt/+wcSLa5q6YhTb6/cA6wqDCZLDcfd8fSL95x5h7AA==" + } + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "dependencies": { + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + } + } + } + } +} diff --git a/examples/node/package.json b/examples/node/package.json index 3af6a113fd5..73153dee4d6 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -2,10 +2,10 @@ "name": "grpc-examples", "version": "0.1.0", "dependencies": { - "@grpc/proto-loader": "^0.1.0", + "@grpc/proto-loader": "^0.5.0", "async": "^1.5.2", "google-protobuf": "^3.0.0", - "grpc": "^1.11.0", + "@grpc/grpc-js": "^1.1.0", "lodash": "^4.6.1", "minimist": "^1.2.0" } diff --git a/examples/node/static_codegen/README.md b/examples/node/static_codegen/README.md index 0441b27f25a..bc087ec4fa7 100644 --- a/examples/node/static_codegen/README.md +++ b/examples/node/static_codegen/README.md @@ -3,6 +3,6 @@ This is the static code generation variant of the Node examples. Code in these e ```sh cd ../../protos npm install -g grpc-tools -grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/ --grpc_out=../node/static_codegen --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` helloworld.proto -grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/route_guide/ --grpc_out=../node/static_codegen/route_guide/ --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` route_guide.proto +grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/ --grpc_out=grpc_js:../node/static_codegen helloworld.proto +grpc_tools_node_protoc --js_out=import_style=commonjs,binary:../node/static_codegen/route_guide/ --grpc_out=grpc_js:../node/static_codegen/route_guide/ route_guide.proto ``` diff --git a/examples/node/static_codegen/greeter_client.js b/examples/node/static_codegen/greeter_client.js index 3f85f9b9dbb..4fdc12b9f29 100644 --- a/examples/node/static_codegen/greeter_client.js +++ b/examples/node/static_codegen/greeter_client.js @@ -19,7 +19,7 @@ var messages = require('./helloworld_pb'); var services = require('./helloworld_grpc_pb'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); function main() { var client = new services.GreeterClient('localhost:50051', diff --git a/examples/node/static_codegen/greeter_server.js b/examples/node/static_codegen/greeter_server.js index 930f50604b3..7a3e87d8050 100644 --- a/examples/node/static_codegen/greeter_server.js +++ b/examples/node/static_codegen/greeter_server.js @@ -19,7 +19,7 @@ var messages = require('./helloworld_pb'); var services = require('./helloworld_grpc_pb'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); /** * Implements the SayHello RPC method. @@ -37,8 +37,9 @@ function sayHello(call, callback) { function main() { var server = new grpc.Server(); server.addService(services.GreeterService, {sayHello: sayHello}); - server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); - server.start(); + server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { + server.start(); + }); } main(); diff --git a/examples/node/static_codegen/helloworld_grpc_pb.js b/examples/node/static_codegen/helloworld_grpc_pb.js index 2605e2dab8d..85dc0f0b7c4 100644 --- a/examples/node/static_codegen/helloworld_grpc_pb.js +++ b/examples/node/static_codegen/helloworld_grpc_pb.js @@ -16,28 +16,28 @@ // limitations under the License. // 'use strict'; -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var helloworld_pb = require('./helloworld_pb.js'); -function serialize_HelloReply(arg) { +function serialize_helloworld_HelloReply(arg) { if (!(arg instanceof helloworld_pb.HelloReply)) { - throw new Error('Expected argument of type HelloReply'); + throw new Error('Expected argument of type helloworld.HelloReply'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_HelloReply(buffer_arg) { +function deserialize_helloworld_HelloReply(buffer_arg) { return helloworld_pb.HelloReply.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_HelloRequest(arg) { +function serialize_helloworld_HelloRequest(arg) { if (!(arg instanceof helloworld_pb.HelloRequest)) { - throw new Error('Expected argument of type HelloRequest'); + throw new Error('Expected argument of type helloworld.HelloRequest'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_HelloRequest(buffer_arg) { +function deserialize_helloworld_HelloRequest(buffer_arg) { return helloworld_pb.HelloRequest.deserializeBinary(new Uint8Array(buffer_arg)); } @@ -45,16 +45,16 @@ function deserialize_HelloRequest(buffer_arg) { // The greeting service definition. var GreeterService = exports.GreeterService = { // Sends a greeting - sayHello: { +sayHello: { path: '/helloworld.Greeter/SayHello', requestStream: false, responseStream: false, requestType: helloworld_pb.HelloRequest, responseType: helloworld_pb.HelloReply, - requestSerialize: serialize_HelloRequest, - requestDeserialize: deserialize_HelloRequest, - responseSerialize: serialize_HelloReply, - responseDeserialize: deserialize_HelloReply, + requestSerialize: serialize_helloworld_HelloRequest, + requestDeserialize: deserialize_helloworld_HelloRequest, + responseSerialize: serialize_helloworld_HelloReply, + responseDeserialize: deserialize_helloworld_HelloReply, }, }; diff --git a/examples/node/static_codegen/helloworld_pb.js b/examples/node/static_codegen/helloworld_pb.js index d1e50c90ea8..e6768028139 100644 --- a/examples/node/static_codegen/helloworld_pb.js +++ b/examples/node/static_codegen/helloworld_pb.js @@ -1,6 +1,9 @@ +// source: helloworld.proto /** * @fileoverview * @enhanceable + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. * @public */ // GENERATED CODE -- DO NOT EDIT! @@ -11,7 +14,6 @@ var global = Function('return this')(); goog.exportSymbol('proto.helloworld.HelloReply', null, global); goog.exportSymbol('proto.helloworld.HelloRequest', null, global); - /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -27,19 +29,47 @@ proto.helloworld.HelloRequest = function(opt_data) { }; goog.inherits(proto.helloworld.HelloRequest, jspb.Message); if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ proto.helloworld.HelloRequest.displayName = 'proto.helloworld.HelloRequest'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.helloworld.HelloReply = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.helloworld.HelloReply, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.helloworld.HelloReply.displayName = 'proto.helloworld.HelloReply'; +} + if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.helloworld.HelloRequest.prototype.toObject = function(opt_includeInstance) { @@ -49,15 +79,16 @@ proto.helloworld.HelloRequest.prototype.toObject = function(opt_includeInstance) /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.helloworld.HelloRequest} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.helloworld.HelloRequest.toObject = function(includeInstance, msg) { var f, obj = { - name: msg.getName() + name: jspb.Message.getFieldWithDefault(msg, 1, "") }; if (includeInstance) { @@ -107,36 +138,27 @@ proto.helloworld.HelloRequest.deserializeBinaryFromReader = function(msg, reader }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.helloworld.HelloRequest} message - * @param {!jspb.BinaryWriter} writer - */ -proto.helloworld.HelloRequest.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.helloworld.HelloRequest.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.helloworld.HelloRequest.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.helloworld.HelloRequest} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.helloworld.HelloRequest.prototype.serializeBinaryToWriter = function (writer) { +proto.helloworld.HelloRequest.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getName(); + f = message.getName(); if (f.length > 0) { writer.writeString( 1, @@ -146,59 +168,38 @@ proto.helloworld.HelloRequest.prototype.serializeBinaryToWriter = function (writ }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.helloworld.HelloRequest} The clone. - */ -proto.helloworld.HelloRequest.prototype.cloneMessage = function() { - return /** @type {!proto.helloworld.HelloRequest} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional string name = 1; * @return {string} */ proto.helloworld.HelloRequest.prototype.getName = function() { - return /** @type {string} */ (jspb.Message.getFieldProto3(this, 1, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; -/** @param {string} value */ +/** + * @param {string} value + * @return {!proto.helloworld.HelloRequest} returns this + */ proto.helloworld.HelloRequest.prototype.setName = function(value) { - jspb.Message.setField(this, 1, value); + return jspb.Message.setProto3StringField(this, 1, value); }; -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.helloworld.HelloReply = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.helloworld.HelloReply, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.helloworld.HelloReply.displayName = 'proto.helloworld.HelloReply'; -} if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.helloworld.HelloReply.prototype.toObject = function(opt_includeInstance) { @@ -208,15 +209,16 @@ proto.helloworld.HelloReply.prototype.toObject = function(opt_includeInstance) { /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.helloworld.HelloReply} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.helloworld.HelloReply.toObject = function(includeInstance, msg) { var f, obj = { - message: msg.getMessage() + message: jspb.Message.getFieldWithDefault(msg, 1, "") }; if (includeInstance) { @@ -266,36 +268,27 @@ proto.helloworld.HelloReply.deserializeBinaryFromReader = function(msg, reader) }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.helloworld.HelloReply} message - * @param {!jspb.BinaryWriter} writer - */ -proto.helloworld.HelloReply.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.helloworld.HelloReply.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.helloworld.HelloReply.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.helloworld.HelloReply} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.helloworld.HelloReply.prototype.serializeBinaryToWriter = function (writer) { +proto.helloworld.HelloReply.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getMessage(); + f = message.getMessage(); if (f.length > 0) { writer.writeString( 1, @@ -305,27 +298,21 @@ proto.helloworld.HelloReply.prototype.serializeBinaryToWriter = function (writer }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.helloworld.HelloReply} The clone. - */ -proto.helloworld.HelloReply.prototype.cloneMessage = function() { - return /** @type {!proto.helloworld.HelloReply} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional string message = 1; * @return {string} */ proto.helloworld.HelloReply.prototype.getMessage = function() { - return /** @type {string} */ (jspb.Message.getFieldProto3(this, 1, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; -/** @param {string} value */ +/** + * @param {string} value + * @return {!proto.helloworld.HelloReply} returns this + */ proto.helloworld.HelloReply.prototype.setMessage = function(value) { - jspb.Message.setField(this, 1, value); + return jspb.Message.setProto3StringField(this, 1, value); }; diff --git a/examples/node/static_codegen/route_guide/route_guide_client.js b/examples/node/static_codegen/route_guide/route_guide_client.js index b65e3f830a3..0ab40a8a550 100644 --- a/examples/node/static_codegen/route_guide/route_guide_client.js +++ b/examples/node/static_codegen/route_guide/route_guide_client.js @@ -24,7 +24,7 @@ var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var client = new services.RouteGuideClient('localhost:50051', grpc.credentials.createInsecure()); diff --git a/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js b/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js index 7765bf916d1..83c839dc85c 100644 --- a/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js +++ b/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js @@ -16,61 +16,61 @@ // limitations under the License. // 'use strict'; -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var route_guide_pb = require('./route_guide_pb.js'); -function serialize_Feature(arg) { +function serialize_routeguide_Feature(arg) { if (!(arg instanceof route_guide_pb.Feature)) { - throw new Error('Expected argument of type Feature'); + throw new Error('Expected argument of type routeguide.Feature'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_Feature(buffer_arg) { +function deserialize_routeguide_Feature(buffer_arg) { return route_guide_pb.Feature.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_Point(arg) { +function serialize_routeguide_Point(arg) { if (!(arg instanceof route_guide_pb.Point)) { - throw new Error('Expected argument of type Point'); + throw new Error('Expected argument of type routeguide.Point'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_Point(buffer_arg) { +function deserialize_routeguide_Point(buffer_arg) { return route_guide_pb.Point.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_Rectangle(arg) { +function serialize_routeguide_Rectangle(arg) { if (!(arg instanceof route_guide_pb.Rectangle)) { - throw new Error('Expected argument of type Rectangle'); + throw new Error('Expected argument of type routeguide.Rectangle'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_Rectangle(buffer_arg) { +function deserialize_routeguide_Rectangle(buffer_arg) { return route_guide_pb.Rectangle.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_RouteNote(arg) { +function serialize_routeguide_RouteNote(arg) { if (!(arg instanceof route_guide_pb.RouteNote)) { - throw new Error('Expected argument of type RouteNote'); + throw new Error('Expected argument of type routeguide.RouteNote'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_RouteNote(buffer_arg) { +function deserialize_routeguide_RouteNote(buffer_arg) { return route_guide_pb.RouteNote.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_RouteSummary(arg) { +function serialize_routeguide_RouteSummary(arg) { if (!(arg instanceof route_guide_pb.RouteSummary)) { - throw new Error('Expected argument of type RouteSummary'); + throw new Error('Expected argument of type routeguide.RouteSummary'); } - return new Buffer(arg.serializeBinary()); + return Buffer.from(arg.serializeBinary()); } -function deserialize_RouteSummary(buffer_arg) { +function deserialize_routeguide_RouteSummary(buffer_arg) { return route_guide_pb.RouteSummary.deserializeBinary(new Uint8Array(buffer_arg)); } @@ -78,68 +78,68 @@ function deserialize_RouteSummary(buffer_arg) { // Interface exported by the server. var RouteGuideService = exports.RouteGuideService = { // A simple RPC. - // - // Obtains the feature at a given position. - // - // A feature with an empty name is returned if there's no feature at the given - // position. - getFeature: { +// +// Obtains the feature at a given position. +// +// A feature with an empty name is returned if there's no feature at the given +// position. +getFeature: { path: '/routeguide.RouteGuide/GetFeature', requestStream: false, responseStream: false, requestType: route_guide_pb.Point, responseType: route_guide_pb.Feature, - requestSerialize: serialize_Point, - requestDeserialize: deserialize_Point, - responseSerialize: serialize_Feature, - responseDeserialize: deserialize_Feature, + requestSerialize: serialize_routeguide_Point, + requestDeserialize: deserialize_routeguide_Point, + responseSerialize: serialize_routeguide_Feature, + responseDeserialize: deserialize_routeguide_Feature, }, // A server-to-client streaming RPC. - // - // Obtains the Features available within the given Rectangle. Results are - // streamed rather than returned at once (e.g. in a response message with a - // repeated field), as the rectangle may cover a large area and contain a - // huge number of features. - listFeatures: { +// +// Obtains the Features available within the given Rectangle. Results are +// streamed rather than returned at once (e.g. in a response message with a +// repeated field), as the rectangle may cover a large area and contain a +// huge number of features. +listFeatures: { path: '/routeguide.RouteGuide/ListFeatures', requestStream: false, responseStream: true, requestType: route_guide_pb.Rectangle, responseType: route_guide_pb.Feature, - requestSerialize: serialize_Rectangle, - requestDeserialize: deserialize_Rectangle, - responseSerialize: serialize_Feature, - responseDeserialize: deserialize_Feature, + requestSerialize: serialize_routeguide_Rectangle, + requestDeserialize: deserialize_routeguide_Rectangle, + responseSerialize: serialize_routeguide_Feature, + responseDeserialize: deserialize_routeguide_Feature, }, // A client-to-server streaming RPC. - // - // Accepts a stream of Points on a route being traversed, returning a - // RouteSummary when traversal is completed. - recordRoute: { +// +// Accepts a stream of Points on a route being traversed, returning a +// RouteSummary when traversal is completed. +recordRoute: { path: '/routeguide.RouteGuide/RecordRoute', requestStream: true, responseStream: false, requestType: route_guide_pb.Point, responseType: route_guide_pb.RouteSummary, - requestSerialize: serialize_Point, - requestDeserialize: deserialize_Point, - responseSerialize: serialize_RouteSummary, - responseDeserialize: deserialize_RouteSummary, + requestSerialize: serialize_routeguide_Point, + requestDeserialize: deserialize_routeguide_Point, + responseSerialize: serialize_routeguide_RouteSummary, + responseDeserialize: deserialize_routeguide_RouteSummary, }, // A Bidirectional streaming RPC. - // - // Accepts a stream of RouteNotes sent while a route is being traversed, - // while receiving other RouteNotes (e.g. from other users). - routeChat: { +// +// Accepts a stream of RouteNotes sent while a route is being traversed, +// while receiving other RouteNotes (e.g. from other users). +routeChat: { path: '/routeguide.RouteGuide/RouteChat', requestStream: true, responseStream: true, requestType: route_guide_pb.RouteNote, responseType: route_guide_pb.RouteNote, - requestSerialize: serialize_RouteNote, - requestDeserialize: deserialize_RouteNote, - responseSerialize: serialize_RouteNote, - responseDeserialize: deserialize_RouteNote, + requestSerialize: serialize_routeguide_RouteNote, + requestDeserialize: deserialize_routeguide_RouteNote, + responseSerialize: serialize_routeguide_RouteNote, + responseDeserialize: deserialize_routeguide_RouteNote, }, }; diff --git a/examples/node/static_codegen/route_guide/route_guide_pb.js b/examples/node/static_codegen/route_guide/route_guide_pb.js index 2e2f9a1da23..a032bec4c4f 100644 --- a/examples/node/static_codegen/route_guide/route_guide_pb.js +++ b/examples/node/static_codegen/route_guide/route_guide_pb.js @@ -1,6 +1,9 @@ +// source: route_guide.proto /** * @fileoverview * @enhanceable + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. * @public */ // GENERATED CODE -- DO NOT EDIT! @@ -14,7 +17,6 @@ goog.exportSymbol('proto.routeguide.Point', null, global); goog.exportSymbol('proto.routeguide.Rectangle', null, global); goog.exportSymbol('proto.routeguide.RouteNote', null, global); goog.exportSymbol('proto.routeguide.RouteSummary', null, global); - /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -30,19 +32,110 @@ proto.routeguide.Point = function(opt_data) { }; goog.inherits(proto.routeguide.Point, jspb.Message); if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ proto.routeguide.Point.displayName = 'proto.routeguide.Point'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.routeguide.Rectangle = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.routeguide.Rectangle, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.routeguide.Rectangle.displayName = 'proto.routeguide.Rectangle'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.routeguide.Feature = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.routeguide.Feature, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.routeguide.Feature.displayName = 'proto.routeguide.Feature'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.routeguide.RouteNote = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.routeguide.RouteNote, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.routeguide.RouteNote.displayName = 'proto.routeguide.RouteNote'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.routeguide.RouteSummary = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.routeguide.RouteSummary, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.routeguide.RouteSummary.displayName = 'proto.routeguide.RouteSummary'; +} + if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.routeguide.Point.prototype.toObject = function(opt_includeInstance) { @@ -52,16 +145,17 @@ proto.routeguide.Point.prototype.toObject = function(opt_includeInstance) { /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.routeguide.Point} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.routeguide.Point.toObject = function(includeInstance, msg) { var f, obj = { - latitude: msg.getLatitude(), - longitude: msg.getLongitude() + latitude: jspb.Message.getFieldWithDefault(msg, 1, 0), + longitude: jspb.Message.getFieldWithDefault(msg, 2, 0) }; if (includeInstance) { @@ -115,43 +209,34 @@ proto.routeguide.Point.deserializeBinaryFromReader = function(msg, reader) { }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.routeguide.Point} message - * @param {!jspb.BinaryWriter} writer - */ -proto.routeguide.Point.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.routeguide.Point.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.routeguide.Point.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.routeguide.Point} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.routeguide.Point.prototype.serializeBinaryToWriter = function (writer) { +proto.routeguide.Point.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getLatitude(); + f = message.getLatitude(); if (f !== 0) { writer.writeInt32( 1, f ); } - f = this.getLongitude(); + f = message.getLongitude(); if (f !== 0) { writer.writeInt32( 2, @@ -161,27 +246,21 @@ proto.routeguide.Point.prototype.serializeBinaryToWriter = function (writer) { }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.routeguide.Point} The clone. - */ -proto.routeguide.Point.prototype.cloneMessage = function() { - return /** @type {!proto.routeguide.Point} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional int32 latitude = 1; * @return {number} */ proto.routeguide.Point.prototype.getLatitude = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.Point} returns this + */ proto.routeguide.Point.prototype.setLatitude = function(value) { - jspb.Message.setField(this, 1, value); + return jspb.Message.setProto3IntField(this, 1, value); }; @@ -190,45 +269,33 @@ proto.routeguide.Point.prototype.setLatitude = function(value) { * @return {number} */ proto.routeguide.Point.prototype.getLongitude = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.Point} returns this + */ proto.routeguide.Point.prototype.setLongitude = function(value) { - jspb.Message.setField(this, 2, value); + return jspb.Message.setProto3IntField(this, 2, value); }; -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.routeguide.Rectangle = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.routeguide.Rectangle, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.routeguide.Rectangle.displayName = 'proto.routeguide.Rectangle'; -} if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.routeguide.Rectangle.prototype.toObject = function(opt_includeInstance) { @@ -238,11 +305,12 @@ proto.routeguide.Rectangle.prototype.toObject = function(opt_includeInstance) { /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.routeguide.Rectangle} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.routeguide.Rectangle.toObject = function(includeInstance, msg) { var f, obj = { @@ -303,36 +371,27 @@ proto.routeguide.Rectangle.deserializeBinaryFromReader = function(msg, reader) { }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.routeguide.Rectangle} message - * @param {!jspb.BinaryWriter} writer - */ -proto.routeguide.Rectangle.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.routeguide.Rectangle.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.routeguide.Rectangle.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.routeguide.Rectangle} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.routeguide.Rectangle.prototype.serializeBinaryToWriter = function (writer) { +proto.routeguide.Rectangle.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getLo(); + f = message.getLo(); if (f != null) { writer.writeMessage( 1, @@ -340,7 +399,7 @@ proto.routeguide.Rectangle.prototype.serializeBinaryToWriter = function (writer) proto.routeguide.Point.serializeBinaryToWriter ); } - f = this.getHi(); + f = message.getHi(); if (f != null) { writer.writeMessage( 2, @@ -351,86 +410,94 @@ proto.routeguide.Rectangle.prototype.serializeBinaryToWriter = function (writer) }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.routeguide.Rectangle} The clone. - */ -proto.routeguide.Rectangle.prototype.cloneMessage = function() { - return /** @type {!proto.routeguide.Rectangle} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional Point lo = 1; - * @return {proto.routeguide.Point} + * @return {?proto.routeguide.Point} */ proto.routeguide.Rectangle.prototype.getLo = function() { - return /** @type{proto.routeguide.Point} */ ( + return /** @type{?proto.routeguide.Point} */ ( jspb.Message.getWrapperField(this, proto.routeguide.Point, 1)); }; -/** @param {proto.routeguide.Point|undefined} value */ +/** + * @param {?proto.routeguide.Point|undefined} value + * @return {!proto.routeguide.Rectangle} returns this +*/ proto.routeguide.Rectangle.prototype.setLo = function(value) { - jspb.Message.setWrapperField(this, 1, value); + return jspb.Message.setWrapperField(this, 1, value); }; +/** + * Clears the message field making it undefined. + * @return {!proto.routeguide.Rectangle} returns this + */ proto.routeguide.Rectangle.prototype.clearLo = function() { - this.setLo(undefined); + return this.setLo(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.routeguide.Rectangle.prototype.hasLo = function() { + return jspb.Message.getField(this, 1) != null; }; /** * optional Point hi = 2; - * @return {proto.routeguide.Point} + * @return {?proto.routeguide.Point} */ proto.routeguide.Rectangle.prototype.getHi = function() { - return /** @type{proto.routeguide.Point} */ ( + return /** @type{?proto.routeguide.Point} */ ( jspb.Message.getWrapperField(this, proto.routeguide.Point, 2)); }; -/** @param {proto.routeguide.Point|undefined} value */ +/** + * @param {?proto.routeguide.Point|undefined} value + * @return {!proto.routeguide.Rectangle} returns this +*/ proto.routeguide.Rectangle.prototype.setHi = function(value) { - jspb.Message.setWrapperField(this, 2, value); + return jspb.Message.setWrapperField(this, 2, value); }; +/** + * Clears the message field making it undefined. + * @return {!proto.routeguide.Rectangle} returns this + */ proto.routeguide.Rectangle.prototype.clearHi = function() { - this.setHi(undefined); + return this.setHi(undefined); }; - /** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor + * Returns whether this field is set. + * @return {boolean} */ -proto.routeguide.Feature = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); +proto.routeguide.Rectangle.prototype.hasHi = function() { + return jspb.Message.getField(this, 2) != null; }; -goog.inherits(proto.routeguide.Feature, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.routeguide.Feature.displayName = 'proto.routeguide.Feature'; -} + + + if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.routeguide.Feature.prototype.toObject = function(opt_includeInstance) { @@ -440,15 +507,16 @@ proto.routeguide.Feature.prototype.toObject = function(opt_includeInstance) { /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.routeguide.Feature} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.routeguide.Feature.toObject = function(includeInstance, msg) { var f, obj = { - name: msg.getName(), + name: jspb.Message.getFieldWithDefault(msg, 1, ""), location: (f = msg.getLocation()) && proto.routeguide.Point.toObject(includeInstance, f) }; @@ -504,43 +572,34 @@ proto.routeguide.Feature.deserializeBinaryFromReader = function(msg, reader) { }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.routeguide.Feature} message - * @param {!jspb.BinaryWriter} writer - */ -proto.routeguide.Feature.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.routeguide.Feature.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.routeguide.Feature.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.routeguide.Feature} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.routeguide.Feature.prototype.serializeBinaryToWriter = function (writer) { +proto.routeguide.Feature.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getName(); + f = message.getName(); if (f.length > 0) { writer.writeString( 1, f ); } - f = this.getLocation(); + f = message.getLocation(); if (f != null) { writer.writeMessage( 2, @@ -551,80 +610,75 @@ proto.routeguide.Feature.prototype.serializeBinaryToWriter = function (writer) { }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.routeguide.Feature} The clone. - */ -proto.routeguide.Feature.prototype.cloneMessage = function() { - return /** @type {!proto.routeguide.Feature} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional string name = 1; * @return {string} */ proto.routeguide.Feature.prototype.getName = function() { - return /** @type {string} */ (jspb.Message.getFieldProto3(this, 1, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; -/** @param {string} value */ +/** + * @param {string} value + * @return {!proto.routeguide.Feature} returns this + */ proto.routeguide.Feature.prototype.setName = function(value) { - jspb.Message.setField(this, 1, value); + return jspb.Message.setProto3StringField(this, 1, value); }; /** * optional Point location = 2; - * @return {proto.routeguide.Point} + * @return {?proto.routeguide.Point} */ proto.routeguide.Feature.prototype.getLocation = function() { - return /** @type{proto.routeguide.Point} */ ( + return /** @type{?proto.routeguide.Point} */ ( jspb.Message.getWrapperField(this, proto.routeguide.Point, 2)); }; -/** @param {proto.routeguide.Point|undefined} value */ +/** + * @param {?proto.routeguide.Point|undefined} value + * @return {!proto.routeguide.Feature} returns this +*/ proto.routeguide.Feature.prototype.setLocation = function(value) { - jspb.Message.setWrapperField(this, 2, value); + return jspb.Message.setWrapperField(this, 2, value); }; +/** + * Clears the message field making it undefined. + * @return {!proto.routeguide.Feature} returns this + */ proto.routeguide.Feature.prototype.clearLocation = function() { - this.setLocation(undefined); + return this.setLocation(undefined); }; - /** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor + * Returns whether this field is set. + * @return {boolean} */ -proto.routeguide.RouteNote = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); +proto.routeguide.Feature.prototype.hasLocation = function() { + return jspb.Message.getField(this, 2) != null; }; -goog.inherits(proto.routeguide.RouteNote, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.routeguide.RouteNote.displayName = 'proto.routeguide.RouteNote'; -} + + + if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.routeguide.RouteNote.prototype.toObject = function(opt_includeInstance) { @@ -634,16 +688,17 @@ proto.routeguide.RouteNote.prototype.toObject = function(opt_includeInstance) { /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.routeguide.RouteNote} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.routeguide.RouteNote.toObject = function(includeInstance, msg) { var f, obj = { location: (f = msg.getLocation()) && proto.routeguide.Point.toObject(includeInstance, f), - message: msg.getMessage() + message: jspb.Message.getFieldWithDefault(msg, 2, "") }; if (includeInstance) { @@ -698,36 +753,27 @@ proto.routeguide.RouteNote.deserializeBinaryFromReader = function(msg, reader) { }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.routeguide.RouteNote} message - * @param {!jspb.BinaryWriter} writer - */ -proto.routeguide.RouteNote.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.routeguide.RouteNote.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.routeguide.RouteNote.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.routeguide.RouteNote} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.routeguide.RouteNote.prototype.serializeBinaryToWriter = function (writer) { +proto.routeguide.RouteNote.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getLocation(); + f = message.getLocation(); if (f != null) { writer.writeMessage( 1, @@ -735,7 +781,7 @@ proto.routeguide.RouteNote.prototype.serializeBinaryToWriter = function (writer) proto.routeguide.Point.serializeBinaryToWriter ); } - f = this.getMessage(); + f = message.getMessage(); if (f.length > 0) { writer.writeString( 2, @@ -745,33 +791,40 @@ proto.routeguide.RouteNote.prototype.serializeBinaryToWriter = function (writer) }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.routeguide.RouteNote} The clone. - */ -proto.routeguide.RouteNote.prototype.cloneMessage = function() { - return /** @type {!proto.routeguide.RouteNote} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional Point location = 1; - * @return {proto.routeguide.Point} + * @return {?proto.routeguide.Point} */ proto.routeguide.RouteNote.prototype.getLocation = function() { - return /** @type{proto.routeguide.Point} */ ( + return /** @type{?proto.routeguide.Point} */ ( jspb.Message.getWrapperField(this, proto.routeguide.Point, 1)); }; -/** @param {proto.routeguide.Point|undefined} value */ +/** + * @param {?proto.routeguide.Point|undefined} value + * @return {!proto.routeguide.RouteNote} returns this +*/ proto.routeguide.RouteNote.prototype.setLocation = function(value) { - jspb.Message.setWrapperField(this, 1, value); + return jspb.Message.setWrapperField(this, 1, value); }; +/** + * Clears the message field making it undefined. + * @return {!proto.routeguide.RouteNote} returns this + */ proto.routeguide.RouteNote.prototype.clearLocation = function() { - this.setLocation(undefined); + return this.setLocation(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.routeguide.RouteNote.prototype.hasLocation = function() { + return jspb.Message.getField(this, 1) != null; }; @@ -780,45 +833,33 @@ proto.routeguide.RouteNote.prototype.clearLocation = function() { * @return {string} */ proto.routeguide.RouteNote.prototype.getMessage = function() { - return /** @type {string} */ (jspb.Message.getFieldProto3(this, 2, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); }; -/** @param {string} value */ +/** + * @param {string} value + * @return {!proto.routeguide.RouteNote} returns this + */ proto.routeguide.RouteNote.prototype.setMessage = function(value) { - jspb.Message.setField(this, 2, value); + return jspb.Message.setProto3StringField(this, 2, value); }; -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.routeguide.RouteSummary = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.routeguide.RouteSummary, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.routeguide.RouteSummary.displayName = 'proto.routeguide.RouteSummary'; -} if (jspb.Message.GENERATE_TO_OBJECT) { /** - * Creates an object representation of this proto suitable for use in Soy templates. + * Creates an object representation of this proto. * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. * To access a reserved field use, foo.pb_, eg, foo.pb_default. * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration * @return {!Object} */ proto.routeguide.RouteSummary.prototype.toObject = function(opt_includeInstance) { @@ -828,18 +869,19 @@ proto.routeguide.RouteSummary.prototype.toObject = function(opt_includeInstance) /** * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: * http://goto/soy-param-migration * @param {!proto.routeguide.RouteSummary} msg The msg instance to transform. * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.routeguide.RouteSummary.toObject = function(includeInstance, msg) { var f, obj = { - pointCount: msg.getPointCount(), - featureCount: msg.getFeatureCount(), - distance: msg.getDistance(), - elapsedTime: msg.getElapsedTime() + pointCount: jspb.Message.getFieldWithDefault(msg, 1, 0), + featureCount: jspb.Message.getFieldWithDefault(msg, 2, 0), + distance: jspb.Message.getFieldWithDefault(msg, 3, 0), + elapsedTime: jspb.Message.getFieldWithDefault(msg, 4, 0) }; if (includeInstance) { @@ -901,57 +943,48 @@ proto.routeguide.RouteSummary.deserializeBinaryFromReader = function(msg, reader }; -/** - * Class method variant: serializes the given message to binary data - * (in protobuf wire format), writing to the given BinaryWriter. - * @param {!proto.routeguide.RouteSummary} message - * @param {!jspb.BinaryWriter} writer - */ -proto.routeguide.RouteSummary.serializeBinaryToWriter = function(message, writer) { - message.serializeBinaryToWriter(writer); -}; - - /** * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ proto.routeguide.RouteSummary.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - this.serializeBinaryToWriter(writer); + proto.routeguide.RouteSummary.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; /** - * Serializes the message to binary data (in protobuf wire format), - * writing to the given BinaryWriter. + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.routeguide.RouteSummary} message * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.routeguide.RouteSummary.prototype.serializeBinaryToWriter = function (writer) { +proto.routeguide.RouteSummary.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = this.getPointCount(); + f = message.getPointCount(); if (f !== 0) { writer.writeInt32( 1, f ); } - f = this.getFeatureCount(); + f = message.getFeatureCount(); if (f !== 0) { writer.writeInt32( 2, f ); } - f = this.getDistance(); + f = message.getDistance(); if (f !== 0) { writer.writeInt32( 3, f ); } - f = this.getElapsedTime(); + f = message.getElapsedTime(); if (f !== 0) { writer.writeInt32( 4, @@ -961,27 +994,21 @@ proto.routeguide.RouteSummary.prototype.serializeBinaryToWriter = function (writ }; -/** - * Creates a deep clone of this proto. No data is shared with the original. - * @return {!proto.routeguide.RouteSummary} The clone. - */ -proto.routeguide.RouteSummary.prototype.cloneMessage = function() { - return /** @type {!proto.routeguide.RouteSummary} */ (jspb.Message.cloneMessage(this)); -}; - - /** * optional int32 point_count = 1; * @return {number} */ proto.routeguide.RouteSummary.prototype.getPointCount = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.RouteSummary} returns this + */ proto.routeguide.RouteSummary.prototype.setPointCount = function(value) { - jspb.Message.setField(this, 1, value); + return jspb.Message.setProto3IntField(this, 1, value); }; @@ -990,13 +1017,16 @@ proto.routeguide.RouteSummary.prototype.setPointCount = function(value) { * @return {number} */ proto.routeguide.RouteSummary.prototype.getFeatureCount = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.RouteSummary} returns this + */ proto.routeguide.RouteSummary.prototype.setFeatureCount = function(value) { - jspb.Message.setField(this, 2, value); + return jspb.Message.setProto3IntField(this, 2, value); }; @@ -1005,13 +1035,16 @@ proto.routeguide.RouteSummary.prototype.setFeatureCount = function(value) { * @return {number} */ proto.routeguide.RouteSummary.prototype.getDistance = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 3, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.RouteSummary} returns this + */ proto.routeguide.RouteSummary.prototype.setDistance = function(value) { - jspb.Message.setField(this, 3, value); + return jspb.Message.setProto3IntField(this, 3, value); }; @@ -1020,13 +1053,16 @@ proto.routeguide.RouteSummary.prototype.setDistance = function(value) { * @return {number} */ proto.routeguide.RouteSummary.prototype.getElapsedTime = function() { - return /** @type {number} */ (jspb.Message.getFieldProto3(this, 4, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); }; -/** @param {number} value */ +/** + * @param {number} value + * @return {!proto.routeguide.RouteSummary} returns this + */ proto.routeguide.RouteSummary.prototype.setElapsedTime = function(value) { - jspb.Message.setField(this, 4, value); + return jspb.Message.setProto3IntField(this, 4, value); }; diff --git a/examples/node/static_codegen/route_guide/route_guide_server.js b/examples/node/static_codegen/route_guide/route_guide_server.js index eecac623544..eb1fd283df1 100644 --- a/examples/node/static_codegen/route_guide/route_guide_server.js +++ b/examples/node/static_codegen/route_guide/route_guide_server.js @@ -23,7 +23,7 @@ var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var COORD_FACTOR = 1e7; @@ -220,23 +220,24 @@ function getServer() { if (require.main === module) { // If this is run as a script, start a server on an unused port var routeServer = getServer(); - routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); - var argv = parseArgs(process.argv, { - string: 'db_path' - }); - fs.readFile(path.resolve(argv.db_path), function(err, data) { - if (err) throw err; - // Transform the loaded features to Feature objects - feature_list = _.map(JSON.parse(data), function(value) { - var feature = new messages.Feature(); - feature.setName(value.name); - var location = new messages.Point(); - location.setLatitude(value.location.latitude); - location.setLongitude(value.location.longitude); - feature.setLocation(location); - return feature; + routeServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { + var argv = parseArgs(process.argv, { + string: 'db_path' + }); + fs.readFile(path.resolve(argv.db_path), function(err, data) { + if (err) throw err; + // Transform the loaded features to Feature objects + feature_list = _.map(JSON.parse(data), function(value) { + var feature = new messages.Feature(); + feature.setName(value.name); + var location = new messages.Point(); + location.setLatitude(value.location.latitude); + location.setLongitude(value.location.longitude); + feature.setLocation(location); + return feature; + }); + routeServer.start(); }); - routeServer.start(); }); }