X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fserialization.cpp;h=118bad467c91e880a3a1cecb0e9ed77dd678c65c;hb=5a34f40d80ea1a339b599bc11db549a6bd86912f;hp=57db2b40f6c319133b99b2bb12964a909117ca00;hpb=fc26dcdb19dd4e296d850714019ed7da1de0b021;p=minetest.git diff --git a/src/serialization.cpp b/src/serialization.cpp index 57db2b40f..118bad467 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -1,34 +1,201 @@ /* -Minetest-c55 -Copyright (C) 2010 celeron55, Perttu Ahola +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/* -(c) 2010 Perttu Ahola -*/ - #include "serialization.h" -#include "utility.h" + +#include "util/serialize.h" +#ifdef _WIN32 + #define ZLIB_WINAPI +#endif +#include "zlib.h" + +/* 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"< databuf((u8*)data.c_str(), data.size()); + compressZlib(databuf, os); +} + +void decompressZlib(std::istream &is, std::ostream &os) +{ + z_stream z; + const s32 bufsize = 16384; + char input_buffer[bufsize]; + char output_buffer[bufsize]; + int status = 0; + int ret; + int bytes_read = 0; + int input_buffer_len = 0; + + z.zalloc = Z_NULL; + z.zfree = Z_NULL; + z.opaque = Z_NULL; + + ret = inflateInit(&z); + if(ret != Z_OK) + throw SerializationError("dcompressZlib: inflateInit failed"); + + z.avail_in = 0; + + //dstream<<"initial fail="< data, std::ostream &os, u8 version) { - if(data.getSize() == 0) + if(version >= 11) + { + compressZlib(data, os); return; + } + if(data.getSize() == 0) + return; + // Write length (u32) u8 tmp[4]; @@ -63,6 +230,12 @@ void compress(SharedBuffer data, std::ostream &os, u8 version) void decompress(std::istream &is, std::ostream &os, u8 version) { + if(version >= 11) + { + decompressZlib(is, os); + return; + } + // Read length (u32) u8 tmp[4];