Skip to content

Commit

Permalink
Added setting 'data_version' to all flatbuffers response functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Chaplygin committed Aug 23, 2019
1 parent 9312724 commit 050e673
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 11 additions & 0 deletions include/engine/api/trip_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 050e673

Please sign in to comment.