mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
clang-format on c++ code
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
clang test.cpp -std=c++11 -lstdc++ -o test && ./test
|
clang test.cpp -std=c++11 -lstdc++ -o test && ./test
|
||||||
|
|
||||||
|
indent:
|
||||||
|
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false, SortIncludes: false}" pmtiles.hpp test.cpp
|
||||||
|
|||||||
227
cpp/pmtiles.hpp
227
cpp/pmtiles.hpp
@@ -38,73 +38,73 @@ struct headerv3 {
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "PMTiles";
|
ss << "PMTiles";
|
||||||
uint8_t version = 3;
|
uint8_t version = 3;
|
||||||
ss.write((char *)&version,1);
|
ss.write((char *) &version, 1);
|
||||||
ss.write((char *)&root_dir_offset,8);
|
ss.write((char *) &root_dir_offset, 8);
|
||||||
ss.write((char *)&root_dir_bytes,8);
|
ss.write((char *) &root_dir_bytes, 8);
|
||||||
ss.write((char *)&json_metadata_offset,8);
|
ss.write((char *) &json_metadata_offset, 8);
|
||||||
ss.write((char *)&json_metadata_bytes,8);
|
ss.write((char *) &json_metadata_bytes, 8);
|
||||||
ss.write((char *)&leaf_dirs_offset,8);
|
ss.write((char *) &leaf_dirs_offset, 8);
|
||||||
ss.write((char *)&leaf_dirs_bytes,8);
|
ss.write((char *) &leaf_dirs_bytes, 8);
|
||||||
ss.write((char *)&tile_data_offset,8);
|
ss.write((char *) &tile_data_offset, 8);
|
||||||
ss.write((char *)&tile_data_bytes,8);
|
ss.write((char *) &tile_data_bytes, 8);
|
||||||
ss.write((char *)&addressed_tiles_count,8);
|
ss.write((char *) &addressed_tiles_count, 8);
|
||||||
ss.write((char *)&tile_entries_count,8);
|
ss.write((char *) &tile_entries_count, 8);
|
||||||
ss.write((char *)&tile_contents_count,8);
|
ss.write((char *) &tile_contents_count, 8);
|
||||||
|
|
||||||
uint8_t clustered_val = 0x0;
|
uint8_t clustered_val = 0x0;
|
||||||
if (clustered) {
|
if (clustered) {
|
||||||
clustered_val = 0x1;
|
clustered_val = 0x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ss.write((char *)&clustered_val,1);
|
ss.write((char *) &clustered_val, 1);
|
||||||
ss.write((char *)&internal_compression,1);
|
ss.write((char *) &internal_compression, 1);
|
||||||
ss.write((char *)&tile_compression,1);
|
ss.write((char *) &tile_compression, 1);
|
||||||
ss.write((char *)&tile_type,1);
|
ss.write((char *) &tile_type, 1);
|
||||||
ss.write((char *)&min_zoom,1);
|
ss.write((char *) &min_zoom, 1);
|
||||||
ss.write((char *)&max_zoom,1);
|
ss.write((char *) &max_zoom, 1);
|
||||||
ss.write((char *)&min_lon_e7,4);
|
ss.write((char *) &min_lon_e7, 4);
|
||||||
ss.write((char *)&min_lat_e7,4);
|
ss.write((char *) &min_lat_e7, 4);
|
||||||
ss.write((char *)&max_lon_e7,4);
|
ss.write((char *) &max_lon_e7, 4);
|
||||||
ss.write((char *)&max_lat_e7,4);
|
ss.write((char *) &max_lat_e7, 4);
|
||||||
ss.write((char *)¢er_zoom,1);
|
ss.write((char *) ¢er_zoom, 1);
|
||||||
ss.write((char *)¢er_lon_e7,4);
|
ss.write((char *) ¢er_lon_e7, 4);
|
||||||
ss.write((char *)¢er_lat_e7,4);
|
ss.write((char *) ¢er_lat_e7, 4);
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmtiles_magic_number_exception : std::exception {
|
struct pmtiles_magic_number_exception : std::exception {
|
||||||
const char* what() const noexcept override {
|
const char *what() const noexcept override {
|
||||||
return "pmtiles magic number exception";
|
return "pmtiles magic number exception";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmtiles_version_exception : std::exception {
|
struct pmtiles_version_exception : std::exception {
|
||||||
const char* what() const noexcept override {
|
const char *what() const noexcept override {
|
||||||
return "pmtiles version: must be 3";
|
return "pmtiles version: must be 3";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline headerv3 deserialize_header(const std::string &s) {
|
inline headerv3 deserialize_header(const std::string &s) {
|
||||||
if (s.substr(0,7) != "PMTiles") {
|
if (s.substr(0, 7) != "PMTiles") {
|
||||||
throw pmtiles_magic_number_exception{};
|
throw pmtiles_magic_number_exception{};
|
||||||
}
|
}
|
||||||
if (s.size() != 127 || s[7] != 0x3) {
|
if (s.size() != 127 || s[7] != 0x3) {
|
||||||
throw pmtiles_version_exception{};
|
throw pmtiles_version_exception{};
|
||||||
}
|
}
|
||||||
headerv3 h;
|
headerv3 h;
|
||||||
s.copy((char *)&h.root_dir_offset,8,8);
|
s.copy((char *) &h.root_dir_offset, 8, 8);
|
||||||
s.copy((char *)&h.root_dir_bytes,8,16);
|
s.copy((char *) &h.root_dir_bytes, 8, 16);
|
||||||
s.copy((char *)&h.json_metadata_offset,8,24);
|
s.copy((char *) &h.json_metadata_offset, 8, 24);
|
||||||
s.copy((char *)&h.json_metadata_bytes,8,32);
|
s.copy((char *) &h.json_metadata_bytes, 8, 32);
|
||||||
s.copy((char *)&h.leaf_dirs_offset,8,40);
|
s.copy((char *) &h.leaf_dirs_offset, 8, 40);
|
||||||
s.copy((char *)&h.leaf_dirs_bytes,8,48);
|
s.copy((char *) &h.leaf_dirs_bytes, 8, 48);
|
||||||
s.copy((char *)&h.tile_data_offset,8,56);
|
s.copy((char *) &h.tile_data_offset, 8, 56);
|
||||||
s.copy((char *)&h.tile_data_bytes,8,64);
|
s.copy((char *) &h.tile_data_bytes, 8, 64);
|
||||||
s.copy((char *)&h.addressed_tiles_count,8,72);
|
s.copy((char *) &h.addressed_tiles_count, 8, 72);
|
||||||
s.copy((char *)&h.tile_entries_count,8,80);
|
s.copy((char *) &h.tile_entries_count, 8, 80);
|
||||||
s.copy((char *)&h.tile_contents_count,8,88);
|
s.copy((char *) &h.tile_contents_count, 8, 88);
|
||||||
if (s[96] == 0x1) {
|
if (s[96] == 0x1) {
|
||||||
h.clustered = true;
|
h.clustered = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -115,13 +115,13 @@ inline headerv3 deserialize_header(const std::string &s) {
|
|||||||
h.tile_type = s[99];
|
h.tile_type = s[99];
|
||||||
h.min_zoom = s[100];
|
h.min_zoom = s[100];
|
||||||
h.max_zoom = s[101];
|
h.max_zoom = s[101];
|
||||||
s.copy((char *)&h.min_lon_e7,4,102);
|
s.copy((char *) &h.min_lon_e7, 4, 102);
|
||||||
s.copy((char *)&h.min_lat_e7,4,106);
|
s.copy((char *) &h.min_lat_e7, 4, 106);
|
||||||
s.copy((char *)&h.max_lon_e7,4,110);
|
s.copy((char *) &h.max_lon_e7, 4, 110);
|
||||||
s.copy((char *)&h.max_lat_e7,4,114);
|
s.copy((char *) &h.max_lat_e7, 4, 114);
|
||||||
h.center_zoom = s[118];
|
h.center_zoom = s[118];
|
||||||
s.copy((char *)&h.center_lon_e7,4,119);
|
s.copy((char *) &h.center_lon_e7, 4, 119);
|
||||||
s.copy((char *)&h.center_lat_e7,4,123);
|
s.copy((char *) &h.center_lat_e7, 4, 123);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +130,8 @@ struct zxy {
|
|||||||
uint32_t x;
|
uint32_t x;
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
|
|
||||||
zxy(int _z, int _x, int _y) : z(_z), x(_x), y(_y) {
|
zxy(int _z, int _x, int _y)
|
||||||
|
: z(_z), x(_x), y(_y) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -140,7 +141,8 @@ struct entryv3 {
|
|||||||
uint32_t length;
|
uint32_t length;
|
||||||
uint32_t run_length;
|
uint32_t run_length;
|
||||||
|
|
||||||
entryv3() : tile_id(0), offset(0), length(0), run_length(0) {
|
entryv3()
|
||||||
|
: tile_id(0), offset(0), length(0), run_length(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
entryv3(uint64_t _tile_id, uint64_t _offset, uint32_t _length, uint32_t _run_length)
|
entryv3(uint64_t _tile_id, uint64_t _offset, uint32_t _length, uint32_t _run_length)
|
||||||
@@ -149,44 +151,85 @@ struct entryv3 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool operator()(entryv3 a, entryv3 b) const { return a.tile_id < b.tile_id; }
|
bool operator()(entryv3 a, entryv3 b) const {
|
||||||
|
return a.tile_id < b.tile_id;
|
||||||
|
}
|
||||||
} entryv3_cmp;
|
} entryv3_cmp;
|
||||||
|
|
||||||
struct varint_too_long_exception : std::exception {
|
struct varint_too_long_exception : std::exception {
|
||||||
const char* what() const noexcept override {
|
const char *what() const noexcept override {
|
||||||
return "varint too long exception";
|
return "varint too long exception";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct end_of_buffer_exception : std::exception {
|
struct end_of_buffer_exception : std::exception {
|
||||||
const char* what() const noexcept override {
|
const char *what() const noexcept override {
|
||||||
return "end of buffer exception";
|
return "end of buffer exception";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
constexpr const int8_t max_varint_length = sizeof(uint64_t) * 8 / 7 + 1;
|
constexpr const int8_t max_varint_length = sizeof(uint64_t) * 8 / 7 + 1;
|
||||||
|
|
||||||
// from https://github.com/mapbox/protozero/blob/master/include/protozero/varint.hpp
|
// from https://github.com/mapbox/protozero/blob/master/include/protozero/varint.hpp
|
||||||
inline uint64_t decode_varint_impl(const char** data, const char* end) {
|
inline uint64_t decode_varint_impl(const char **data, const char *end) {
|
||||||
const auto* begin = reinterpret_cast<const int8_t*>(*data);
|
const auto *begin = reinterpret_cast<const int8_t *>(*data);
|
||||||
const auto* iend = reinterpret_cast<const int8_t*>(end);
|
const auto *iend = reinterpret_cast<const int8_t *>(end);
|
||||||
const int8_t* p = begin;
|
const int8_t *p = begin;
|
||||||
uint64_t val = 0;
|
uint64_t val = 0;
|
||||||
|
|
||||||
if (iend - begin >= max_varint_length) { // fast path
|
if (iend - begin >= max_varint_length) { // fast path
|
||||||
do {
|
do {
|
||||||
int64_t b = *p++;
|
int64_t b = *p++;
|
||||||
val = ((uint64_t(b) & 0x7fU) ); if (b >= 0) { break; }
|
val = ((uint64_t(b) & 0x7fU));
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 7U); if (b >= 0) { break; }
|
if (b >= 0) {
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 14U); if (b >= 0) { break; }
|
break;
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 21U); if (b >= 0) { break; }
|
}
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 28U); if (b >= 0) { break; }
|
b = *p++;
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 35U); if (b >= 0) { break; }
|
val |= ((uint64_t(b) & 0x7fU) << 7U);
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 42U); if (b >= 0) { break; }
|
if (b >= 0) {
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 49U); if (b >= 0) { break; }
|
break;
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x7fU) << 56U); if (b >= 0) { break; }
|
}
|
||||||
b = *p++; val |= ((uint64_t(b) & 0x01U) << 63U); if (b >= 0) { break; }
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 14U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 21U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 28U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 35U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 42U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 49U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x7fU) << 56U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
b = *p++;
|
||||||
|
val |= ((uint64_t(b) & 0x01U) << 63U);
|
||||||
|
if (b >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
throw varint_too_long_exception{};
|
throw varint_too_long_exception{};
|
||||||
} while (false);
|
} while (false);
|
||||||
} else {
|
} else {
|
||||||
@@ -201,11 +244,11 @@ namespace detail {
|
|||||||
val |= uint64_t(*p++) << shift;
|
val |= uint64_t(*p++) << shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data = reinterpret_cast<const char*>(p);
|
*data = reinterpret_cast<const char *>(p);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t decode_varint(const char** data, const char* end) {
|
inline uint64_t decode_varint(const char **data, const char *end) {
|
||||||
// If this is a one-byte varint, decode it here.
|
// If this is a one-byte varint, decode it here.
|
||||||
if (end != *data && ((static_cast<uint64_t>(**data) & 0x80U) == 0)) {
|
if (end != *data && ((static_cast<uint64_t>(**data) & 0x80U) == 0)) {
|
||||||
const auto val = static_cast<uint64_t>(**data);
|
const auto val = static_cast<uint64_t>(**data);
|
||||||
@@ -214,36 +257,36 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
// If this varint is more than one byte, defer to complete implementation.
|
// If this varint is more than one byte, defer to complete implementation.
|
||||||
return detail::decode_varint_impl(data, end);
|
return detail::decode_varint_impl(data, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void rotate(int64_t n, int64_t &x, int64_t &y, int64_t rx, int64_t ry) {
|
inline void rotate(int64_t n, int64_t &x, int64_t &y, int64_t rx, int64_t ry) {
|
||||||
if (ry == 0) {
|
if (ry == 0) {
|
||||||
if (rx == 1) {
|
if (rx == 1) {
|
||||||
x = n-1 - x;
|
x = n - 1 - x;
|
||||||
y = n-1 - y;
|
y = n - 1 - y;
|
||||||
}
|
}
|
||||||
int64_t t = x;
|
int64_t t = x;
|
||||||
x = y;
|
x = y;
|
||||||
y = t;
|
y = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline zxy t_on_level(uint8_t z, uint64_t pos) {
|
inline zxy t_on_level(uint8_t z, uint64_t pos) {
|
||||||
int64_t n = 1 << z;
|
int64_t n = 1 << z;
|
||||||
int64_t rx, ry, s, t = pos;
|
int64_t rx, ry, s, t = pos;
|
||||||
int64_t tx = 0;
|
int64_t tx = 0;
|
||||||
int64_t ty = 0;
|
int64_t ty = 0;
|
||||||
|
|
||||||
for (s=1; s<n; s*=2) {
|
for (s = 1; s < n; s *= 2) {
|
||||||
rx = 1 & (t/2);
|
rx = 1 & (t / 2);
|
||||||
ry = 1 & (t ^ rx);
|
ry = 1 & (t ^ rx);
|
||||||
rotate(s, tx, ty, rx, ry);
|
rotate(s, tx, ty, rx, ry);
|
||||||
tx += s * rx;
|
tx += s * rx;
|
||||||
ty += s * ry;
|
ty += s * ry;
|
||||||
t /= 4;
|
t /= 4;
|
||||||
}
|
}
|
||||||
return zxy(z,tx,ty);
|
return zxy(z, tx, ty);
|
||||||
}
|
}
|
||||||
} // end namespace detail
|
} // end namespace detail
|
||||||
|
|
||||||
inline int write_varint(std::back_insert_iterator<std::string> data, uint64_t value) {
|
inline int write_varint(std::back_insert_iterator<std::string> data, uint64_t value) {
|
||||||
@@ -262,7 +305,7 @@ inline int write_varint(std::back_insert_iterator<std::string> data, uint64_t va
|
|||||||
inline zxy tileid_to_zxy(uint64_t tileid) {
|
inline zxy tileid_to_zxy(uint64_t tileid) {
|
||||||
uint64_t acc = 0;
|
uint64_t acc = 0;
|
||||||
uint8_t t_z = 0;
|
uint8_t t_z = 0;
|
||||||
while(true) {
|
while (true) {
|
||||||
uint64_t num_tiles = (1 << t_z) * (1 << t_z);
|
uint64_t num_tiles = (1 << t_z) * (1 << t_z);
|
||||||
if (acc + num_tiles > tileid) {
|
if (acc + num_tiles > tileid) {
|
||||||
return detail::t_on_level(t_z, tileid - acc);
|
return detail::t_on_level(t_z, tileid - acc);
|
||||||
@@ -276,10 +319,10 @@ inline uint64_t zxy_to_tileid(uint8_t z, uint32_t x, uint32_t y) {
|
|||||||
uint64_t acc = 0;
|
uint64_t acc = 0;
|
||||||
for (uint8_t t_z = 0; t_z < z; t_z++) acc += (0x1 << t_z) * (0x1 << t_z);
|
for (uint8_t t_z = 0; t_z < z; t_z++) acc += (0x1 << t_z) * (0x1 << t_z);
|
||||||
int64_t n = 1 << z;
|
int64_t n = 1 << z;
|
||||||
int64_t rx, ry, s, d=0;
|
int64_t rx, ry, s, d = 0;
|
||||||
int64_t tx = x;
|
int64_t tx = x;
|
||||||
int64_t ty = y;
|
int64_t ty = y;
|
||||||
for (s=n/2; s>0; s/=2) {
|
for (s = n / 2; s > 0; s /= 2) {
|
||||||
rx = (tx & s) > 0;
|
rx = (tx & s) > 0;
|
||||||
ry = (ty & s) > 0;
|
ry = (ty & s) > 0;
|
||||||
d += s * s * ((3 * rx) ^ ry);
|
d += s * s * ((3 * rx) ^ ry);
|
||||||
@@ -289,7 +332,7 @@ inline uint64_t zxy_to_tileid(uint8_t z, uint32_t x, uint32_t y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns an uncompressed byte buffer
|
// returns an uncompressed byte buffer
|
||||||
inline std::string serialize_directory(const std::vector<entryv3>& entries) {
|
inline std::string serialize_directory(const std::vector<entryv3> &entries) {
|
||||||
std::string data;
|
std::string data;
|
||||||
|
|
||||||
write_varint(std::back_inserter(data), entries.size());
|
write_varint(std::back_inserter(data), entries.size());
|
||||||
@@ -309,10 +352,10 @@ inline std::string serialize_directory(const std::vector<entryv3>& entries) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < entries.size(); i++) {
|
for (size_t i = 0; i < entries.size(); i++) {
|
||||||
if (i > 0 && entries[i].offset == entries[i-1].offset + entries[i-1].length) {
|
if (i > 0 && entries[i].offset == entries[i - 1].offset + entries[i - 1].length) {
|
||||||
write_varint(std::back_inserter(data), 0);
|
write_varint(std::back_inserter(data), 0);
|
||||||
} else {
|
} else {
|
||||||
write_varint(std::back_inserter(data), entries[i].offset+1);
|
write_varint(std::back_inserter(data), entries[i].offset + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,31 +367,31 @@ inline std::vector<entryv3> deserialize_directory(const std::string &decompresse
|
|||||||
const char *t = decompressed.data();
|
const char *t = decompressed.data();
|
||||||
const char *end = t + decompressed.size();
|
const char *end = t + decompressed.size();
|
||||||
|
|
||||||
uint64_t num_entries = detail::decode_varint(&t,end);
|
uint64_t num_entries = detail::decode_varint(&t, end);
|
||||||
|
|
||||||
std::vector<entryv3> result;
|
std::vector<entryv3> result;
|
||||||
result.resize(num_entries);
|
result.resize(num_entries);
|
||||||
|
|
||||||
uint64_t last_id = 0;
|
uint64_t last_id = 0;
|
||||||
for (size_t i = 0; i < num_entries; i++) {
|
for (size_t i = 0; i < num_entries; i++) {
|
||||||
uint64_t tile_id = last_id + detail::decode_varint(&t,end);
|
uint64_t tile_id = last_id + detail::decode_varint(&t, end);
|
||||||
result[i].tile_id = tile_id;
|
result[i].tile_id = tile_id;
|
||||||
last_id = tile_id;
|
last_id = tile_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < num_entries; i++) {
|
for (size_t i = 0; i < num_entries; i++) {
|
||||||
result[i].run_length = detail::decode_varint(&t,end);
|
result[i].run_length = detail::decode_varint(&t, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < num_entries; i++) {
|
for (size_t i = 0; i < num_entries; i++) {
|
||||||
result[i].length = detail::decode_varint(&t,end);
|
result[i].length = detail::decode_varint(&t, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < num_entries; i++) {
|
for (size_t i = 0; i < num_entries; i++) {
|
||||||
uint64_t tmp = detail::decode_varint(&t,end);
|
uint64_t tmp = detail::decode_varint(&t, end);
|
||||||
|
|
||||||
if (i > 0 && tmp == 0) {
|
if (i > 0 && tmp == 0) {
|
||||||
result[i].offset = result[i-1].offset + result[i-1].length;
|
result[i].offset = result[i - 1].offset + result[i - 1].length;
|
||||||
} else {
|
} else {
|
||||||
result[i].offset = tmp - 1;
|
result[i].offset = tmp - 1;
|
||||||
}
|
}
|
||||||
@@ -363,5 +406,5 @@ inline std::vector<entryv3> deserialize_directory(const std::string &decompresse
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace pmtiles
|
||||||
#endif
|
#endif
|
||||||
18
cpp/test.cpp
18
cpp/test.cpp
@@ -31,19 +31,19 @@ MU_TEST(test_tileid_to_zxy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MU_TEST(test_zxy_to_tileid) {
|
MU_TEST(test_zxy_to_tileid) {
|
||||||
mu_check(zxy_to_tileid(0,0,0) == 0);
|
mu_check(zxy_to_tileid(0, 0, 0) == 0);
|
||||||
mu_check(zxy_to_tileid(1,0,0) == 1);
|
mu_check(zxy_to_tileid(1, 0, 0) == 1);
|
||||||
mu_check(zxy_to_tileid(1,0,1) == 2);
|
mu_check(zxy_to_tileid(1, 0, 1) == 2);
|
||||||
mu_check(zxy_to_tileid(1,1,1) == 3);
|
mu_check(zxy_to_tileid(1, 1, 1) == 3);
|
||||||
mu_check(zxy_to_tileid(1,1,0) == 4);
|
mu_check(zxy_to_tileid(1, 1, 0) == 4);
|
||||||
mu_check(zxy_to_tileid(2,0,0) == 5);
|
mu_check(zxy_to_tileid(2, 0, 0) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
MU_TEST(test_serialize_directory) {
|
MU_TEST(test_serialize_directory) {
|
||||||
std::vector<entryv3> entries;
|
std::vector<entryv3> entries;
|
||||||
entries.push_back(entryv3(0,0,0,0));
|
entries.push_back(entryv3(0, 0, 0, 0));
|
||||||
entries.push_back(entryv3(1,1,1,1));
|
entries.push_back(entryv3(1, 1, 1, 1));
|
||||||
entries.push_back(entryv3(2,2,2,2));
|
entries.push_back(entryv3(2, 2, 2, 2));
|
||||||
auto serialized = serialize_directory(entries);
|
auto serialized = serialize_directory(entries);
|
||||||
auto result = deserialize_directory(serialized);
|
auto result = deserialize_directory(serialized);
|
||||||
mu_check(result.size() == 3);
|
mu_check(result.size() == 3);
|
||||||
|
|||||||
Reference in New Issue
Block a user