move pbf parsing to use exceptions

This commit is contained in:
Konstantin Käfer
2014-01-21 16:30:28 +01:00
parent 474fb42807
commit a637ad5473
2 changed files with 102 additions and 162 deletions

View File

@@ -85,24 +85,22 @@ bool Tile::parse() {
// fprintf(stderr, "[%p] parsing tile [%d/%d/%d]...\n", this, z, x, y);
pbf tile(data, bytes);
int code = setjmp(tile.jump_buffer);
if (code > 0) {
fprintf(stderr, "[%p] parsing tile [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, tile.msg.c_str());
try {
while (tile.next()) {
if (tile.tag == 3) { // layer
uint32_t bytes = (uint32_t)tile.varint();
parseLayer(tile.data, bytes);
tile.skipBytes(bytes);
} else {
tile.skip();
}
}
} catch(const pbf::exception& ex) {
fprintf(stderr, "[%p] parsing tile [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what());
cancel();
return false;
}
while (tile.next()) {
if (tile.tag == 3) { // layer
uint32_t bytes = (uint32_t)tile.varint();
parseLayer(tile.data, bytes);
tile.skipBytes(bytes);
} else {
tile.skip();
}
}
if (state == obsolete) {
return false;
} else {