summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-08-12 14:13:22 +0200
committerljfa-ag <ljfa-ag@web.de>2015-08-12 14:13:22 +0200
commit5166cfb9b70f21b16193315cbdee69a507371a13 (patch)
tree2e6d7c00501563764ac277cacf11be47daa474dc /include
parent2f0bf929fcecc47c5a5d2b3f151d8f187fb5d7f9 (diff)
downloadProject-Tick-5166cfb9b70f21b16193315cbdee69a507371a13.tar.gz
Project-Tick-5166cfb9b70f21b16193315cbdee69a507371a13.zip
Implement basic stream_writer methods
Diffstat (limited to 'include')
-rw-r--r--include/io/stream_writer.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/include/io/stream_writer.h b/include/io/stream_writer.h
index ea3dcd1c58..78d02cb2cc 100644
--- a/include/io/stream_writer.h
+++ b/include/io/stream_writer.h
@@ -42,17 +42,22 @@ class output_error : public std::runtime_error
class stream_writer
{
public:
+ ///Maximum length of an NBT string (65535)
+ static constexpr size_t max_string_len = UINT16_MAX;
+
/**
* @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
*/
- explicit stream_writer(std::ostream& os, endian::endian e = endian::big) noexcept;
+ explicit stream_writer(std::ostream& os, endian::endian e = endian::big) noexcept:
+ os(os), endian(e)
+ {}
///Returns the stream
- std::ostream& get_ostr() const;
+ std::ostream& get_ostr() const { return os; }
///Returns the byte order
- endian::endian get_endian() const;
+ endian::endian get_endian() const { return endian; }
/**
* @brief Writes a tag type to the stream
@@ -70,6 +75,7 @@ public:
*
* An NBT string consists of two bytes indicating the length, followed by
* the characters encoded in modified UTF-8.
+ * @throw std::length_error if the string is too long for NBT
*/
void write_string(const std::string& str);