From fb7d87145c5ba167b00be9e873b0e1ac136aae3f Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Thu, 26 Jan 2023 22:08:29 -0800 Subject: [PATCH] Remove unused code from the other day --- serial.cpp | 147 ----------------------------------------------------- 1 file changed, 147 deletions(-) diff --git a/serial.cpp b/serial.cpp index c3193b17..a07be331 100644 --- a/serial.cpp +++ b/serial.cpp @@ -24,114 +24,6 @@ #include "milo/dtoa_milo.h" #include "errors.hpp" -struct zwriter { - z_stream zstream; - std::string buf; - std::string zbuf; - FILE *fp; - - zwriter(FILE *out) { - zstream.zalloc = NULL; - zstream.zfree = NULL; - zstream.opaque = NULL; - if (deflateInit(&zstream, Z_DEFAULT_COMPRESSION) != Z_OK) { - fprintf(stderr, "Compression initialization failed\n"); - exit(EXIT_MEMORY); - } - - zbuf.resize(5000); - fp = out; - } - - int fwrite_check(const void *p, size_t size, size_t nmemb, bool flush, std::atomic *fpos, const char *fname) { - buf += std::string((char *) p, size * nmemb); - bool again = false; - - while (buf.size() != 0 || again) { - again = false; - - zstream.next_in = (Bytef *) buf.c_str(); - zstream.avail_in = buf.size(); - - zstream.next_out = (Bytef *) zbuf.c_str(); - zstream.avail_out = zbuf.size(); - - int d = deflate(&zstream, flush ? Z_FULL_FLUSH : Z_NO_FLUSH); - - if (zstream.next_in != (Bytef *) buf.c_str()) { - // it consumed some input - - ssize_t consumed = zstream.next_in - (Bytef *) buf.c_str(); - buf.erase(buf.begin(), buf.begin() + consumed); - } - - if (zstream.next_out != (Bytef *) zbuf.c_str()) { - // it produced some output - - ssize_t produced = zstream.next_out - (Bytef *) zbuf.c_str(); - ::fwrite_check((void *) zbuf.c_str(), sizeof(char), produced, fp, fpos, fname); - } - - if (d == Z_BUF_ERROR) { - zbuf.resize(zbuf.size() + 5000); - again = true; - } else if (d != Z_OK) { - fprintf(stderr, "impossible return %d from deflate() in fclose()\n", d); - exit(EXIT_IMPOSSIBLE); - } - - if (zstream.avail_out == 0) { - again = true; - } - } - - return nmemb; - } - - int putc(int c, std::atomic *fpos, const char *fname) { - char ch = c; - return fwrite_check(&ch, sizeof(char), 1, false, fpos, fname); - } - - int fclose(std::atomic *fpos, const char *fname) { - while (true) { - zstream.next_in = (Bytef *) buf.c_str(); - zstream.avail_in = 0; - - zstream.next_out = (Bytef *) zbuf.c_str(); - zstream.avail_out = zbuf.size(); - - int d = deflate(&zstream, Z_FINISH); - - if (zstream.next_out != (Bytef *) zbuf.c_str()) { - // it produced some output - - ssize_t produced = zstream.next_out - (Bytef *) zbuf.c_str(); - ::fwrite_check((void *) zbuf.c_str(), sizeof(char), produced, fp, fpos, fname); - } - - if (d == Z_BUF_ERROR || d == Z_OK) { - // still more to be written - zbuf.resize(zbuf.size() + 5000); - continue; - } else if (d == Z_STREAM_END) { - // done - break; - } else { - fprintf(stderr, "impossible return %d from deflate()\n", d); - exit(EXIT_IMPOSSIBLE); - } - } - - if (deflateEnd(&zstream) != Z_OK) { - fprintf(stderr, "Error closing compression scheme (%s)\n", zstream.msg); - exit(EXIT_WRITE); - } - - return ::fclose(fp); - } -}; - // Offset coordinates to keep them positive #define COORD_OFFSET (4LL << 32) #define SHIFT_RIGHT(a) ((((a) + COORD_OFFSET) >> geometry_scale) - (COORD_OFFSET >> geometry_scale)) @@ -189,45 +81,6 @@ void serialize_uint(FILE *out, unsigned n, std::atomic *fpos, const c serialize_ulong_long(out, n, fpos, fname); } -// write to compression - -size_t fwrite_check(const void *ptr, size_t size, size_t nitems, zwriter *stream, std::atomic *fpos, const char *fname) { - size_t w = stream->fwrite_check(ptr, size, nitems, false, fpos, fname); - return w; -} - -void serialize_ulong_long(zwriter *out, unsigned long long zigzag, std::atomic *fpos, const char *fname) { - while (1) { - unsigned char b = zigzag & 0x7F; - if ((zigzag >> 7) != 0) { - b |= 0x80; - out->putc(b, fpos, fname); - zigzag >>= 7; - } else { - out->putc(b, fpos, fname); - break; - } - } -} - -void serialize_long_long(zwriter *out, long long n, std::atomic *fpos, const char *fname) { - unsigned long long zigzag = protozero::encode_zigzag64(n); - - serialize_ulong_long(out, zigzag, fpos, fname); -} - -void serialize_int(zwriter *out, int n, std::atomic *fpos, const char *fname) { - serialize_long_long(out, n, fpos, fname); -} - -void serialize_byte(zwriter *out, signed char n, std::atomic *fpos, const char *fname) { - out->fwrite_check(&n, sizeof(signed char), 1, false, fpos, fname); -} - -void serialize_uint(zwriter *out, unsigned n, std::atomic *fpos, const char *fname) { - serialize_ulong_long(out, n, fpos, fname); -} - // write to memory size_t fwrite_check(const void *ptr, size_t size, size_t nitems, std::string &stream) {