Add NBT::Tag::GetData() and NBT::DataBuffer
This commit is contained in:
parent
a616c4ce80
commit
ecf8a1dd0b
|
@ -6,6 +6,7 @@
|
|||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace NBT
|
||||
{
|
||||
|
@ -38,6 +39,12 @@ namespace NBT
|
|||
return list_entry(item, const decltype(nbt_node::payload)::nbt_list, entry)->data;
|
||||
}
|
||||
|
||||
DataBuffer::~DataBuffer()
|
||||
{
|
||||
// equivalent to buffer_free in cNBT buffer.h
|
||||
free(data);
|
||||
}
|
||||
|
||||
Tag Tag::CreateTag(nbt_node *node)
|
||||
{
|
||||
switch (node->type)
|
||||
|
@ -119,6 +126,13 @@ namespace NBT
|
|||
}
|
||||
}
|
||||
|
||||
const DataBuffer Tag::GetData() const
|
||||
{
|
||||
buffer buf = nbt_dump_binary(m_node);
|
||||
DataBuffer result { buf.data, buf.len };
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *Tag::ToString() const
|
||||
{
|
||||
return nbt_dump_ascii(m_node);
|
||||
|
|
|
@ -13,7 +13,17 @@ struct nbt_node;
|
|||
struct list_head;
|
||||
|
||||
namespace NBT
|
||||
{
|
||||
{
|
||||
// NBT-specific data buffer.
|
||||
// TODO: could replace with some project-wide utility class
|
||||
struct DataBuffer
|
||||
{
|
||||
uint8_t* data;
|
||||
size_t length;
|
||||
|
||||
~DataBuffer();
|
||||
};
|
||||
|
||||
// Represents a generic NBT tag of any type
|
||||
class Tag
|
||||
{
|
||||
|
@ -31,6 +41,9 @@ namespace NBT
|
|||
// Get the number of iterable immediate children
|
||||
size_t GetLength() const;
|
||||
|
||||
// Get uncompressed NBT binary data
|
||||
const DataBuffer GetData() const;
|
||||
|
||||
const char* ToString() const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue