summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-08-05 14:37:07 +0200
committerljfa-ag <ljfa-ag@web.de>2015-08-05 14:37:07 +0200
commit7f2dc607b7ba1192feeae00f4aeff50385e097ae (patch)
tree388d5c3d5bdd1c877c73fb9a6d44ad3e1b540a4f
parent51553817630748b1f8ca342db59b0834032222cb (diff)
downloadProject-Tick-7f2dc607b7ba1192feeae00f4aeff50385e097ae.tar.gz
Project-Tick-7f2dc607b7ba1192feeae00f4aeff50385e097ae.zip
Make tag_list::read_payload handle lists of tag_end
-rw-r--r--include/tag.h5
-rw-r--r--include/tag_list.h4
-rw-r--r--src/tag_list.cpp18
3 files changed, 21 insertions, 6 deletions
diff --git a/include/tag.h b/include/tag.h
index 4b547e013c..58b99c082c 100644
--- a/include/tag.h
+++ b/include/tag.h
@@ -76,7 +76,10 @@ public:
*/
virtual tag& assign(tag&& rhs) = 0;
- ///Reads the tag's payload from the stream
+ /**
+ * @brief Reads the tag's payload from the stream
+ * @throw io::stream_reader::input_error on failure
+ */
virtual void read_payload(io::stream_reader& reader) = 0;
/**
diff --git a/include/tag_list.h b/include/tag_list.h
index 324d2de6d8..dff89c4fcc 100644
--- a/include/tag_list.h
+++ b/include/tag_list.h
@@ -158,6 +158,10 @@ public:
const_iterator cbegin() const;
const_iterator cend() const;
+ /**
+ * @inheritdoc
+ * In case of a list of tag_end, the content type will be undetermined.
+ */
void read_payload(io::stream_reader& reader) override;
/**
diff --git a/src/tag_list.cpp b/src/tag_list.cpp
index c5d9eb5901..3bcc42e8b6 100644
--- a/src/tag_list.cpp
+++ b/src/tag_list.cpp
@@ -134,18 +134,26 @@ auto tag_list::cend() const -> const_iterator { return tags.cend(); }
void tag_list::read_payload(io::stream_reader& reader)
{
- tag_type lt = reader.read_type();
+ tag_type lt = reader.read_type(true);
int32_t length;
reader.read_num(length);
if(length < 0 || !reader.get_istr())
throw io::stream_reader::input_error("Error reading length of tag_list");
- reset(lt);
- tags.reserve(length);
+ if(lt != tag_type::End)
+ {
+ reset(lt);
+ tags.reserve(length);
- for(int32_t i = 0; i < length; ++i)
- tags.emplace_back(reader.read_payload(lt));
+ for(int32_t i = 0; i < length; ++i)
+ tags.emplace_back(reader.read_payload(lt));
+ }
+ else
+ {
+ //In case of tag_end, ignore the length and leave the type undetermined
+ reset(tag_type::Null);
+ }
}
bool operator==(const tag_list& lhs, const tag_list& rhs)