nbt_io.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. libnbt++ - A library for the Minecraft Named Binary Tag format.
  3. Copyright (C) 2013 ljfa-ag
  4. This file is part of libnbt++.
  5. libnbt++ 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 3 of the License, or
  8. (at your option) any later version.
  9. libnbt++ is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef NBT_IO_H_INCLUDED
  17. #define NBT_IO_H_INCLUDED
  18. #include "tag_base.h"
  19. #include "nbt_conf.h"
  20. #include <memory>
  21. namespace nbt
  22. {
  23. ///Stream input and output of binary NBT data
  24. namespace io
  25. {
  26. /**
  27. * \brief Reads a named tag in uncompressed NBT format from stream.
  28. * \param is The stream to read from.
  29. * \param[out] key A string object to read the name into.
  30. * \return A \c unique_ptr to the tag object.
  31. * \throw input_error if an error occurs while reading, i.e. end of file or a syntax error
  32. * \sa read_gzip()
  33. */
  34. std::unique_ptr<tag> read(std::istream& is, std::string& key);
  35. /**
  36. * \brief Writes a named tag in uncompressed NBT format into stream.
  37. * \param os The stream to write the data to.
  38. * \param key The key of the root tag.
  39. * \param t The tag to write. Should be a tag_compound.
  40. * \sa write_gzip()
  41. */
  42. void write(std::ostream& os, const std::string& key, const tag& t);
  43. #ifdef NBT_WITH_GZIP
  44. /**
  45. * \brief Reads a named tag in GZip-compressed NBT format from stream.
  46. * \param is The stream to read from.
  47. * \param[out] key A string object to read the name into.
  48. * \return A \c unique_ptr to the tag object.
  49. * \throw input_error if an error occurs while reading, i.e. end of file or a syntax error
  50. * \sa read()
  51. */
  52. std::unique_ptr<tag> read_gzip(std::istream& is, std::string& key);
  53. /**
  54. * \brief Writes a named tag in GZip-compressed NBT format into stream.
  55. * \param os The stream to write the compressed data to.
  56. * \param key The key of the root tag.
  57. * \param t The tag to write. Should be a tag_compound.
  58. * \param compression_level The GZip compression level. Must be a number between 0 and 9:
  59. * 0 gives no compression, 1 wekaest and 9 strongest compression.
  60. * \sa write()
  61. */
  62. void write_gzip(std::ostream& os, const std::string& key, const tag& t, int compression_level = -1);
  63. #endif
  64. }
  65. }
  66. #endif // NBT_IO_H_INCLUDED