示例#1
0
void validate_value(protozero::pbf_reader value)
{
    using namespace osrm;
    while (value.next())
    {
        switch (value.tag())
        {
        case util::vector_tile::VARIANT_TYPE_BOOL:
            value.get_bool();
            break;
        case util::vector_tile::VARIANT_TYPE_DOUBLE:
            value.get_double();
            break;
        case util::vector_tile::VARIANT_TYPE_FLOAT:
            value.get_float();
            break;
        case util::vector_tile::VARIANT_TYPE_STRING:
            value.get_string();
            break;
        case util::vector_tile::VARIANT_TYPE_UINT64:
            value.get_uint64();
            break;
        case util::vector_tile::VARIANT_TYPE_SINT64:
            value.get_sint64();
            break;
        }
    }
}
示例#2
0
Value parseValue(protozero::pbf_reader data) {
    while (data.next())
    {
        switch (data.tag()) {
        case 1: // string_value
            return data.get_string();
        case 2: // float_value
            return static_cast<double>(data.get_float());
        case 3: // double_value
            return data.get_double();
        case 4: // int_value
            return data.get_int64();
        case 5: // uint_value
            return data.get_uint64();
        case 6: // sint_value
            return data.get_sint64();
        case 7: // bool_value
            return data.get_bool();
        default:
            data.skip();
            break;
        }
    }
    return false;
}
示例#3
0
void validate_node_layer(protozero::pbf_reader &layer_message)
{
    using namespace osrm;
    auto number_of_nodes_found = 0u;

    const auto check_osmnode_feature = [](protozero::pbf_reader feature_message) {
        feature_message.next(); // advance parser to first entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
        BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);

        feature_message.next(); // advance to next entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
        feature_message.get_uint64(); // id

        feature_message.next(); // advance to next entry
        // Note - on this layer, there should be no feature attributes, the next thing
        // we get should be the geometry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_GEOMETRIES_TAG);
        auto geometry_iter_pair = feature_message.get_packed_uint32();
        BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
    };

    while (layer_message.next())
    {
        switch (layer_message.tag())
        {
        case util::vector_tile::VERSION_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
            break;
        case util::vector_tile::NAME_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_string(), "osmnodes");
            break;
        case util::vector_tile::EXTENT_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
            break;
        case util::vector_tile::FEATURE_TAG:
            check_osmnode_feature(layer_message.get_message());
            number_of_nodes_found++;
            break;
        case util::vector_tile::KEY_TAG:
            BOOST_CHECK(false); // There should be no properties on node features
            break;
        case util::vector_tile::VARIANT_TAG:
            BOOST_CHECK(false); // There should be no properties on node features
            break;
        default:
            BOOST_CHECK(false); // invalid tag
            break;
        }
    }
    BOOST_CHECK_EQUAL(number_of_nodes_found, 1791);
}
示例#4
0
inline void check_subsub(protozero::pbf_reader message) {
    while (message.next()) {
        switch (message.tag()) {
            case 1: {
                REQUIRE("foobar" == message.get_string());
                break;
            }
            case 2: {
                REQUIRE(99 == message.get_int32());
                break;
            }
            default: {
                REQUIRE(false); // should never be here
                break;
            }
        }
    }
}
示例#5
0
void validate_feature_layer(protozero::pbf_reader &layer_message)
{
    using namespace osrm;

    const auto check_feature = [](protozero::pbf_reader feature_message) {
        feature_message.next(); // advance parser to first entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
        BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_LINE);

        feature_message.next(); // advance to next entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
        feature_message.get_uint64(); // id

        feature_message.next(); // advance to next entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
        // properties
        auto property_iter_pair = feature_message.get_packed_uint32();
        auto value_begin = property_iter_pair.begin();
        auto value_end = property_iter_pair.end();
        BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14);
        auto iter = value_begin;
        BOOST_CHECK_EQUAL(*iter++, 0); // speed key
        BOOST_CHECK_LT(*iter++, 128);  // speed value
        BOOST_CHECK_EQUAL(*iter++, 1); // component key
        // component value
        BOOST_CHECK_GE(*iter, 128);
        BOOST_CHECK_LE(*iter, 129);
        iter++;
        BOOST_CHECK_EQUAL(*iter++, 2); // data source key
        *iter++;                       // skip value check, can be valud uint32
        BOOST_CHECK_EQUAL(*iter++, 3); // weight key
        BOOST_CHECK_GT(*iter++, 130);  // weight value
        BOOST_CHECK_EQUAL(*iter++, 4); // duration key
        BOOST_CHECK_GT(*iter++, 130);  // duration value
        // name
        BOOST_CHECK_EQUAL(*iter++, 5);
        BOOST_CHECK_GT(*iter++, 130);
        // rate
        BOOST_CHECK_EQUAL(*iter++, 6);
        BOOST_CHECK_GT(*iter++, 130);
        BOOST_CHECK(iter == value_end);
        // geometry
        feature_message.next();
        auto geometry_iter_pair = feature_message.get_packed_uint32();
        BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
    };

    auto number_of_speed_keys = 0u;
    auto number_of_speed_values = 0u;

    while (layer_message.next())
    {
        switch (layer_message.tag())
        {
        case util::vector_tile::VERSION_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
            break;
        case util::vector_tile::NAME_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_string(), "speeds");
            break;
        case util::vector_tile::EXTENT_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
            break;
        case util::vector_tile::FEATURE_TAG:
            check_feature(layer_message.get_message());
            break;
        case util::vector_tile::KEY_TAG:
            layer_message.get_string();
            number_of_speed_keys++;
            break;
        case util::vector_tile::VARIANT_TAG:
            validate_value(layer_message.get_message());
            number_of_speed_values++;
            break;
        default:
            BOOST_CHECK(false); // invalid tag
            break;
        }
    }

    BOOST_CHECK_EQUAL(number_of_speed_keys, 7);
    BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution
}
示例#6
0
void validate_turn_layer(protozero::pbf_reader &layer_message)
{
    using namespace osrm;

    const auto check_turn_feature = [](protozero::pbf_reader feature_message) {
        feature_message.next(); // advance parser to first entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
        BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);

        feature_message.next(); // advance to next entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
        feature_message.get_uint64(); // id

        feature_message.next(); // advance to next entry
        BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
        // properties
        auto feature_iter_pair = feature_message.get_packed_uint32();
        BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 12);
        auto iter = feature_iter_pair.begin();
        BOOST_CHECK_EQUAL(*iter++, 0); // bearing_in key
        *iter++;
        BOOST_CHECK_EQUAL(*iter++, 1); // turn_angle key
        *iter++;
        BOOST_CHECK_EQUAL(*iter++, 2); // turn cost (duration) key
        *iter++;                       // skip value check, can be valud uint32
        BOOST_CHECK_EQUAL(*iter++, 3); // turn weight key
        *iter++;                       // skip value check, can be valud uint32
        BOOST_CHECK_EQUAL(*iter++, 4); // turn type key
        *iter++;                       // skip value check, can be valud uint32
        BOOST_CHECK_EQUAL(*iter++, 5); // turn modifier
        *iter++;                       // skip value check, can be valud uint32
        BOOST_CHECK(iter == feature_iter_pair.end());
        // geometry
        feature_message.next();
        auto geometry_iter_pair = feature_message.get_packed_uint32();
        BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
    };

    auto number_of_turn_keys = 0u;
    auto number_of_turns_found = 0u;

    while (layer_message.next())
    {
        switch (layer_message.tag())
        {
        case util::vector_tile::VERSION_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
            break;
        case util::vector_tile::NAME_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_string(), "turns");
            break;
        case util::vector_tile::EXTENT_TAG:
            BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
            break;
        case util::vector_tile::FEATURE_TAG:
            check_turn_feature(layer_message.get_message());
            number_of_turns_found++;
            break;
        case util::vector_tile::KEY_TAG:
            layer_message.get_string();
            number_of_turn_keys++;
            break;
        case util::vector_tile::VARIANT_TAG:
            validate_value(layer_message.get_message());
            break;
        default:
            BOOST_CHECK(false); // invalid tag
            break;
        }
    }

    BOOST_CHECK_EQUAL(number_of_turn_keys, 6);
    BOOST_CHECK(number_of_turns_found > 700);
}
static std::string get_name(protozero::pbf_reader layer) { // copy!
    while (layer.next(1)) { // required string name
        return layer.get_string();
    }
    return "";
}