Luanti 5.10.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// This represents an uninitialized or invalid format
54#define SER_FMT_VER_INVALID 255
55// Highest supported serialization version
56#define SER_FMT_VER_HIGHEST_READ 29
57// Saved on disk version
58#define SER_FMT_VER_HIGHEST_WRITE 29
59// Lowest supported serialization version
60#define SER_FMT_VER_LOWEST_READ 0
61// Lowest serialization version for writing
62// Can't do < 24 anymore; we have 16-bit dynamically allocated node IDs
63// in memory; conversion just won't work in this direction.
64#define SER_FMT_VER_LOWEST_WRITE 24
65
66inline bool ser_ver_supported(s32 v) {
68}
69
70/*
71 Compression functions
72*/
73
74void compressZlib(const u8 *data, size_t data_size, std::ostream &os, int level = -1);
75inline void compressZlib(std::string_view data, std::ostream &os, int level = -1)
76{
77 compressZlib(reinterpret_cast<const u8*>(data.data()), data.size(), os, level);
78}
79void decompressZlib(std::istream &is, std::ostream &os, size_t limit = 0);
80
81void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level = 0);
82inline void compressZstd(std::string_view data, std::ostream &os, int level = 0)
83{
84 compressZstd(reinterpret_cast<const u8*>(data.data()), data.size(), os, level);
85}
86void decompressZstd(std::istream &is, std::ostream &os);
87
88// These choose between zstd, zlib and a self-made one according to version
89void compress(const u8 *data, u32 size, std::ostream &os, u8 version, int level = -1);
90inline void compress(std::string_view data, std::ostream &os, u8 version, int level = -1)
91{
92 compress(reinterpret_cast<const u8*>(data.data()), data.size(), os, version, level);
93}
94void 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
void decompressZlib(std::istream &is, std::ostream &os, size_t limit=0)
Definition serialization.cpp:95
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
bool ser_ver_supported(s32 v)
Definition serialization.h:66
void decompressZstd(std::istream &is, std::ostream &os)
Definition serialization.cpp:230
#define SER_FMT_VER_HIGHEST_READ
Definition serialization.h:56
void decompress(std::istream &is, std::ostream &os, u8 version)
Definition serialization.cpp:325
#define SER_FMT_VER_LOWEST_READ
Definition serialization.h:60