diff --git a/src/node/examples/route_guide_db.json b/src/node/examples/route_guide_db.json new file mode 100644 index 00000000000..57f749382a4 --- /dev/null +++ b/src/node/examples/route_guide_db.json @@ -0,0 +1 @@ +[{"location":{"latitude":-898084041,"longitude":-956335530},"name":"Antarctica"},{"location":{"latitude":-146631624,"longitude":-958383511},"name":""},{"location":{"latitude":804112575,"longitude":-442594532},"name":"Greenland"},{"location":{"latitude":-49416972,"longitude":-350954955},"name":"Brazil"},{"location":{"latitude":89468665,"longitude":242327820},"name":"Buram, Sudan"},{"location":{"latitude":-649624710,"longitude":746289111},"name":""},{"location":{"latitude":-505487958,"longitude":-838328104},"name":""},{"location":{"latitude":848121953,"longitude":-298247781},"name":""},{"location":{"latitude":524094837,"longitude":-795584572},"name":"Baffin Region, NU, Canada"},{"location":{"latitude":56485291,"longitude":-187715698},"name":""},{"location":{"latitude":-470089856,"longitude":1789140056},"name":""},{"location":{"latitude":-577486081,"longitude":-1733155598},"name":""},{"location":{"latitude":577741664,"longitude":-873781618},"name":"Keewatin Region, NU, Canada"},{"location":{"latitude":306507262,"longitude":219338963},"name":"Al Wahat, Libya"},{"location":{"latitude":-446911497,"longitude":1679295563},"name":"154 Milford Sound Highway, Fiordland National Park 9679, New Zealand"},{"location":{"latitude":733881426,"longitude":737563031},"name":"Russia, 629705"},{"location":{"latitude":-688087271,"longitude":-262799641},"name":""},{"location":{"latitude":-99379946,"longitude":1774186549},"name":""},{"location":{"latitude":-65992383,"longitude":1099806539},"name":"Indonesia"},{"location":{"latitude":220938950,"longitude":968560584},"name":"41, Republic of the Union of Myanmar"},{"location":{"latitude":-594140442,"longitude":1504883782},"name":""},{"location":{"latitude":-707179151,"longitude":-896729854},"name":""},{"location":{"latitude":-787916310,"longitude":-889044879},"name":""},{"location":{"latitude":-119497900,"longitude":1114024289},"name":""},{"location":{"latitude":-648254087,"longitude":362768502},"name":""},{"location":{"latitude":-402418031,"longitude":117993618},"name":""},{"location":{"latitude":130550282,"longitude":-1032012014},"name":""},{"location":{"latitude":734388781,"longitude":-452362128},"name":""},{"location":{"latitude":-533182420,"longitude":1155727285},"name":""},{"location":{"latitude":741870560,"longitude":585594215},"name":""},{"location":{"latitude":-722890458,"longitude":-812696271},"name":""},{"location":{"latitude":-589756031,"longitude":-640124308},"name":""},{"location":{"latitude":190966959,"longitude":1496287526},"name":""},{"location":{"latitude":-836654415,"longitude":-1662752612},"name":""},{"location":{"latitude":-731583802,"longitude":-574895638},"name":""},{"location":{"latitude":-666407402,"longitude":-1535334105},"name":""},{"location":{"latitude":-790147961,"longitude":-1328725946},"name":""},{"location":{"latitude":858845788,"longitude":-864446073},"name":""},{"location":{"latitude":477627565,"longitude":336161401},"name":""},{"location":{"latitude":878499845,"longitude":-1366230271},"name":""},{"location":{"latitude":161644757,"longitude":1232275165},"name":""},{"location":{"latitude":654854594,"longitude":567182834},"name":""},{"location":{"latitude":572943963,"longitude":1261462818},"name":""},{"location":{"latitude":-679708566,"longitude":244550718},"name":""},{"location":{"latitude":-381192803,"longitude":1745293826},"name":""},{"location":{"latitude":137171282,"longitude":293455452},"name":""},{"location":{"latitude":667714793,"longitude":-26493598},"name":""},{"location":{"latitude":201258356,"longitude":1083312913},"name":""},{"location":{"latitude":-687799996,"longitude":-966880051},"name":""},{"location":{"latitude":-437056011,"longitude":1700457053},"name":""},{"location":{"latitude":-187508133,"longitude":511728352},"name":""},{"location":{"latitude":-512677292,"longitude":-911360176},"name":""},{"location":{"latitude":-208144386,"longitude":449727920},"name":""},{"location":{"latitude":-269716310,"longitude":-1370371395},"name":""},{"location":{"latitude":796592091,"longitude":-122849658},"name":""},{"location":{"latitude":134492646,"longitude":-894681833},"name":""},{"location":{"latitude":894694483,"longitude":-1229015411},"name":""},{"location":{"latitude":567905024,"longitude":-332346260},"name":""},{"location":{"latitude":838345452,"longitude":745395722},"name":""},{"location":{"latitude":108813570,"longitude":1517086626},"name":""},{"location":{"latitude":-273284408,"longitude":1637597498},"name":""},{"location":{"latitude":-221336059,"longitude":-3716325},"name":""},{"location":{"latitude":231027483,"longitude":1469916710},"name":""},{"location":{"latitude":223499746,"longitude":-805682376},"name":"Diego GarcĂ­a, Rodas, Cuba"},{"location":{"latitude":-257443435,"longitude":1566640501},"name":""},{"location":{"latitude":402291696,"longitude":-1298402965},"name":""},{"location":{"latitude":-398778441,"longitude":552807095},"name":""},{"location":{"latitude":152404713,"longitude":-1465239382},"name":""},{"location":{"latitude":-582856140,"longitude":-1629641450},"name":""},{"location":{"latitude":-473967125,"longitude":-1652968152},"name":""},{"location":{"latitude":-174439271,"longitude":1422960643},"name":"Strathmore QLD 4871, Australia"},{"location":{"latitude":253782635,"longitude":1030164726},"name":"011 Xiang Dao, Songming Xian, Kunming Shi, Yunnan Sheng, China"},{"location":{"latitude":-621365989,"longitude":-1115532139},"name":""},{"location":{"latitude":862664618,"longitude":1416457351},"name":""},{"location":{"latitude":-383388727,"longitude":-785952718},"name":""},{"location":{"latitude":125664168,"longitude":-291998446},"name":""},{"location":{"latitude":656343840,"longitude":439439764},"name":""},{"location":{"latitude":-655738461,"longitude":-544212722},"name":""},{"location":{"latitude":623251752,"longitude":1488435750},"name":""},{"location":{"latitude":436237502,"longitude":-626387911},"name":""},{"location":{"latitude":515395937,"longitude":-16624701},"name":"Hatchet Hill, Swindon, Swindon SN4 0DP, UK"},{"location":{"latitude":755285640,"longitude":572210361},"name":""},{"location":{"latitude":-52275136,"longitude":-644800186},"name":"Coari - AM, 69460-000, Brazil"},{"location":{"latitude":-402181536,"longitude":1006662754},"name":""},{"location":{"latitude":138914296,"longitude":368173660},"name":""},{"location":{"latitude":-645551826,"longitude":-519728595},"name":""},{"location":{"latitude":548423365,"longitude":-981205907},"name":""},{"location":{"latitude":749998314,"longitude":195688905},"name":""},{"location":{"latitude":861483051,"longitude":990210887},"name":""},{"location":{"latitude":286877612,"longitude":-1112752249},"name":""},{"location":{"latitude":633715864,"longitude":1766634742},"name":""},{"location":{"latitude":625250411,"longitude":-1430210949},"name":""},{"location":{"latitude":146536486,"longitude":-1562487612},"name":""},{"location":{"latitude":-846541096,"longitude":-860062860},"name":""},{"location":{"latitude":-243481285,"longitude":515382553},"name":""},{"location":{"latitude":-851258156,"longitude":373511818},"name":""},{"location":{"latitude":-366270851,"longitude":-52214308},"name":""},{"location":{"latitude":-842736612,"longitude":277021516},"name":""},{"location":{"latitude":753713504,"longitude":490552554},"name":""},{"location":{"latitude":-211675256,"longitude":-1172151400},"name":""}] diff --git a/src/node/examples/route_guide_server.js b/src/node/examples/route_guide_server.js index b21190d62e4..a3fb079215d 100644 --- a/src/node/examples/route_guide_server.js +++ b/src/node/examples/route_guide_server.js @@ -27,6 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +var fs = require('fs'); var _ = require('underscore'); var grpc = require('..'); var examples = grpc.load(__dirname + '/route_guide.proto').examples; @@ -47,21 +48,6 @@ var COORD_FACTOR = 1e7; */ var feature_list = []; -/** - * Return a random "word" (alphabetic character sequence) of the given length. - * @param {number} length The length of the word to create - * @return {string} An alphabetic string with the given length. - */ -function randomWord(length) { - var alphabet = 'abcdefghijklmnopqrstuvwxyz'; - var word = ''; - for (var i = 0; i < length; i++) { - // Add a random character from the alphabet to the word - word += alphabet[_.random(0, alphabet.length - 1)]; - } - return word; -} - /** * Get a feature object at the given point, or creates one if it does not exist. * @param {point} point The point to check @@ -78,19 +64,11 @@ function checkFeature(point) { return feature; } } - // If not, create a new one with 50% chance of indicating "no feature present" - var name; - if (_.random(0,1) === 0) { - name = ''; - } else { - name = randomWord(5); - } + var name = ''; feature = { name: name, location: point }; - // Add the feature object to the list and return it - feature_list.push(feature); return feature; } @@ -253,7 +231,11 @@ 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:0'); - routeServer.listen(); + fs.readFile(__dirname + '/route_guide_db.json', function(err, data) { + if (err) throw err; + feature_list = JSON.parse(data); + routeServer.listen(); + }); } exports.getServer = getServer;