2#include <vanetza/geodesy/country_polygon.hpp>
3#include <vanetza/geodesy/m49_code.hpp>
26 bool ok()
const {
return m_success; }
27 bool failed()
const {
return !ok(); }
28 const std::string& message()
const {
return m_detail; }
29 std::size_t position()
const {
return m_position; }
38 CountryReaderResult(std::size_t pos) : m_position(pos) {}
39 CountryReaderResult(std::string msg, std::size_t pos) :
40 m_success(
false), m_position(pos), m_detail(std::move(msg)) {}
42 bool m_success =
true;
43 std::size_t m_position = 0;
51
52
53static constexpr uint16_t country_data_format_version = 1;
56
57
58
59
60
61
62
65uint16_t read_u16le(
const uint8_t*);
66uint32_t read_u32le(
const uint8_t*);
71
72
73
74
75
76
77
78
79
80
81
82
83template<
typename CallbackFn>
84CountryReaderResult read_country_data(
const uint8_t* data, std::size_t length, CallbackFn fn)
86 if (length <
sizeof(uint16_t)) {
90 uint16_t version = detail::read_u16le(data);
91 if (version != detail::country_data_format_version) {
95 std::size_t offset =
sizeof(uint16_t);
96 const std::size_t entry_header_size =
sizeof(uint16_t) +
sizeof(uint32_t);
98 while (offset < length) {
99 if (length - offset < entry_header_size) {
103 uint16_t m49 = detail::read_u16le(data + offset);
104 offset +=
sizeof(uint16_t);
106 uint32_t wkb_size = detail::read_u32le(data + offset);
107 offset +=
sizeof(uint32_t);
109 if (length - offset < wkb_size) {
110 return CountryReaderResult::failure(
"invalid WKB payload size exceeding remaining data", offset);
113 CountryPolygon polygon;
114 auto inner = detail::parse_wkb(data + offset, wkb_size, polygon);
115 if (inner.failed()) {
116 inner.add_offset(offset);
120 fn(
M49Code(m49), std::move(polygon));