mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-23 18:40:17 +00:00
Decode Blake-style lists and hashes
This commit is contained in:
parent
bfc211adc7
commit
a5e1153bbd
6
mvt.cpp
6
mvt.cpp
@ -562,7 +562,7 @@ static std::string quote(std::string const &s) {
|
|||||||
|
|
||||||
std::string mvt_value::toString() const {
|
std::string mvt_value::toString() const {
|
||||||
if (type == mvt_string) {
|
if (type == mvt_string) {
|
||||||
return quote(string_value);
|
return std::string("\"") + quote(string_value) + "\"";
|
||||||
} else if (type == mvt_int) {
|
} else if (type == mvt_int) {
|
||||||
return std::to_string(numeric_value.int_value);
|
return std::to_string(numeric_value.int_value);
|
||||||
} else if (type == mvt_double) {
|
} else if (type == mvt_double) {
|
||||||
@ -585,6 +585,8 @@ std::string mvt_value::toString() const {
|
|||||||
return std::to_string(numeric_value.uint_value);
|
return std::to_string(numeric_value.uint_value);
|
||||||
} else if (type == mvt_bool) {
|
} else if (type == mvt_bool) {
|
||||||
return numeric_value.bool_value ? "true" : "false";
|
return numeric_value.bool_value ? "true" : "false";
|
||||||
|
} else if ((type == mvt_list || type == mvt_hash) && string_value.size() > 0) {
|
||||||
|
return string_value;
|
||||||
} else if (type == mvt_null) {
|
} else if (type == mvt_null) {
|
||||||
return "null";
|
return "null";
|
||||||
} else {
|
} else {
|
||||||
@ -982,7 +984,6 @@ mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property,
|
|||||||
if (((property[off] >> 4) & 1) == 0) {
|
if (((property[off] >> 4) & 1) == 0) {
|
||||||
ret.type = mvt_hash;
|
ret.type = mvt_hash;
|
||||||
size_t len = property[off] >> 5;
|
size_t len = property[off] >> 5;
|
||||||
fprintf(stderr, "hash %zu\n", len);
|
|
||||||
off++;
|
off++;
|
||||||
|
|
||||||
ret.string_value = "{";
|
ret.string_value = "{";
|
||||||
@ -1008,7 +1009,6 @@ mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property,
|
|||||||
} else {
|
} else {
|
||||||
ret.type = mvt_list;
|
ret.type = mvt_list;
|
||||||
size_t len = property[off] >> 5;
|
size_t len = property[off] >> 5;
|
||||||
fprintf(stderr, "array %zu\n", len);
|
|
||||||
off++;
|
off++;
|
||||||
|
|
||||||
ret.string_value = "[";
|
ret.string_value = "[";
|
||||||
|
@ -322,39 +322,47 @@ void stringify_val(std::string &out, mvt_feature const &feature, mvt_layer const
|
|||||||
} else if (val.type == mvt_bool) {
|
} else if (val.type == mvt_bool) {
|
||||||
out.append(val.numeric_value.bool_value ? "true" : "false");
|
out.append(val.numeric_value.bool_value ? "true" : "false");
|
||||||
} else if (val.type == mvt_list) {
|
} else if (val.type == mvt_list) {
|
||||||
out.push_back('[');
|
if (val.string_value.size() != 0) {
|
||||||
for (size_t i = 0; i < val.list_value.size(); i++) {
|
out.append(val.string_value);
|
||||||
if (i != 0) {
|
} else {
|
||||||
out.push_back(',');
|
out.push_back('[');
|
||||||
|
for (size_t i = 0; i < val.list_value.size(); i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
out.push_back(',');
|
||||||
|
}
|
||||||
|
if (val.list_value[i] >= vo || val.list_value[i] >= layer.values.size()) {
|
||||||
|
fprintf(stderr, "Invalid value reference in list (%lu from %lu within %lu)\n", val.list_value[i], vo,
|
||||||
|
layer.values.size());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
stringify_val(out, feature, layer, layer.values[val.list_value[i]], val.list_value[i]);
|
||||||
}
|
}
|
||||||
if (val.list_value[i] >= vo || val.list_value[i] >= layer.values.size()) {
|
out.push_back(']');
|
||||||
fprintf(stderr, "Invalid value reference in list (%lu from %lu within %lu)\n", val.list_value[i], vo,
|
|
||||||
layer.values.size());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
stringify_val(out, feature, layer, layer.values[val.list_value[i]], val.list_value[i]);
|
|
||||||
}
|
}
|
||||||
out.push_back(']');
|
|
||||||
} else if (val.type == mvt_hash) {
|
} else if (val.type == mvt_hash) {
|
||||||
out.push_back('{');
|
if (val.string_value.size() != 0) {
|
||||||
for (size_t i = 0; i + 1 < val.list_value.size(); i += 2) {
|
out.append(val.string_value);
|
||||||
if (i != 0) {
|
} else {
|
||||||
out.push_back(',');
|
out.push_back('{');
|
||||||
|
for (size_t i = 0; i + 1 < val.list_value.size(); i += 2) {
|
||||||
|
if (i != 0) {
|
||||||
|
out.push_back(',');
|
||||||
|
}
|
||||||
|
if (val.list_value[i] >= layer.keys.size()) {
|
||||||
|
fprintf(stderr, "Invalid key reference in hash (%lu from %lu within %lu)\n", val.list_value[i], vo, layer.keys.size());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (val.list_value[i + 1] >= vo || val.list_value[i + 1] >= layer.values.size()) {
|
||||||
|
fprintf(stderr, "Invalid value reference in hash (%lu from %lu within %lu)\n", val.list_value[i + 1],
|
||||||
|
vo, layer.values.size());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
quote(out, layer.keys[val.list_value[i]]);
|
||||||
|
out.push_back(':');
|
||||||
|
stringify_val(out, feature, layer, layer.values[val.list_value[i + 1]], val.list_value[i + 1]);
|
||||||
}
|
}
|
||||||
if (val.list_value[i] >= layer.keys.size()) {
|
out.push_back('}');
|
||||||
fprintf(stderr, "Invalid key reference in hash (%lu from %lu within %lu)\n", val.list_value[i], vo, layer.keys.size());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (val.list_value[i + 1] >= vo || val.list_value[i + 1] >= layer.values.size()) {
|
|
||||||
fprintf(stderr, "Invalid value reference in hash (%lu from %lu within %lu)\n", val.list_value[i + 1],
|
|
||||||
vo, layer.values.size());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
quote(out, layer.keys[val.list_value[i]]);
|
|
||||||
out.push_back(':');
|
|
||||||
stringify_val(out, feature, layer, layer.values[val.list_value[i + 1]], val.list_value[i + 1]);
|
|
||||||
}
|
}
|
||||||
out.push_back('}');
|
|
||||||
} else if (val.type == mvt_null) {
|
} else if (val.type == mvt_null) {
|
||||||
out.append("null");
|
out.append("null");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user