Encode null sub-attributes as an empty message, not as their own type

This commit is contained in:
Eric Fischer 2017-06-05 10:48:58 -07:00
parent 98c558190e
commit c1889b74fd
5 changed files with 43 additions and 12 deletions

10
mvt.cpp

@ -115,6 +115,9 @@ bool mvt_tile::decode(std::string &message) {
protozero::pbf_reader value_reader(layer_reader.get_message());
mvt_value value;
value.type = mvt_null;
value.numeric_value.int_value = 0;
while (value_reader.next()) {
switch (value_reader.tag()) {
case 1: /* string */
@ -172,11 +175,6 @@ bool mvt_tile::decode(std::string &message) {
}
break;
case 10: /* null */
value.type = mvt_null;
value.numeric_value.int_value = value_reader.get_int64();
break;
default:
value_reader.skip();
break;
@ -326,7 +324,7 @@ std::string mvt_tile::encode() {
} else if (pbv.type == mvt_list) {
value_writer.add_packed_uint32(9, std::begin(layers[i].values[v].list_value), std::end(layers[i].values[v].list_value));
} else if (pbv.type == mvt_null) {
value_writer.add_int64(10, 0);
; // Don't write anything for null
} else {
fprintf(stderr, "Unknown value type\n");
exit(EXIT_FAILURE);

13
tests/object/in.json Normal file

@ -0,0 +1,13 @@
{ "type": "Feature", "properties": {
"null": null,
"compound": {
"string": "string",
"number": 10,
"null": null,
"true": true,
"false": false,
"array": [
"string", 10, null, true, false
]
}
}, "geometry": { "type": "Point", "coordinates": [ 0,0 ]} }

18
tests/object/out/-z0.json Normal file

@ -0,0 +1,18 @@
{ "type": "FeatureCollection", "properties": {
"bounds": "0.000000,0.000000,0.000000,0.000000",
"center": "0.000000,0.000000,0",
"description": "tests/object/out/-z0.json.check.mbtiles",
"format": "pbf",
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"compound\": \"String\"} } ] }",
"maxzoom": "0",
"minzoom": "0",
"name": "tests/object/out/-z0.json.check.mbtiles",
"type": "overlay",
"version": "2"
}, "features": [
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "compound": {"string":"string","number":10,"null":null,"true":true,"false":false,"array":["string",10,null,true,false]} }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
] }
] }
] }

@ -183,9 +183,12 @@ size_t tag_object(mvt_layer &layer, json_object *j) {
tv.type = mvt_double;
tv.numeric_value.double_value = atof(j->string);
}
} else if (j->type == JSON_TRUE || j->type == JSON_FALSE) {
} else if (j->type == JSON_TRUE) {
tv.type = mvt_bool;
tv.numeric_value.bool_value = (j->string[0] == 't');
tv.numeric_value.bool_value = 1;
} else if (j->type == JSON_FALSE) {
tv.type = mvt_bool;
tv.numeric_value.bool_value = 0;
} else if (j->type == JSON_STRING) {
tv.type = mvt_string;
tv.string_value = std::string(j->string);

@ -15,6 +15,8 @@ message tile {
// Variant type encoding
message value {
// Exactly one of these values may be present in a valid message
// If no value is written, the message is null.
optional string string_value = 1;
optional float float_value = 2;
optional double double_value = 3;
@ -30,10 +32,7 @@ message tile {
// Each element refers to the nth value in the layer's values list
repeated uint32 list_value = 9 [ packed = true ];
// The actual number written is unused; any value counts as a null value
optional int64 null_value = 10;
extensions 11 to max;
extensions 10 to max;
}
message feature {