From f5366eb767a0c1c5e6c40f1933bbfc616205fe7c Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 30 Jan 2023 14:45:48 -0800 Subject: [PATCH] Works until we get to concatenated tiles --- tile.cpp | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/tile.cpp b/tile.cpp index ba400a52..11053c78 100644 --- a/tile.cpp +++ b/tile.cpp @@ -67,6 +67,7 @@ struct decompressor { void begin() { within = true; + printf("------- BEGIN\n"); zs.zalloc = NULL; zs.zfree = NULL; @@ -83,16 +84,6 @@ struct decompressor { zs.avail_out = 0; } - void end() { - within = false; - - int d = inflateEnd(&zs); - if (d != Z_OK) { - fprintf(stderr, "end decompression: %d %s\n", d, zs.msg); - exit(EXIT_IMPOSSIBLE); - } - } - int fread(void *p, size_t size, size_t nmemb, std::atomic *geompos) { zs.next_out = (Bytef *) p; zs.avail_out = size * nmemb; @@ -124,6 +115,7 @@ struct decompressor { if (d == Z_OK) { // it made some progress } else if (d == Z_STREAM_END) { + printf("-------------- EOS\n"); // it may have made some progress and now we are done break; } else { @@ -147,6 +139,26 @@ struct decompressor { return (size * nmemb - zs.avail_out) / size; } + void end(std::atomic *geompos) { +#if 0 + // consume the trailer of the compressed stream + char s[20]; + int n; + while ((n = fread(s, sizeof(char), 20, geompos)) != 0) { + printf("read extra %d\n", n); + } +#endif + + within = false; + printf("------- END\n"); + + int d = inflateEnd(&zs); + if (d != Z_OK) { + fprintf(stderr, "end decompression: %d %s\n", d, zs.msg); + exit(EXIT_IMPOSSIBLE); + } + } + int deserialize_ulong_long(unsigned long long *zigzag, std::atomic *geompos) { *zigzag = 0; int shift = 0; @@ -1682,16 +1694,18 @@ serial_feature next_feature(decompressor *geoms, std::atomic *geompos long long len; if (geoms->deserialize_long_long(&len, geompos_in) == 0) { + printf("------ <<<<<< deserialization failure, end of tile\n"); if (z != 0) { - geoms->end(); + geoms->end(geompos_in); } sf.t = -2; return sf; } if (len == 0) { + printf("------ <<<<<< feature len 0, end of tile\n"); if (z != 0) { - geoms->end(); + geoms->end(geompos_in); } sf.t = -2; @@ -2193,7 +2207,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch if (*geompos_in != og) { if (z != 0) { - geoms->end(); + geoms->end(geompos_in); geoms->begin(); } @@ -2683,7 +2697,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch int j; for (j = 0; j < child_shards; j++) { if (within[j]) { - geomfile[j]->serialize_ulong_long(0, &geompos[j], fname); // EOF + geomfile[j]->serialize_long_long(0, &geompos[j], fname); // EOF geomfile[j]->end(&geompos[j], fname); within[j] = 0; } @@ -3117,12 +3131,13 @@ void *run_thread(void *vargs) { if (!deserialize_int_io(geom, &z, &geompos)) { break; } + deserialize_uint_io(geom, &x, &geompos); + deserialize_uint_io(geom, &y, &geompos); + printf("------- %d/%d/%d\n", z, x, y); if (z != arg->zoom) { fprintf(stderr, "Expected zoom %d, found zoom %d\n", arg->zoom, z); exit(EXIT_IMPOSSIBLE); } - deserialize_uint_io(geom, &x, &geompos); - deserialize_uint_io(geom, &y, &geompos); if (z != 0) { dc.begin();