summaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorLars <larsh@apache.org>2020-12-09 14:30:37 -0800
committerlhofhansl <larsh@apache.org>2020-12-15 10:15:25 -0800
commite6380565236d6d963acf75538f1f8fec807190cc (patch)
treed5af32aff7273e13baafbe03a1dec08482d6abaa /src/mapnode.cpp
parentd0a38f694d483fbd9c0554c8d7175a94097fd67e (diff)
downloadminetest-e6380565236d6d963acf75538f1f8fec807190cc.tar.gz
minetest-e6380565236d6d963acf75538f1f8fec807190cc.tar.bz2
minetest-e6380565236d6d963acf75538f1f8fec807190cc.zip
Allow configuring block disk and net compression. Change default disk level.
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index dcf1f6d6e..0551f3b6f 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -706,7 +706,7 @@ void MapNode::deSerialize(u8 *source, u8 version)
}
void MapNode::serializeBulk(std::ostream &os, int version,
const MapNode *nodes, u32 nodecount,
- u8 content_width, u8 params_width, bool compressed)
+ u8 content_width, u8 params_width, int compression_level)
{
if (!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapNode format not supported");
@@ -737,10 +737,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
Compress data to output stream
*/
- if (compressed)
- compressZlib(databuf, databuf_size, os);
- else
- os.write((const char*) &databuf[0], databuf_size);
+ compressZlib(databuf, databuf_size, os, compression_level);
delete [] databuf;
}
@@ -748,7 +745,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
// Deserialize bulk node data
void MapNode::deSerializeBulk(std::istream &is, int version,
MapNode *nodes, u32 nodecount,
- u8 content_width, u8 params_width, bool compressed)
+ u8 content_width, u8 params_width)
{
if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapNode format not supported");
@@ -760,24 +757,13 @@ void MapNode::deSerializeBulk(std::istream &is, int version,
// Uncompress or read data
u32 len = nodecount * (content_width + params_width);
- SharedBuffer<u8> databuf(len);
- if(compressed)
- {
- std::ostringstream os(std::ios_base::binary);
- decompressZlib(is, os);
- std::string s = os.str();
- if(s.size() != len)
- throw SerializationError("deSerializeBulkNodes: "
- "decompress resulted in invalid size");
- memcpy(&databuf[0], s.c_str(), len);
- }
- else
- {
- is.read((char*) &databuf[0], len);
- if(is.eof() || is.fail())
- throw SerializationError("deSerializeBulkNodes: "
- "failed to read bulk node data");
- }
+ std::ostringstream os(std::ios_base::binary);
+ decompressZlib(is, os);
+ std::string s = os.str();
+ if(s.size() != len)
+ throw SerializationError("deSerializeBulkNodes: "
+ "decompress resulted in invalid size");
+ const u8 *databuf = reinterpret_cast<const u8*>(s.c_str());
// Deserialize content
if(content_width == 1)