feat: use rapidjson for osrm_route serializer#5462
feat: use rapidjson for osrm_route serializer#5462MohamedM216 wants to merge 19 commits intovalhalla:masterfrom
Conversation
migrate waypoints() to use rapidjson
|
After merging #5429 we need to remove this function in this PR valhalla/valhalla/tyr/serializers.h Line 129 in 7e36888 EDIT: Done |
| (prev_maneuver->type() == DirectionsLeg_Maneuver_Type_kRoundaboutEnter) && | ||
| !prev_step_json.empty()) { | ||
| rapidjson::writer_wrapper_t prev_step_writer; | ||
| prev_step_writer(prev_step_json); | ||
| prev_step_writer("destinations", dest); | ||
| prev_step_json = prev_step_writer.get_buffer(); | ||
| } |
There was a problem hiding this comment.
Some tests are failing due to wrong serialization here and in the next 2 ifs. The reason behind that is writing prev_step_json with the writer directly which means writing it as a string instead of proper json elements. I will work on finding a way to fix this. Probably using rapidjson::Document might work.
…ng multiple roots
| inline void raw_json(const std::string& json_string) { | ||
| writer.Flush(); | ||
| for (char c : json_string) { | ||
| buffer.Put(c); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
All these tests were failing due to writing prev_step_json as a string instead of proper json elements.
test_zero_length_route.cc
test_via_waypoints.cc
test_use.cc
test_use_direction_on_ways.cc
test_turn_lanes.cc
test_turns.cc
test_traffic.cc
test_tagged_values.cc
test_simple_restrictions.cc
test_search_filter.cc
test_route.cc
test_restricted_area.cc
test_recost.cc
test_osrm_serializer.cc
test_node_type.cc
test_multi_layer_loki.cc
test_maxspeed.cc
test_instructions_uturn.cc
test_instructions_collapse_double_turn.cc
test_conditional_restrictions.cc
test_admin.cc
test_route_summary.cc
test_access.cc
Now after adding this function raw_json, writer can write any valid json string as proper json elements.
| !prev_step_json.empty()) { | ||
| std::string inner_json = prev_step_json; | ||
| if (inner_json.front() == '{' && inner_json.back() == '}') { | ||
| inner_json = inner_json.substr(1, inner_json.size() - 2); |
There was a problem hiding this comment.
raw_json works correctly only for embedding inside an object or array, or it will throw !has_root exception coming fromprefix function. The reason behind that is writer expects only one root. So I removed the step object notations {} and then created a new one to be able to write inner_json and any other content.
|
As for the valhalla/src/tyr/route_serializer_osrm.cc Line 2179 in 2b1e693 I will start refactoring that part now. EDIT: Errors are coming from these lines: I think that there are only 2 reasons behind those errors:
Before I dive into the work, what changes do you suggest @nilsnolde? Should I restore the |
|
@nilsnolde should we may be merge it? WDYT? |
|
Last time I looked at it (a while ago admittedly), there was some strange json string parsing. Wanted to have a look if that can't be done a bit less hacky. |
Issue
This PR addresses issue #5190 by migrating the
osrm_routeAPI serializer from the legacyjson::implementation torapidjsonfor improved performance and consistency.This PR should close this issue
Tasklist
Requirements / Relations
#5190