Added flatbuffers support to the PluginBase::Error
This changes BREAKS osrm.
This commit is contained in:
parent
56406e80ce
commit
7ddda105a3
@ -440,6 +440,8 @@ set(VTZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vtzero/include")
|
|||||||
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
|
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
|
||||||
|
|
||||||
set(FLATBUFFERS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers")
|
set(FLATBUFFERS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers")
|
||||||
|
set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include")
|
||||||
|
include_directories(${FLATBUFFERS_INCLUDE_DIR})
|
||||||
add_subdirectory(${FLATBUFFERS_SRC_DIR}
|
add_subdirectory(${FLATBUFFERS_SRC_DIR}
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
|
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
|
||||||
EXCLUDE_FROM_ALL)
|
EXCLUDE_FROM_ALL)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef ENGINE_API_BASE_RESULT_HPP
|
#ifndef ENGINE_API_BASE_RESULT_HPP
|
||||||
#define ENGINE_API_BASE_RESULT_HPP
|
#define ENGINE_API_BASE_RESULT_HPP
|
||||||
|
|
||||||
|
#include <flatbuffers/flatbuffers.h>
|
||||||
#include <mapbox/variant.hpp>
|
#include <mapbox/variant.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -13,7 +14,7 @@ namespace engine
|
|||||||
{
|
{
|
||||||
namespace api
|
namespace api
|
||||||
{
|
{
|
||||||
using ResultT = mapbox::util::variant<util::json::Object, std::string>;
|
using ResultT = mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
|
||||||
} // ns api
|
} // ns api
|
||||||
} // ns engine
|
} // ns engine
|
||||||
} // ns osrm
|
} // ns osrm
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "engine/api/base_parameters.hpp"
|
#include "engine/api/base_parameters.hpp"
|
||||||
#include "engine/api/base_result.hpp"
|
#include "engine/api/base_result.hpp"
|
||||||
|
#include "engine/api/flatbuffers/fbresult_generated.h"
|
||||||
#include "engine/datafacade/datafacade_base.hpp"
|
#include "engine/datafacade/datafacade_base.hpp"
|
||||||
#include "engine/phantom_node.hpp"
|
#include "engine/phantom_node.hpp"
|
||||||
#include "engine/routing_algorithms.hpp"
|
#include "engine/routing_algorithms.hpp"
|
||||||
@ -63,14 +64,32 @@ class BasePlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ErrorRenderer {
|
||||||
|
std::string code;
|
||||||
|
std::string message;
|
||||||
|
|
||||||
|
ErrorRenderer(std::string code, std::string message) : code(std::move(code)), message(std::move(message)) {};
|
||||||
|
|
||||||
|
void operator()(util::json::Object& json_result) {
|
||||||
|
json_result.values["code"] = code;
|
||||||
|
json_result.values["message"] = message;
|
||||||
|
};
|
||||||
|
void operator()(flatbuffers::FlatBufferBuilder& fb_result) {
|
||||||
|
osrm::engine::api::fbresult::FBResultBuilder error(fb_result);
|
||||||
|
error.add_code(fb_result.CreateString(code));
|
||||||
|
error.add_message(fb_result.CreateString(message));
|
||||||
|
fb_result.Finish(error.Finish());
|
||||||
|
};
|
||||||
|
void operator()(std::string& str_result) {
|
||||||
|
str_result = str(boost::format("code=%1% message=%2%") % code % message);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
Status Error(const std::string &code,
|
Status Error(const std::string &code,
|
||||||
const std::string &message,
|
const std::string &message,
|
||||||
osrm::engine::api::ResultT &result) const
|
osrm::engine::api::ResultT &result) const
|
||||||
{
|
{
|
||||||
result = util::json::Object();
|
mapbox::util::apply_visitor(ErrorRenderer(code, message), result);
|
||||||
auto& json_result = result.get<util::json::Object>();
|
|
||||||
json_result.values["code"] = code;
|
|
||||||
json_result.values["message"] = message;
|
|
||||||
return Status::Error;
|
return Status::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
|||||||
const api::TableParameters ¶ms,
|
const api::TableParameters ¶ms,
|
||||||
osrm::engine::api::ResultT &result) const
|
osrm::engine::api::ResultT &result) const
|
||||||
{
|
{
|
||||||
auto& json_result = result.get<util::json::Object>();
|
|
||||||
if (!algorithms.HasManyToManySearch())
|
if (!algorithms.HasManyToManySearch())
|
||||||
{
|
{
|
||||||
return Error("NotImplemented",
|
return Error("NotImplemented",
|
||||||
@ -155,6 +154,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
api::TableAPI table_api{facade, params};
|
api::TableAPI table_api{facade, params};
|
||||||
|
auto& json_result = result.get<util::json::Object>();
|
||||||
table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, json_result);
|
table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, json_result);
|
||||||
|
|
||||||
return Status::Ok;
|
return Status::Ok;
|
||||||
|
@ -97,6 +97,12 @@ TableService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engi
|
|||||||
}
|
}
|
||||||
BOOST_ASSERT(parameters->IsValid());
|
BOOST_ASSERT(parameters->IsValid());
|
||||||
|
|
||||||
|
if (parameters->format)
|
||||||
|
{
|
||||||
|
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) {
|
||||||
|
result = flatbuffers::FlatBufferBuilder();
|
||||||
|
}
|
||||||
|
}
|
||||||
return BaseService::routing_machine.Table(*parameters, result);
|
return BaseService::routing_machine.Table(*parameters, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user