MinedMap/src/NBT/ByteArrayTag.hpp

69 lines
1.1 KiB
C++
Raw Permalink Normal View History

// SPDX-License-Identifier: BSD-2-Clause
2015-02-01 00:21:17 +01:00
/*
Copyright (c) 2015, Matthias Schiffer <mschiffer@universe-factory.net>
All rights reserved.
*/
#pragma once
#include "Tag.hpp"
#include <vector>
namespace MinedMap {
namespace NBT {
class ByteArrayTag : public Tag {
private:
2015-02-01 04:14:42 +01:00
uint32_t len;
const uint8_t *ptr;
2015-02-01 00:21:17 +01:00
public:
2018-07-21 18:07:45 +02:00
static const MakeType<ByteArrayTag> Type;
2015-02-01 00:21:17 +01:00
ByteArrayTag(Buffer *buffer) {
2015-02-01 04:14:42 +01:00
len = buffer->get32();
ptr = buffer->get(len);
2015-02-01 00:21:17 +01:00
}
2018-07-21 18:07:45 +02:00
virtual const TagType & getType() const {
return Type;
2015-02-01 00:21:17 +01:00
}
2015-02-01 04:14:42 +01:00
virtual void print(std::ostream& os, const std::string &indent) const {
os << "(" << len << ") [" << std::endl;
std::string inner = indent + " ";
for (size_t i = 0; i < len; i++) {
uint8_t v = ptr[i];
os << inner
<< (unsigned)v << " / "
<< (int)(int8_t)v << " / "
<< std::hex << "0x" << (unsigned)v << std::dec
<< std::endl;
}
os << indent << "]";
}
2015-02-01 04:14:42 +01:00
uint32_t getLength() const {
return len;
}
const uint8_t * getPointer() const {
return ptr;
}
uint8_t getValue(size_t i) const {
return ptr[i];
2015-02-01 14:02:04 +01:00
}
2015-02-01 00:21:17 +01:00
};
}
}