fed5bb5223fb77a923e675dd2a0c96bf1a1ab23d
[oweals/minetest.git] / src / serialization.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef SERIALIZATION_HEADER
21 #define SERIALIZATION_HEADER
22
23 #include "common_irrlicht.h"
24 #include "exceptions.h"
25 #include <iostream>
26 #include "utility.h"
27
28 /*
29         NOTE: The goal is to increment this so that saved maps will be
30               loadable by any version. Other compatibility is not
31                   maintained.
32         Serialization format versions:
33         == Unsupported ==
34         0: original networked test with 1-byte nodes
35         1: update with 2-byte nodes
36         == Supported ==
37         2: lighting is transmitted in param
38         3: optional fetching of far blocks
39         4: block compression
40         5: sector objects NOTE: block compression was left accidentally out
41         6: failed attempt at switching block compression on again
42         7: block compression switched on again
43         8: (dev) server-initiated block transfers and all kinds of stuff
44         9: (dev) block objects
45         10: (dev) water pressure
46         11: (dev) zlib'd blocks, block flags
47         12: (dev) UnlimitedHeightmap now uses interpolated areas
48         13: (dev) Mapgen v2
49         14: (dev) NodeMetadata
50 */
51 // This represents an uninitialized or invalid format
52 #define SER_FMT_VER_INVALID 255
53 // Highest supported serialization version
54 #define SER_FMT_VER_HIGHEST 14
55 // Lowest supported serialization version
56 #define SER_FMT_VER_LOWEST 2
57
58 #define ser_ver_supported(v) (v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST)
59
60 void compress(SharedBuffer<u8> data, std::ostream &os, u8 version);
61 void decompress(std::istream &is, std::ostream &os, u8 version);
62
63 /*class Serializable
64 {
65 public:
66         void serialize(std::ostream &os, u8 version) = 0;
67         void deSerialize(std::istream &istr);
68 };*/
69
70 #endif
71