From 5166cfb9b70f21b16193315cbdee69a507371a13 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 12 Aug 2015 14:13:22 +0200 Subject: Implement basic stream_writer methods --- src/io/stream_writer.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/io/stream_writer.cpp') diff --git a/src/io/stream_writer.cpp b/src/io/stream_writer.cpp index dd90c83322..26a6a7eb65 100644 --- a/src/io/stream_writer.cpp +++ b/src/io/stream_writer.cpp @@ -18,13 +18,29 @@ * along with libnbt++. If not, see . */ #include "io/stream_writer.h" +#include namespace nbt { namespace io { +void stream_writer::write_type(tag_type tt) +{ + write_num(static_cast(tt)); +} +void stream_writer::write_string(const std::string& str) +{ + if(str.size() > max_string_len) + { + std::ostringstream sstr; + sstr << "String is too long for NBT (" << str.size() << " > " << max_string_len << ")"; + throw std::length_error(sstr.str()); + } + write_num(static_cast(str.size())); + os.write(str.data(), str.size()); +} } } -- cgit 0.0.5-2-1-g0f52