Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
serialization.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irrlichttypes.h"
8#include "exceptions.h"
9#include <iostream>
10#include <string_view>
11
12/*
13 Map format serialization version
14 --------------------------------
15
16 For map data (blocks, nodes, sectors).
17
18 NOTE: The goal is to increment this so that saved maps will be
19 loadable by any version. Other compatibility is not
20 maintained.
21
22 0: original networked test with 1-byte nodes
23 1: update with 2-byte nodes
24 2: lighting is transmitted in param
25 3: optional fetching of far blocks
26 4: block compression
27 5: sector objects NOTE: block compression was left accidentally out
28 6: failed attempt at switching block compression on again
29 7: block compression switched on again
30 8: server-initiated block transfers and all kinds of stuff
31 9: block objects
32 10: water pressure
33 11: zlib'd blocks, block flags
34 12: UnlimitedHeightmap now uses interpolated areas
35 13: Mapgen v2
36 14: NodeMetadata
37 15: StaticObjects
38 16: larger maximum size of node metadata, and compression
39 17: MapBlocks contain timestamp
40 18: new generator (not really necessary, but it's there)
41 19: new content type handling
42 20: many existing content types translated to extended ones
43 21: dynamic content type allocation
44 22: minerals removed, facedir & wallmounted changed
45 23: new node metadata format
46 24: 16-bit node ids and node timers (never released as stable)
47 25: Improved node timer format
48 26: Never written; read the same as 25
49 27: Added light spreading flags to blocks
50 28: Added "private" flag to NodeMetadata
51 29: Switched compression to zstd, a bit of reorganization
52*/
53
54// This represents an uninitialized or invalid format
55constexpr u8 SER_FMT_VER_INVALID = 255;
56// Highest supported serialization version
57constexpr u8 SER_FMT_VER_HIGHEST_READ = 29;
58// Saved on disk version
59constexpr u8 SER_FMT_VER_HIGHEST_WRITE = 29;
60// Lowest supported serialization version
61constexpr u8 SER_FMT_VER_LOWEST_READ = 0;
62// Lowest serialization version for writing
63// Can't do < 24 anymore; we have 16-bit dynamically allocated node IDs
64// in memory; conversion just won't work in this direction.
65constexpr u8 SER_FMT_VER_LOWEST_WRITE = 24;
66
67inline bool ser_ver_supported_read(s32 v)
68{
70}
71
72inline bool ser_ver_supported_write(s32 v)
73{
75}
76
77/*
78 Compression functions
79*/
80
81void compressZlib(const u8 *data, size_t data_size, std::ostream &os, int level = -1);
82inline void compressZlib(std::string_view data, std::ostream &os, int level = -1)
83{
84 compressZlib(reinterpret_cast<const u8*>(data.data()), data.size(), os, level);
85}
86void decompressZlib(std::istream &is, std::ostream &os, size_t limit = 0);
87
88void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level = 0);
89inline void compressZstd(std::string_view data, std::ostream &os, int level = 0)
90{
91 compressZstd(reinterpret_cast<const u8*>(data.data()), data.size(), os, level);
92}
93void decompressZstd(std::istream &is, std::ostream &os);
94
95// These choose between zstd, zlib and a self-made one according to version
96void compress(const u8 *data, u32 size, std::ostream &os, u8 version, int level = -1);
97inline void compress(std::string_view data, std::ostream &os, u8 version, int level = -1)
98{
99 compress(reinterpret_cast<const u8*>(data.data()), data.size(), os, version, level);
100}
101void decompress(std::istream &is, std::ostream &os, u8 version);
void compress(const u8 *data, u32 size, std::ostream &os, u8 version, int level=-1)
Definition serialization.cpp:275
bool ser_ver_supported_read(s32 v)
Definition serialization.h:67
bool ser_ver_supported_write(s32 v)
Definition serialization.h:72
void decompressZlib(std::istream &is, std::ostream &os, size_t limit=0)
Definition serialization.cpp:95
constexpr u8 SER_FMT_VER_HIGHEST_WRITE
Definition serialization.h:59
void compressZlib(const u8 *data, size_t data_size, std::ostream &os, int level=-1)
Definition serialization.cpp:52
void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level=0)
Definition serialization.cpp:189
void decompressZstd(std::istream &is, std::ostream &os)
Definition serialization.cpp:230
constexpr u8 SER_FMT_VER_LOWEST_WRITE
Definition serialization.h:65
constexpr u8 SER_FMT_VER_INVALID
Definition serialization.h:55
constexpr u8 SER_FMT_VER_HIGHEST_READ
Definition serialization.h:57
void decompress(std::istream &is, std::ostream &os, u8 version)
Definition serialization.cpp:325
constexpr u8 SER_FMT_VER_LOWEST_READ
Definition serialization.h:61