serialization.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef SERIALIZATION_HEADER
  17. #define SERIALIZATION_HEADER
  18. #include "irrlichttypes.h"
  19. #include "exceptions.h"
  20. #include <iostream>
  21. #include "util/pointer.h"
  22. /*
  23. Map format serialization version
  24. --------------------------------
  25. For map data (blocks, nodes, sectors).
  26. NOTE: The goal is to increment this so that saved maps will be
  27. loadable by any version. Other compatibility is not
  28. maintained.
  29. 0: original networked test with 1-byte nodes
  30. 1: update with 2-byte nodes
  31. 2: lighting is transmitted in param
  32. 3: optional fetching of far blocks
  33. 4: block compression
  34. 5: sector objects NOTE: block compression was left accidentally out
  35. 6: failed attempt at switching block compression on again
  36. 7: block compression switched on again
  37. 8: server-initiated block transfers and all kinds of stuff
  38. 9: block objects
  39. 10: water pressure
  40. 11: zlib'd blocks, block flags
  41. 12: UnlimitedHeightmap now uses interpolated areas
  42. 13: Mapgen v2
  43. 14: NodeMetadata
  44. 15: StaticObjects
  45. 16: larger maximum size of node metadata, and compression
  46. 17: MapBlocks contain timestamp
  47. 18: new generator (not really necessary, but it's there)
  48. 19: new content type handling
  49. 20: many existing content types translated to extended ones
  50. 21: dynamic content type allocation
  51. 22: minerals removed, facedir & wallmounted changed
  52. 23: new node metadata format
  53. 24: 16-bit node ids and node timers (never released as stable)
  54. 25: Improved node timer format
  55. 26: Never written; read the same as 25
  56. */
  57. // This represents an uninitialized or invalid format
  58. #define SER_FMT_VER_INVALID 255
  59. // Highest supported serialization version
  60. #define SER_FMT_VER_HIGHEST_READ 26
  61. // Saved on disk version
  62. #define SER_FMT_VER_HIGHEST_WRITE 25
  63. // Lowest supported serialization version
  64. #define SER_FMT_VER_LOWEST 0
  65. #define ser_ver_supported(v) (v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST_READ)
  66. /*
  67. Misc. serialization functions
  68. */
  69. void compressZlib(SharedBuffer<u8> data, std::ostream &os, int level = -1);
  70. void compressZlib(const std::string &data, std::ostream &os, int level = -1);
  71. void decompressZlib(std::istream &is, std::ostream &os);
  72. // These choose between zlib and a self-made one according to version
  73. void compress(SharedBuffer<u8> data, std::ostream &os, u8 version);
  74. //void compress(const std::string &data, std::ostream &os, u8 version);
  75. void decompress(std::istream &is, std::ostream &os, u8 version);
  76. #endif