From 8a8a41a800dfe9bdcab934d6b53d9c6defd4a457 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Feb 2015 04:14:42 +0100 Subject: Parse chunk data on demand --- src/NBT/ByteArrayTag.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/NBT/ByteArrayTag.hpp') diff --git a/src/NBT/ByteArrayTag.hpp b/src/NBT/ByteArrayTag.hpp index ee0d7d1..2081759 100644 --- a/src/NBT/ByteArrayTag.hpp +++ b/src/NBT/ByteArrayTag.hpp @@ -38,22 +38,26 @@ class ByteArrayTag : public Tag { private: friend class Tag; - std::vector value; + uint32_t len; + const uint8_t *value; ByteArrayTag(Buffer *buffer) { - uint32_t len = uint32_t(buffer->get()) << 24; - len |= uint32_t(buffer->get()) << 16; - len |= uint32_t(buffer->get()) << 8; - len |= uint32_t(buffer->get()); - - value.resize(len); - buffer->getData(value.data(), len); + len = buffer->get32(); + value = buffer->get(len); } public: virtual Type getType() const { return Type::ByteArray; } + + uint32_t getLength() const { + return len; + } + + const uint8_t & operator[](size_t i) const { + return value[i]; + } }; } -- cgit v1.2.3