Add Flatbuffers support to NodeJS bindings (#6338)

This commit is contained in:
Siarhei Fedartsou
2022-08-29 22:01:26 +02:00
committed by GitHub
parent 06719be2b1
commit b4142cf1a2
10 changed files with 238 additions and 38 deletions
+18
View File
@@ -4,6 +4,24 @@ var data_path = require('./constants').data_path;
var mld_data_path = require('./constants').mld_data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
test('match: match in Monaco with flatbuffers format', function(assert) {
assert.plan(2);
var osrm = new OSRM(data_path);
var options = {
coordinates: three_test_coordinates,
timestamps: [1424684612, 1424684616, 1424684620],
format: 'flatbuffers'
};
osrm.match(options, function(err, response) {
assert.ifError(err);
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(response));
assert.equal(fb.routesLength(), 1);
});
});
test('match: match in Monaco', function(assert) {
assert.plan(5);
+18
View File
@@ -4,8 +4,26 @@ var data_path = require('./constants').data_path;
var mld_data_path = require('./constants').mld_data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
test('nearest with flatbuffers format', function(assert) {
assert.plan(5);
var osrm = new OSRM(data_path);
osrm.nearest({
coordinates: [three_test_coordinates[0]],
format: 'flatbuffers'
}, function(err, result) {
assert.ifError(err);
assert.ok(result instanceof Buffer);
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result));
assert.equals(fb.waypointsLength(), 1);
assert.ok(fb.waypoints(0).location());
assert.ok(fb.waypoints(0).name());
});
});
test('nearest', function(assert) {
assert.plan(4);
var osrm = new OSRM(data_path);
+45
View File
@@ -5,6 +5,51 @@ var monaco_mld_path = require('./constants').mld_data_path;
var monaco_corech_path = require('./constants').corech_data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
test('route: routes Monaco and can return result in flatbuffers', function(assert) {
assert.plan(5);
var osrm = new OSRM(monaco_path);
osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, function(err, result) {
assert.ifError(err);
assert.ok(result instanceof Buffer);
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result));
assert.equals(fb.waypointsLength(), 2);
assert.equals(fb.routesLength(), 1);
assert.ok(fb.routes(0).polyline);
});
});
test('route: routes Monaco and can return result in flatbuffers if output format is passed explicitly', function(assert) {
assert.plan(5);
var osrm = new OSRM(monaco_path);
osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {output: 'buffer'}, function(err, result) {
assert.ifError(err);
assert.ok(result instanceof Buffer);
var buf = new flatbuffers.ByteBuffer(result);
const fb = FBResult.getRootAsFBResult(buf);
assert.equals(fb.waypointsLength(), 2);
assert.equals(fb.routesLength(), 1);
assert.ok(fb.routes(0).polyline);
});
});
test('route: throws error if required output is object in flatbuffers format', function(assert) {
assert.plan(1);
var osrm = new OSRM(monaco_path);
assert.throws(function() {
osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'object'}, function(err, result) {});
});
});
test('route: throws error if required output is json_buffer in flatbuffers format', function(assert) {
assert.plan(1);
var osrm = new OSRM(monaco_path);
assert.throws(function() {
osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'json_buffer'}, function(err, result) {});
});
});
test('route: routes Monaco', function(assert) {
+18
View File
@@ -4,6 +4,24 @@ var data_path = require('./constants').data_path;
var mld_data_path = require('./constants').mld_data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
test('table: flatbuffer format', function(assert) {
assert.plan(3);
var osrm = new OSRM(data_path);
var options = {
coordinates: [three_test_coordinates[0], three_test_coordinates[1]],
format: 'flatbuffers'
};
osrm.table(options, function(err, table) {
assert.ifError(err);
assert.ok(table instanceof Buffer);
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(table));
assert.ok(fb.table());
});
});
test('table: test annotations paramater combination', function(assert) {
assert.plan(12);
+11
View File
@@ -4,7 +4,18 @@ var data_path = require('./constants').data_path;
var mld_data_path = require('./constants').mld_data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
test('trip: trip in Monaco with flatbuffers format', function(assert) {
assert.plan(2);
var osrm = new OSRM(data_path);
osrm.trip({coordinates: two_test_coordinates, format: 'flatbuffers'}, function(err, trip) {
assert.ifError(err);
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(trip));
assert.equal(fb.routesLength(), 1);
});
});
test('trip: trip in Monaco', function(assert) {
assert.plan(2);