Added setting 'data_version' to all flatbuffers response functions.

This commit is contained in:
Denis Chaplygin 2019-08-23 12:20:56 +03:00
parent ce71e08ef1
commit 80e1abba0c
4 changed files with 45 additions and 1 deletions

View File

@ -49,10 +49,22 @@ class MatchAPI final : public RouteAPI
const std::vector<InternalRouteResult> &sub_routes,
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
}
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() {
return MakeTracepoints(fb_result, sub_matchings);
});
if (data_version_string)
{
response.add_data_version(*data_version_string);
}
fb_result.Finish(response.Finish());
}
void MakeResponse(const std::vector<map_matching::SubMatching> &sub_matchings,

View File

@ -47,6 +47,13 @@ class NearestAPI final : public BaseAPI
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
}
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(phantom_nodes.front().size());
std::transform(phantom_nodes.front().begin(),
@ -67,6 +74,10 @@ class NearestAPI final : public BaseAPI
auto waypoints_vector = fb_result.CreateVector(waypoints);
fbresult::FBResultBuilder response(fb_result);
response.add_waypoints(waypoints_vector);
if (data_version_string)
{
response.add_data_version(*data_version_string);
}
fb_result.Finish(response.Finish());
}
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,

View File

@ -72,6 +72,13 @@ class TableAPI final : public BaseAPI
auto number_of_sources = parameters.sources.size();
auto number_of_destinations = parameters.destinations.size();
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
}
// symmetric case
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> sources;
if (parameters.sources.empty())
@ -134,7 +141,10 @@ class TableAPI final : public BaseAPI
auto table_buffer = table.Finish();
fbresult::FBResultBuilder response(fb_result);
if (data_version_string)
{
response.add_data_version(*data_version_string);
}
response.add_table(table_buffer);
response.add_waypoints(sources);
fb_result.Finish(response.Finish());

View File

@ -47,11 +47,22 @@ class TripAPI final : public RouteAPI
const std::vector<PhantomNode> &phantoms,
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
}
auto response =
MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &phantoms]() {
return MakeWaypoints(fb_result, sub_trips, phantoms);
});
if (data_version_string)
{
response.add_data_version(*data_version_string);
}
fb_result.Finish(response.Finish());
}
void MakeResponse(const std::vector<std::vector<NodeID>> &sub_trips,