Skip to content

Commit

Permalink
Fixed nested offsets inside of the flatbuffers structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Chaplygin committed Aug 15, 2019
1 parent 8836dff commit 3ba6170
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 294 deletions.
16 changes: 11 additions & 5 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,23 @@ class BaseAPI
auto location =
fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)),
static_cast<double>(util::toFloating(phantom.location.lat)));
auto name_string = builder.CreateString(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());

boost::optional<flatbuffers::Offset<flatbuffers::String>> hint_string = boost::none;
if (parameters.generate_hints)
{
hint_string = builder.CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
}

fbresult::WaypointBuilder waypoint(builder);
waypoint.add_location(&location);
waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(
phantom.location, phantom.input_location));
auto name_string = builder.CreateString(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());
waypoint.add_name(name_string);
if (parameters.generate_hints)
if (hint_string)
{
auto hint_string = builder.CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
waypoint.add_hint(hint_string);
waypoint.add_hint(*hint_string);
}
return waypoint;
}
Expand Down
3 changes: 1 addition & 2 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class NearestAPI final : public BaseAPI
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
flatbuffers::FlatBufferBuilder &fb_result) const
{
fbresult::FBResultBuilder response(fb_result);

std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(phantom_nodes.front().size());
std::transform(phantom_nodes.front().begin(),
Expand All @@ -67,6 +65,7 @@ class NearestAPI final : public BaseAPI
});

auto waypoints_vector = fb_result.CreateVector(waypoints);
fbresult::FBResultBuilder response(fb_result);
response.add_waypoints(waypoints_vector);
fb_result.Finish(response.Finish());
}
Expand Down
Loading

0 comments on commit 3ba6170

Please sign in to comment.