2016-03-08 17:46:14 -05:00
|
|
|
#include "engine/hint.hpp"
|
2016-03-14 10:11:38 -04:00
|
|
|
#include "engine/base64.hpp"
|
2016-03-14 09:21:18 -04:00
|
|
|
#include "engine/datafacade/datafacade_base.hpp"
|
2016-03-08 17:46:14 -05:00
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2016-03-15 06:12:12 -04:00
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2016-03-08 17:46:14 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
2016-03-14 09:21:18 -04:00
|
|
|
|
|
|
|
bool Hint::IsValid(const util::Coordinate new_input_coordinates,
|
|
|
|
const datafacade::BaseDataFacade &facade) const
|
|
|
|
{
|
|
|
|
auto is_same_input_coordinate = new_input_coordinates.lon == phantom.input_location.lon &&
|
|
|
|
new_input_coordinates.lat == phantom.input_location.lat;
|
|
|
|
return is_same_input_coordinate && phantom.IsValid(facade.GetNumberOfNodes()) &&
|
|
|
|
facade.GetCheckSum() == data_checksum;
|
|
|
|
}
|
|
|
|
|
2016-03-15 06:12:12 -04:00
|
|
|
std::string Hint::ToBase64() const
|
|
|
|
{
|
|
|
|
auto base64 = encodeBase64Bytewise(*this);
|
|
|
|
|
|
|
|
// Make safe for usage as GET parameter in URLs
|
|
|
|
std::replace(begin(base64), end(base64), '+', '-');
|
|
|
|
std::replace(begin(base64), end(base64), '/', '_');
|
|
|
|
|
|
|
|
return base64;
|
|
|
|
}
|
2016-03-08 17:46:14 -05:00
|
|
|
|
|
|
|
Hint Hint::FromBase64(const std::string &base64Hint)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT_MSG(base64Hint.size() == ENCODED_HINT_SIZE, "Hint has invalid size");
|
|
|
|
|
2016-03-15 06:12:12 -04:00
|
|
|
// We need mutability but don't want to change the API
|
|
|
|
auto encoded = base64Hint;
|
|
|
|
|
|
|
|
// Reverses above encoding we need for GET parameters in URL
|
|
|
|
std::replace(begin(encoded), end(encoded), '-', '+');
|
|
|
|
std::replace(begin(encoded), end(encoded), '_', '/');
|
|
|
|
|
|
|
|
return decodeBase64Bytewise<Hint>(encoded);
|
2016-03-08 17:46:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|