22 #include <system_error> 23 #include "../Endianness.h" 99 m_PrevSibling(a_PrevSibling),
135 public std::true_type
155 cParsedNBT(
const char * a_Data,
size_t a_Length);
195 return m_Data + m_Tags[
static_cast<size_t>(a_Tag)].
m_DataStart;
201 return FindChildByName(a_Tag, a_Name.c_str(), a_Name.length());
205 int FindChildByName(
int a_Tag,
const char * a_Name,
size_t a_NameLength = 0)
const;
208 int FindTagByPath(
int a_Tag,
const AString & a_Path)
const;
216 return (m_Tags[static_cast<size_t>(a_Tag)].
m_FirstChild < 0) ?
TAG_End : m_Tags[
static_cast<size_t>(m_Tags[
static_cast<size_t>(a_Tag)].
m_FirstChild)].m_Type;
223 return static_cast<unsigned char>(m_Data[
static_cast<size_t>(m_Tags[
static_cast<size_t>(a_Tag)].
m_DataStart)]);
254 char Check1[5 -
sizeof(float)];
255 char Check2[
sizeof(float) - 3];
261 memcpy(&f, &i,
sizeof(f));
270 char Check1[9 -
sizeof(double)];
271 char Check2[
sizeof(double) - 7];
284 res.assign(m_Data + m_Tags[static_cast<size_t>(a_Tag)].
m_DataStart, static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].
m_DataLength));
292 res.assign(m_Data + m_Tags[static_cast<size_t>(a_Tag)].
m_NameStart, static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].
m_NameLength));
306 eNBTParseError ReadString(
size_t & a_StringStart,
size_t & a_StringLen);
321 void BeginCompound(
const AString & a_Name);
322 void EndCompound(
void);
327 void AddByte (
const AString & a_Name,
unsigned char a_Value);
331 void AddFloat (
const AString & a_Name,
float a_Value);
332 void AddDouble (
const AString & a_Name,
double a_Value);
334 void AddByteArray(
const AString & a_Name,
const char * a_Value,
size_t a_NumElements);
335 void AddIntArray (
const AString & a_Name,
const int * a_Value,
size_t a_NumElements);
339 AddByteArray(a_Name, a_Value.data(), a_Value.size());
356 static const int MAX_STACK = 50;
366 void WriteString(
const char * a_Data,
UInt16 a_Length);
371 ASSERT((m_Stack[m_CurrentStack].
m_Type !=
TAG_List) || (m_Stack[m_CurrentStack].m_ItemType == a_Type));
373 if (IsStackTopCompound())
376 m_Result.push_back(static_cast<char>(a_Type));
377 WriteString(a_Name.c_str(),
static_cast<UInt16>(a_Name.length()));
382 m_Stack[m_CurrentStack].
m_Count++;
Int64 NetworkToHostLong8(const void *a_Value)
void TagCommon(const AString &a_Name, eTagType a_Type)
float GetFloat(int a_Tag) const
Returns the value stored in a Float tag.
Int64 GetLong(int a_Tag) const
Returns the value stored in a Long tag.
This structure is used for all NBT tags.
const char * GetData(int a_Tag) const
Returns the data stored in this tag.
std::error_code make_error_code(eNBTParseError a_Err) NOEXCEPT
size_t GetErrorPos() const
Returns the position where an error occurred while parsing.
Parses and contains the parsed data Also implements data accessor functions for tree traversal and va...
int GetRoot(void) const
Returns the root tag of the hierarchy.
eTagType GetType(int a_Tag) const
double NetworkToHostDouble8(const void *a_Value)
std::vector< cFastNBTTag > m_Tags
Int32 GetInt(int a_Tag) const
Returns the value stored in an Int tag.
double GetDouble(int a_Tag) const
Returns the value stored in a Double tag.
std::error_code GetErrorCode() const
Returns the error code for the parsing of the NBT data.
short GetBEShort(const char *a_Mem)
Reads two bytes from the specified memory location and interprets them as BigEndian short...
Int16 GetShort(int a_Tag) const
Returns the value stored in a Short tag.
cFastNBTTag(eTagType a_Type, int a_Parent)
int GetNextSibling(int a_Tag) const
Returns the next sibling of the specified tag, or -1 if none.
eTagType GetChildrenType(int a_Tag) const
Returns the children type for a List tag; undefined on other tags.
int GetPrevSibling(int a_Tag) const
Returns the previous sibling of the specified tag, or -1 if none.
bool IsStackTopCompound(void) const
AString GetName(int a_Tag) const
Returns the tag's name.
const AString & GetResult(void) const
int FindChildByName(int a_Tag, const AString &a_Name) const
Returns the direct child tag of the specified name, or -1 if no such tag.
size_t GetDataLength(int a_Tag) const
Returns the length of the tag's data, in bytes.
int GetLastChild(int a_Tag) const
Returns the last child of the specified tag, or -1 if none / not applicable.
unsigned char GetByte(int a_Tag) const
Returns the value stored in a Byte tag.
AString GetString(int a_Tag) const
Returns the value stored in a String tag.
int GetBEInt(const char *a_Mem)
Reads four bytes from the specified memory location and interprets them as BigEndian int...
void AddByteArray(const AString &a_Name, const AString &a_Value)
cFastNBTTag(eTagType a_Type, int a_Parent, int a_PrevSibling)
int GetFirstChild(int a_Tag) const
Returns the first child of the specified tag, or -1 if none / not applicable.