From aac94b91ad83ad8f7832976e6da55d15de6e54e1 Mon Sep 17 00:00:00 2001 From: ljfa Date: Thu, 13 Aug 2015 11:31:57 +0200 Subject: Add io::read_tag and write_tag functions --- include/io/stream_reader.h | 20 ++++++++++++++++++++ include/io/stream_writer.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) (limited to 'include') diff --git a/include/io/stream_reader.h b/include/io/stream_reader.h index 926d2453c6..877f6498ed 100644 --- a/include/io/stream_reader.h +++ b/include/io/stream_reader.h @@ -39,8 +39,28 @@ class input_error : public std::runtime_error using std::runtime_error::runtime_error; }; +/** +* @brief Reads a named tag from the stream, making sure that it is a compound +* @param is the stream to read from +* @param e the byte order of the source data. The Java edition +* of Minecraft uses Big Endian, the Pocket edition uses Little Endian +* @throw input_error on failure, or if the tag in the stream is not a compound +*/ +std::pair> read_compound(std::istream& is, endian::endian e = endian::big); + +/** +* @brief Reads a named tag from the stream +* @param is the stream to read from +* @param e the byte order of the source data. The Java edition +* of Minecraft uses Big Endian, the Pocket edition uses Little Endian +* @throw input_error on failure +*/ +std::pair> read_tag(std::istream& is, endian::endian e = endian::big); + /** * @brief Helper class for reading NBT tags from input streams + * + * Can be reused to read multiple tags */ class stream_reader { diff --git a/include/io/stream_writer.h b/include/io/stream_writer.h index c94a7d4ece..c771426bb3 100644 --- a/include/io/stream_writer.h +++ b/include/io/stream_writer.h @@ -36,8 +36,20 @@ class output_error : public std::runtime_error using std::runtime_error::runtime_error; };*/ +/** +* @brief Writes a named tag into the stream, including the tag type +* @param key the name of the tag +* @param t the tag +* @param os the stream to write to +* @param e the byte order of the written data. The Java edition +* of Minecraft uses Big Endian, the Pocket edition uses Little Endian +*/ +void write_tag(const std::string& key, const tag& t, std::ostream& os, endian::endian e = endian::big); + /** * @brief Helper class for writing NBT tags to output streams + * + * Can be reused to write multiple tags */ class stream_writer { -- cgit 0.0.5-2-1-g0f52