aboutsummaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorlhofhansl <larsh@apache.org>2021-08-31 17:32:31 -0700
committerGitHub <noreply@github.com>2021-08-31 17:32:31 -0700
commitd1624a552151bcb152b7abf63df6501b63458d78 (patch)
treee73a7b216f23962c06e591c4d0d1e5333d949b08 /src/mapnode.cpp
parentbeac4a2c984706b636e7b1e03406e05c87435903 (diff)
downloadhax-minetest-server-d1624a552151bcb152b7abf63df6501b63458d78.tar.gz
hax-minetest-server-d1624a552151bcb152b7abf63df6501b63458d78.zip
Switch MapBlock compression to zstd (#10788)
* Add zstd support. * Rearrange serialization order * Compress entire mapblock Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index f212ea8c9..73bd620fb 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -730,9 +730,10 @@ void MapNode::deSerialize(u8 *source, u8 version)
}
}
}
-void MapNode::serializeBulk(std::ostream &os, int version,
+
+SharedBuffer<u8> MapNode::serializeBulk(int version,
const MapNode *nodes, u32 nodecount,
- u8 content_width, u8 params_width, int compression_level)
+ u8 content_width, u8 params_width)
{
if (!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapNode format not supported");
@@ -746,8 +747,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
throw SerializationError("MapNode::serializeBulk: serialization to "
"version < 24 not possible");
- size_t databuf_size = nodecount * (content_width + params_width);
- u8 *databuf = new u8[databuf_size];
+ SharedBuffer<u8> databuf(nodecount * (content_width + params_width));
u32 start1 = content_width * nodecount;
u32 start2 = (content_width + 1) * nodecount;
@@ -758,14 +758,7 @@ void MapNode::serializeBulk(std::ostream &os, int version,
writeU8(&databuf[start1 + i], nodes[i].param1);
writeU8(&databuf[start2 + i], nodes[i].param2);
}
-
- /*
- Compress data to output stream
- */
-
- compressZlib(databuf, databuf_size, os, compression_level);
-
- delete [] databuf;
+ return databuf;
}
// Deserialize bulk node data
@@ -781,15 +774,10 @@ void MapNode::deSerializeBulk(std::istream &is, int version,
|| params_width != 2)
FATAL_ERROR("Deserialize bulk node data error");
- // Uncompress or read data
- u32 len = nodecount * (content_width + params_width);
- 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());
+ // read data
+ const u32 len = nodecount * (content_width + params_width);
+ Buffer<u8> databuf(len);
+ is.read(reinterpret_cast<char*>(*databuf), len);
// Deserialize content
if(content_width == 1)