From c273351d4a8201306d17c8c3a3f884ce42c0e5bc Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Mar 2012 15:44:21 +0100 Subject: [PATCH 1/2] PhantomNodes get transmitted as well. The client is supposed to send us this information whenever it's possible. --- Algorithms/ObjectToBase64.h | 58 ++++++++++++++++++++++++++++++++++++ Descriptors/JSONDescriptor.h | 20 ++++++++----- 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 Algorithms/ObjectToBase64.h diff --git a/Algorithms/ObjectToBase64.h b/Algorithms/ObjectToBase64.h new file mode 100644 index 000000000..1b44411df --- /dev/null +++ b/Algorithms/ObjectToBase64.h @@ -0,0 +1,58 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#ifndef OBJECTTOBASE64_H_ +#define OBJECTTOBASE64_H_ + +#include +#include +#include +#include + +#include +#include + +#include "../Util/StringUtil.h" + +typedef + boost::archive::iterators::base64_from_binary< + boost::archive::iterators::transform_width +> base64_t; + +typedef + boost::archive::iterators::transform_width< + boost::archive::iterators::binary_from_base64, 8, 6 +> binary_t; + +template +static void EncodeObjectToBase64(const ToEncodeT & object, std::string& encoded) { + assert(0 == encoded.length()); + char * pointerToOriginalObject = (char *)&object; + encoded = std::string(base64_t(pointerToOriginalObject), base64_t(pointerToOriginalObject+sizeof(ToEncodeT))); +} + +template +static void DecodeObjectFraBase64(ToEncodeT & object, const std::string& encoded) { + char * pointerToDecodedObject = (char *)&object; + std::string dec(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1)); + std::copy ( dec.begin(), dec.end(), pointerToDecodedObject ); +} + +#endif /* OBJECTTOBASE64_H_ */ diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index d81c7bb0b..d874cf8c4 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -21,10 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef JSON_DESCRIPTOR_H_ #define JSON_DESCRIPTOR_H_ -#include +#include #include "BaseDescriptor.h" #include "DescriptionFactory.h" +#include "../Algorithms/ObjectToBase64.h" #include "../DataStructures/SegmentInformation.h" #include "../DataStructures/TurnInstructions.h" #include "../Util/Azimuth.h" @@ -173,14 +174,17 @@ public: reply.content += ", \"hint_array\": ["; for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) { - unsigned hint = ((rawRoute.segmentEndCoordinates[i].startPhantom.edgeBasedNode << 1) + rawRoute.segmentEndCoordinates[i].startPhantom.isBidirected()); - intToString(hint, tmp); - reply.content += tmp; - reply.content += ", "; + std::string hint; + reply.content += "\""; + EncodeObjectToBase64(rawRoute.segmentEndCoordinates[i].startPhantom, hint); + reply.content += hint; + reply.content += "\", "; } - intToString(((rawRoute.segmentEndCoordinates.back().targetPhantom.edgeBasedNode << 1)+ rawRoute.segmentEndCoordinates.back().targetPhantom.isBidirected()), tmp); - reply.content += tmp; - reply.content += "]"; + std::string hint; + EncodeObjectToBase64(rawRoute.segmentEndCoordinates.back().targetPhantom, hint); + reply.content += "\""; + reply.content += hint; + reply.content += "\"]"; reply.content += "},"; reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\""; reply.content += "}"; From f7cc34c807fa54ec25ba4109858ffef83c069d53 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 5 Mar 2012 16:19:46 +0100 Subject: [PATCH 2/2] Parsing hints from request. If no hint is given, then it is initialized to empty string. --- Plugins/RouteParameters.h | 2 +- Server/RequestHandler.h | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index ef50c7cb6..46ffeda2d 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/HashTable.h" struct RouteParameters { - std::vector hints; + std::vector hints; std::vector parameters; std::vector viaPoints; HashTable options; diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index d77be20ed..3e76be4b4 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -85,13 +85,7 @@ public: } } else if("hint" == p) { routeParameters.hints.resize(routeParameters.viaPoints.size(), 0); - if(routeParameters.hints.size()) { - unsigned hint = 0; - try { - hint = 10*boost::lexical_cast(o); - } catch(boost::bad_lexical_cast &) { /* do nothing since hint is initialized to 0 */} - routeParameters.hints.back() = hint; - } + routeParameters.hints.back() = o; } else { routeParameters.options.Set(p, o); }