Add NBT::Tag::GetData() and NBT::DataBuffer
This commit is contained in:
parent
a616c4ce80
commit
ecf8a1dd0b
|
@ -6,6 +6,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace NBT
|
namespace NBT
|
||||||
{
|
{
|
||||||
|
@ -38,6 +39,12 @@ namespace NBT
|
||||||
return list_entry(item, const decltype(nbt_node::payload)::nbt_list, entry)->data;
|
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)
|
Tag Tag::CreateTag(nbt_node *node)
|
||||||
{
|
{
|
||||||
switch (node->type)
|
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
|
const char *Tag::ToString() const
|
||||||
{
|
{
|
||||||
return nbt_dump_ascii(m_node);
|
return nbt_dump_ascii(m_node);
|
||||||
|
|
|
@ -14,6 +14,16 @@ struct list_head;
|
||||||
|
|
||||||
namespace NBT
|
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
|
// Represents a generic NBT tag of any type
|
||||||
class Tag
|
class Tag
|
||||||
{
|
{
|
||||||
|
@ -31,6 +41,9 @@ namespace NBT
|
||||||
// Get the number of iterable immediate children
|
// Get the number of iterable immediate children
|
||||||
size_t GetLength() const;
|
size_t GetLength() const;
|
||||||
|
|
||||||
|
// Get uncompressed NBT binary data
|
||||||
|
const DataBuffer GetData() const;
|
||||||
|
|
||||||
const char* ToString() const;
|
const char* ToString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue