2021-11-17 12:07:56 +01:00
|
|
|
// 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;
|
2019-12-11 21:02:51 +01:00
|
|
|
const uint8_t *ptr;
|
2015-02-01 00:21:17 +01:00
|
|
|
|
2018-07-21 16:17:40 +02: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();
|
2019-12-11 21:02:51 +01:00
|
|
|
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
|
|
|
|
2018-07-20 23:09:33 +02: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++) {
|
2019-12-11 21:02:51 +01:00
|
|
|
uint8_t v = ptr[i];
|
2018-07-20 23:09:33 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-11 21:02:51 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|