From 6ccb5835ff55d85156be91473c598eca9d6cb9a6 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 4 Nov 2020 16:57:41 +0100 Subject: Revert "Make Lint Happy" This reverts commit ad148587dcf5244c2d2011dba339786c765c54c4. --- src/serialization.cpp | 180 +++++++++++++++++++++++++++----------------------- 1 file changed, 99 insertions(+), 81 deletions(-) (limited to 'src/serialization.cpp') diff --git a/src/serialization.cpp b/src/serialization.cpp index 64d5cefcc..310604f54 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -26,29 +26,29 @@ with this program; if not, write to the Free Software Foundation, Inc., /* report a zlib or i/o error */ void zerr(int ret) { - dstream << "zerr: "; - switch (ret) { - case Z_ERRNO: - if (ferror(stdin)) - dstream << "error reading stdin" << std::endl; - if (ferror(stdout)) - dstream << "error writing stdout" << std::endl; - break; - case Z_STREAM_ERROR: - dstream << "invalid compression level" << std::endl; - break; - case Z_DATA_ERROR: - dstream << "invalid or incomplete deflate data" << std::endl; - break; - case Z_MEM_ERROR: - dstream << "out of memory" << std::endl; - break; - case Z_VERSION_ERROR: - dstream << "zlib version mismatch!" << std::endl; + dstream<<"zerr: "; + switch (ret) { + case Z_ERRNO: + if (ferror(stdin)) + dstream<<"error reading stdin"< &data, std::ostream &os, u8 version) { - if (version >= 11) { - compressZlib(*data, data.getSize(), os); + if(version >= 11) + { + compressZlib(*data ,data.getSize(), os); return; } - if (data.getSize() == 0) + if(data.getSize() == 0) return; // Write length (u32) u8 tmp[4]; writeU32(tmp, data.getSize()); - os.write((char *)tmp, 4); + os.write((char*)tmp, 4); // We will be writing 8-bit pairs of more_count and byte u8 more_count = 0; u8 current_byte = data[0]; - for (u32 i = 1; i < data.getSize(); i++) { - if (data[i] != current_byte || more_count == 255) { + for(u32 i=1; i= 11) { + if(version >= 11) + { decompressZlib(is, os); return; } @@ -236,28 +251,31 @@ void decompress(std::istream &is, std::ostream &os, u8 version) // Read length (u32) u8 tmp[4]; - is.read((char *)tmp, 4); + is.read((char*)tmp, 4); u32 len = readU32(tmp); // We will be reading 8-bit pairs of more_count and byte u32 count = 0; - for (;;) { - u8 more_count = 0; - u8 byte = 0; + for(;;) + { + u8 more_count=0; + u8 byte=0; - is.read((char *)&more_count, 1); + is.read((char*)&more_count, 1); - is.read((char *)&byte, 1); + is.read((char*)&byte, 1); - if (is.eof()) + if(is.eof()) throw SerializationError("decompress: stream ended halfway"); - for (s32 i = 0; i < (u16)more_count + 1; i++) - os.write((char *)&byte, 1); + for(s32 i=0; i<(u16)more_count+1; i++) + os.write((char*)&byte, 1); - count += (u16)more_count + 1; + count += (u16)more_count+1; - if (count == len) + if(count == len) break; } } + + -- cgit v1.2.3