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;
}
Exemple #2
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;
        }
    }
}
namespace TestBoolean {

enum class Test : protozero::pbf_tag_type {
    required_bool_b = 1
};

} // end namespace TestBoolean

TEST_CASE("read bool field using pbf_reader: false") {
    const std::string buffer = load_data("bool/data-false");

    protozero::pbf_reader item{buffer};

    REQUIRE(item.next());
    REQUIRE_FALSE(item.get_bool());
    REQUIRE_FALSE(item.next());
}

TEST_CASE("read bool field using pbf_reader: true") {
    const std::string buffer = load_data("bool/data-true");

    protozero::pbf_reader item{buffer};

    REQUIRE(item.next());
    REQUIRE(item.get_bool());
    REQUIRE_FALSE(item.next());
}

TEST_CASE("read bool field using pbf_reader: also true") {
    const std::string buffer = load_data("bool/data-also-true");