summaryrefslogtreecommitdiffstats
path: root/src/NBT
diff options
context:
space:
mode:
Diffstat (limited to 'src/NBT')
-rw-r--r--src/NBT/ByteArrayTag.hpp62
-rw-r--r--src/NBT/ByteTag.hpp56
-rw-r--r--src/NBT/CompoundTag.hpp61
-rw-r--r--src/NBT/DoubleTag.hpp59
-rw-r--r--src/NBT/EndTag.hpp48
-rw-r--r--src/NBT/FloatTag.hpp55
-rw-r--r--src/NBT/IntArrayTag.hpp68
-rw-r--r--src/NBT/IntTag.hpp59
-rw-r--r--src/NBT/ListTag.hpp65
-rw-r--r--src/NBT/LongTag.hpp63
-rw-r--r--src/NBT/ShortTag.hpp57
-rw-r--r--src/NBT/StringTag.hpp55
-rw-r--r--src/NBT/Tag.cpp105
-rw-r--r--src/NBT/Tag.hpp65
14 files changed, 878 insertions, 0 deletions
diff --git a/src/NBT/ByteArrayTag.hpp b/src/NBT/ByteArrayTag.hpp
new file mode 100644
index 0000000..d5a6333
--- /dev/null
+++ b/src/NBT/ByteArrayTag.hpp
@@ -0,0 +1,62 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+#include <vector>
+
+
+namespace MinedMap {
+namespace NBT {
+
+class ByteArrayTag : public Tag {
+private:
+ friend class Tag;
+
+ std::vector<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);
+
+ for (uint32_t i = 0; i < len; i++)
+ value[i] = buffer->get();
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::ByteArray;
+ }
+};
+
+}
+}
diff --git a/src/NBT/ByteTag.hpp b/src/NBT/ByteTag.hpp
new file mode 100644
index 0000000..cc4aba9
--- /dev/null
+++ b/src/NBT/ByteTag.hpp
@@ -0,0 +1,56 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class ByteTag : public Tag {
+private:
+ friend class Tag;
+
+ uint8_t value;
+
+ ByteTag(Buffer *buffer) {
+ value = buffer->get();
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Byte;
+ }
+
+ uint8_t getValue() const {
+ return value;
+ }
+};
+
+}
+}
diff --git a/src/NBT/CompoundTag.hpp b/src/NBT/CompoundTag.hpp
new file mode 100644
index 0000000..99bbd94
--- /dev/null
+++ b/src/NBT/CompoundTag.hpp
@@ -0,0 +1,61 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+#include <string>
+#include <unordered_map>
+
+
+namespace MinedMap {
+namespace NBT {
+
+class CompoundTag : public Tag {
+private:
+ friend class Tag;
+
+ std::unordered_map<std::string, std::shared_ptr<Tag>> value;
+
+ CompoundTag(Buffer *buffer) {
+ while (true) {
+ std::pair<std::string, std::shared_ptr<Tag>> v = Tag::readNamedTag(buffer);
+ if (v.second->getType() == Type::End)
+ break;
+
+ value.insert(std::move(v));
+ }
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Compound;
+ }
+};
+
+}
+}
diff --git a/src/NBT/DoubleTag.hpp b/src/NBT/DoubleTag.hpp
new file mode 100644
index 0000000..327dcf5
--- /dev/null
+++ b/src/NBT/DoubleTag.hpp
@@ -0,0 +1,59 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class DoubleTag : public Tag {
+private:
+ friend class Tag;
+
+ DoubleTag(Buffer *buffer) {
+ uint64_t value;
+
+ value = uint64_t(buffer->get()) << 56;
+ value |= uint64_t(buffer->get()) << 48;
+ value |= uint64_t(buffer->get()) << 40;
+ value |= uint64_t(buffer->get()) << 32;
+ value |= uint64_t(buffer->get()) << 24;
+ value |= uint64_t(buffer->get()) << 16;
+ value |= uint64_t(buffer->get()) << 8;
+ value |= uint64_t(buffer->get());
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Double;
+ }
+};
+
+}
+}
diff --git a/src/NBT/EndTag.hpp b/src/NBT/EndTag.hpp
new file mode 100644
index 0000000..c969e98
--- /dev/null
+++ b/src/NBT/EndTag.hpp
@@ -0,0 +1,48 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class EndTag : public Tag {
+private:
+ friend class Tag;
+
+ EndTag() {}
+
+public:
+ virtual Type getType() const {
+ return Type::End;
+ }
+};
+
+}
+}
diff --git a/src/NBT/FloatTag.hpp b/src/NBT/FloatTag.hpp
new file mode 100644
index 0000000..8859f94
--- /dev/null
+++ b/src/NBT/FloatTag.hpp
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class FloatTag : public Tag {
+private:
+ friend class Tag;
+
+ FloatTag(Buffer *buffer) {
+ uint32_t value;
+
+ value = uint32_t(buffer->get()) << 24;
+ value |= uint32_t(buffer->get()) << 16;
+ value |= uint32_t(buffer->get()) << 8;
+ value |= uint32_t(buffer->get());
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Float;
+ }
+};
+
+}
+}
diff --git a/src/NBT/IntArrayTag.hpp b/src/NBT/IntArrayTag.hpp
new file mode 100644
index 0000000..e9b0d3d
--- /dev/null
+++ b/src/NBT/IntArrayTag.hpp
@@ -0,0 +1,68 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+#include <vector>
+
+
+namespace MinedMap {
+namespace NBT {
+
+class IntArrayTag : public Tag {
+private:
+ friend class Tag;
+
+ std::vector<uint32_t> value;
+
+ IntArrayTag(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);
+
+ for (uint32_t i = 0; i < len; i++) {
+ uint32_t v = uint32_t(buffer->get()) << 24;
+ v |= uint32_t(buffer->get()) << 16;
+ v |= uint32_t(buffer->get()) << 8;
+ v |= uint32_t(buffer->get());
+
+ value[i] = v;
+ }
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::IntArray;
+ }
+};
+
+}
+}
diff --git a/src/NBT/IntTag.hpp b/src/NBT/IntTag.hpp
new file mode 100644
index 0000000..9e7b3db
--- /dev/null
+++ b/src/NBT/IntTag.hpp
@@ -0,0 +1,59 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class IntTag : public Tag {
+private:
+ friend class Tag;
+
+ uint32_t value;
+
+ IntTag(Buffer *buffer) {
+ value = uint32_t(buffer->get()) << 24;
+ value |= uint32_t(buffer->get()) << 16;
+ value |= uint32_t(buffer->get()) << 8;
+ value |= uint32_t(buffer->get());
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Int;
+ }
+
+ uint32_t getValue() const {
+ return value;
+ }
+};
+
+}
+}
diff --git a/src/NBT/ListTag.hpp b/src/NBT/ListTag.hpp
new file mode 100644
index 0000000..6404065
--- /dev/null
+++ b/src/NBT/ListTag.hpp
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+#include <vector>
+
+
+namespace MinedMap {
+namespace NBT {
+
+class ListTag : public Tag {
+private:
+ friend class Tag;
+
+ std::vector<std::shared_ptr<Tag>> value;
+
+
+ ListTag(Buffer *buffer) {
+ Type type = static_cast<Type>(buffer->get());
+
+ 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);
+
+ for (uint32_t i = 0; i < len; i++)
+ value[i] = Tag::readTag(type, buffer);
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::List;
+ }
+};
+
+}
+}
diff --git a/src/NBT/LongTag.hpp b/src/NBT/LongTag.hpp
new file mode 100644
index 0000000..6cd5f8f
--- /dev/null
+++ b/src/NBT/LongTag.hpp
@@ -0,0 +1,63 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class LongTag : public Tag {
+private:
+ friend class Tag;
+
+ uint64_t value;
+
+ LongTag(Buffer *buffer) {
+ value = uint64_t(buffer->get()) << 56;
+ value |= uint64_t(buffer->get()) << 48;
+ value |= uint64_t(buffer->get()) << 40;
+ value |= uint64_t(buffer->get()) << 32;
+ value |= uint64_t(buffer->get()) << 24;
+ value |= uint64_t(buffer->get()) << 16;
+ value |= uint64_t(buffer->get()) << 8;
+ value |= uint64_t(buffer->get());
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Long;
+ }
+
+ uint64_t getValue() const {
+ return value;
+ }
+};
+
+}
+}
diff --git a/src/NBT/ShortTag.hpp b/src/NBT/ShortTag.hpp
new file mode 100644
index 0000000..a44ca9b
--- /dev/null
+++ b/src/NBT/ShortTag.hpp
@@ -0,0 +1,57 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class ShortTag : public Tag {
+private:
+ friend class Tag;
+
+ uint16_t value;
+
+ ShortTag(Buffer *buffer) {
+ value = buffer->get() << 8;
+ value |= buffer->get();
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::Short;
+ }
+
+ uint16_t getValue() const {
+ return value;
+ }
+};
+
+}
+}
diff --git a/src/NBT/StringTag.hpp b/src/NBT/StringTag.hpp
new file mode 100644
index 0000000..a120183
--- /dev/null
+++ b/src/NBT/StringTag.hpp
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include "Tag.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class StringTag : public Tag {
+private:
+ friend class Tag;
+
+ std::string value;
+
+ StringTag(Buffer *buffer) {
+ uint16_t len = buffer->get() << 8;
+ len |= buffer->get();
+
+ value = buffer->getString(len);
+ }
+
+public:
+ virtual Type getType() const {
+ return Type::String;
+ }
+};
+
+}
+}
diff --git a/src/NBT/Tag.cpp b/src/NBT/Tag.cpp
new file mode 100644
index 0000000..fddfc4e
--- /dev/null
+++ b/src/NBT/Tag.cpp
@@ -0,0 +1,105 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#include "Tag.hpp"
+
+#include "EndTag.hpp"
+#include "ByteTag.hpp"
+#include "ShortTag.hpp"
+#include "IntTag.hpp"
+#include "LongTag.hpp"
+#include "FloatTag.hpp"
+#include "DoubleTag.hpp"
+#include "ByteArrayTag.hpp"
+#include "StringTag.hpp"
+#include "ListTag.hpp"
+#include "CompoundTag.hpp"
+#include "IntArrayTag.hpp"
+
+
+#include <stdexcept>
+
+
+namespace MinedMap {
+namespace NBT {
+
+std::shared_ptr<Tag> Tag::readTag(Type type, Buffer *buffer) {
+ switch (type) {
+ case Type::End:
+ return std::shared_ptr<EndTag>(new EndTag());
+
+ case Type::Byte:
+ return std::shared_ptr<ByteTag>(new ByteTag(buffer));
+
+ case Type::Short:
+ return std::shared_ptr<ShortTag>(new ShortTag(buffer));
+
+ case Type::Int:
+ return std::shared_ptr<IntTag>(new IntTag(buffer));
+
+ case Type::Long:
+ return std::shared_ptr<LongTag>(new LongTag(buffer));
+
+ case Type::Float:
+ return std::shared_ptr<FloatTag>(new FloatTag(buffer));
+
+ case Type::Double:
+ return std::shared_ptr<DoubleTag>(new DoubleTag(buffer));
+
+ case Type::ByteArray:
+ return std::shared_ptr<ByteArrayTag>(new ByteArrayTag(buffer));
+
+ case Type::String:
+ return std::shared_ptr<StringTag>(new StringTag(buffer));
+
+ case Type::List:
+ return std::shared_ptr<ListTag>(new ListTag(buffer));
+
+ case Type::Compound:
+ return std::shared_ptr<CompoundTag>(new CompoundTag(buffer));
+
+ case Type::IntArray:
+ return std::shared_ptr<IntArrayTag>(new IntArrayTag(buffer));
+
+ default:
+ throw std::runtime_error("Tag::read: unknown tag type");
+ }
+}
+
+std::pair<std::string, std::shared_ptr<Tag>> Tag::readNamedTag(Buffer *buffer) {
+ Type type = static_cast<Type>(buffer->get());
+ if (type == Type::End)
+ return std::make_pair("", std::shared_ptr<EndTag>(new EndTag()));
+
+ uint16_t len = buffer->get() << 8;
+ len |= buffer->get();
+ std::string name = buffer->getString(len);
+
+ return std::make_pair(name, readTag(type, buffer));
+}
+
+}
+}
diff --git a/src/NBT/Tag.hpp b/src/NBT/Tag.hpp
new file mode 100644
index 0000000..0d25299
--- /dev/null
+++ b/src/NBT/Tag.hpp
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#pragma once
+
+#include <cstdint>
+#include <memory>
+
+#include "../Buffer.hpp"
+
+
+namespace MinedMap {
+namespace NBT {
+
+class Tag {
+public:
+ enum class Type {
+ End = 0,
+ Byte = 1,
+ Short = 2,
+ Int = 3,
+ Long = 4,
+ Float = 5,
+ Double = 6,
+ ByteArray = 7,
+ String = 8,
+ List = 9,
+ Compound = 10,
+ IntArray = 11,
+ };
+
+ static std::shared_ptr<Tag> readTag(Type type, Buffer *buffer);
+
+ static std::pair<std::string, std::shared_ptr<Tag>> readNamedTag(Buffer *buffer);
+
+ virtual Type getType() const = 0;
+
+ virtual ~Tag() {}
+};
+
+}
+}