Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
cParsedNBT Class Reference

Parses and contains the parsed data Also implements data accessor functions for tree traversal and value getters The data pointer passed in the constructor is assumed to be valid throughout the object's life. More...

#include <FastNBT.h>

Public Member Functions

 cParsedNBT (ContiguousByteBufferView a_Data)
 
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. More...
 
int FindChildByName (int a_Tag, const char *a_Name, size_t a_NameLength=0) const
 Returns the direct child tag of the specified name, or -1 if no such tag. More...
 
int FindTagByPath (int a_Tag, const AString &a_Path) const
 Returns the child tag of the specified path (Name1 / Name2 / Name3...), or -1 if no such tag. More...
 
unsigned char GetByte (int a_Tag) const
 Returns the value stored in a Byte tag. More...
 
eTagType GetChildrenType (int a_Tag) const
 Returns the children type for a List tag; undefined on other tags. More...
 
const std::byte * GetData (int a_Tag) const
 Returns the data stored in this tag. More...
 
size_t GetDataLength (int a_Tag) const
 Returns the length of the tag's data, in bytes. More...
 
double GetDouble (int a_Tag) const
 Returns the value stored in a Double tag. More...
 
std::error_code GetErrorCode () const
 Returns the error code for the parsing of the NBT data. More...
 
size_t GetErrorPos () const
 Returns the position where an error occurred while parsing. More...
 
int GetFirstChild (int a_Tag) const
 Returns the first child of the specified tag, or -1 if none / not applicable. More...
 
float GetFloat (int a_Tag) const
 Returns the value stored in a Float tag. More...
 
Int32 GetInt (int a_Tag) const
 Returns the value stored in an Int tag. More...
 
int GetLastChild (int a_Tag) const
 Returns the last child of the specified tag, or -1 if none / not applicable. More...
 
Int64 GetLong (int a_Tag) const
 Returns the value stored in a Long tag. More...
 
AString GetName (int a_Tag) const
 Returns the tag's name. More...
 
int GetNextSibling (int a_Tag) const
 Returns the next sibling of the specified tag, or -1 if none. More...
 
int GetPrevSibling (int a_Tag) const
 Returns the previous sibling of the specified tag, or -1 if none. More...
 
int GetRoot (void) const
 Returns the root tag of the hierarchy. More...
 
Int16 GetShort (int a_Tag) const
 Returns the value stored in a Short tag. More...
 
AString GetString (int a_Tag) const
 Returns the value stored in a String tag. More...
 
std::string_view GetStringView (int a_Tag) const
 Returns the value stored in a String tag. More...
 
eTagType GetType (int a_Tag) const
 
bool IsValid (void) const
 

Protected Member Functions

eNBTParseError Parse (void)
 
eNBTParseError ReadCompound (void)
 
eNBTParseError ReadList (eTagType a_ChildrenType)
 
eNBTParseError ReadString (size_t &a_StringStart, size_t &a_StringLen)
 
eNBTParseError ReadTag (void)
 

Static Protected Member Functions

static size_t GetMinTagSize (eTagType a_TagType)
 Returns the minimum size, in bytes, of the specified tag type. More...
 

Protected Attributes

ContiguousByteBufferView m_Data
 
eNBTParseError m_Error
 
size_t m_Pos
 
std::vector< cFastNBTTagm_Tags
 

Detailed Description

Parses and contains the parsed data Also implements data accessor functions for tree traversal and value getters The data pointer passed in the constructor is assumed to be valid throughout the object's life.

Care must be taken not to initialize from a temporary. The parser decomposes the input data into a tree of tags that is stored as an array of cFastNBTTag items, and accessing the tree is done by using the array indices for tags. Each tag stores the indices for its parent, first child, last child, prev sibling and next sibling, a value of -1 indicates that the indice is not valid. Each primitive tag also stores the length of the contained data, in bytes.

Definition at line 152 of file FastNBT.h.

Constructor & Destructor Documentation

◆ cParsedNBT()

cParsedNBT::cParsedNBT ( ContiguousByteBufferView  a_Data)

Definition at line 150 of file FastNBT.cpp.

Member Function Documentation

◆ FindChildByName() [1/2]

int cParsedNBT::FindChildByName ( int  a_Tag,
const AString a_Name 
) const
inline

Returns the direct child tag of the specified name, or -1 if no such tag.

Definition at line 199 of file FastNBT.h.

◆ FindChildByName() [2/2]

int cParsedNBT::FindChildByName ( int  a_Tag,
const char *  a_Name,
size_t  a_NameLength = 0 
) const

Returns the direct child tag of the specified name, or -1 if no such tag.

Definition at line 375 of file FastNBT.cpp.

◆ FindTagByPath()

int cParsedNBT::FindTagByPath ( int  a_Tag,
const AString a_Path 
) const

Returns the child tag of the specified path (Name1 / Name2 / Name3...), or -1 if no such tag.

Definition at line 407 of file FastNBT.cpp.

◆ GetByte()

unsigned char cParsedNBT::GetByte ( int  a_Tag) const
inline

Returns the value stored in a Byte tag.

Not valid for any other tag type.

Definition at line 220 of file FastNBT.h.

◆ GetChildrenType()

eTagType cParsedNBT::GetChildrenType ( int  a_Tag) const
inline

Returns the children type for a List tag; undefined on other tags.

If list empty, returns TAG_End.

Definition at line 213 of file FastNBT.h.

◆ GetData()

const std::byte* cParsedNBT::GetData ( int  a_Tag) const
inline

Returns the data stored in this tag.

Not valid for Compound or List tags!

Definition at line 191 of file FastNBT.h.

◆ GetDataLength()

size_t cParsedNBT::GetDataLength ( int  a_Tag) const
inline

Returns the length of the tag's data, in bytes.

Not valid for Compound or List tags!

Definition at line 182 of file FastNBT.h.

◆ GetDouble()

double cParsedNBT::GetDouble ( int  a_Tag) const
inline

Returns the value stored in a Double tag.

Not valid for any other tag type.

Definition at line 266 of file FastNBT.h.

◆ GetErrorCode()

std::error_code cParsedNBT::GetErrorCode ( ) const
inline

Returns the error code for the parsing of the NBT data.

Definition at line 160 of file FastNBT.h.

◆ GetErrorPos()

size_t cParsedNBT::GetErrorPos ( ) const
inline

Returns the position where an error occurred while parsing.

Definition at line 163 of file FastNBT.h.

◆ GetFirstChild()

int cParsedNBT::GetFirstChild ( int  a_Tag) const
inline

Returns the first child of the specified tag, or -1 if none / not applicable.

Definition at line 169 of file FastNBT.h.

◆ GetFloat()

float cParsedNBT::GetFloat ( int  a_Tag) const
inline

Returns the value stored in a Float tag.

Not valid for any other tag type.

Definition at line 248 of file FastNBT.h.

◆ GetInt()

Int32 cParsedNBT::GetInt ( int  a_Tag) const
inline

Returns the value stored in an Int tag.

Not valid for any other tag type.

Definition at line 234 of file FastNBT.h.

◆ GetLastChild()

int cParsedNBT::GetLastChild ( int  a_Tag) const
inline

Returns the last child of the specified tag, or -1 if none / not applicable.

Definition at line 172 of file FastNBT.h.

◆ GetLong()

Int64 cParsedNBT::GetLong ( int  a_Tag) const
inline

Returns the value stored in a Long tag.

Not valid for any other tag type.

Definition at line 241 of file FastNBT.h.

◆ GetMinTagSize()

size_t cParsedNBT::GetMinTagSize ( eTagType  a_TagType)
staticprotected

Returns the minimum size, in bytes, of the specified tag type.

Used for sanity-checking.

Definition at line 441 of file FastNBT.cpp.

◆ GetName()

AString cParsedNBT::GetName ( int  a_Tag) const
inline

Returns the tag's name.

For tags that are not named, returns an empty string.

Definition at line 293 of file FastNBT.h.

◆ GetNextSibling()

int cParsedNBT::GetNextSibling ( int  a_Tag) const
inline

Returns the next sibling of the specified tag, or -1 if none.

Definition at line 175 of file FastNBT.h.

◆ GetPrevSibling()

int cParsedNBT::GetPrevSibling ( int  a_Tag) const
inline

Returns the previous sibling of the specified tag, or -1 if none.

Definition at line 178 of file FastNBT.h.

◆ GetRoot()

int cParsedNBT::GetRoot ( void  ) const
inline

Returns the root tag of the hierarchy.

Definition at line 166 of file FastNBT.h.

◆ GetShort()

Int16 cParsedNBT::GetShort ( int  a_Tag) const
inline

Returns the value stored in a Short tag.

Not valid for any other tag type.

Definition at line 227 of file FastNBT.h.

◆ GetString()

AString cParsedNBT::GetString ( int  a_Tag) const
inline

Returns the value stored in a String tag.

Not valid for any other tag type.

Definition at line 280 of file FastNBT.h.

◆ GetStringView()

std::string_view cParsedNBT::GetStringView ( int  a_Tag) const
inline

Returns the value stored in a String tag.

Not valid for any other tag type.

Definition at line 286 of file FastNBT.h.

◆ GetType()

eTagType cParsedNBT::GetType ( int  a_Tag) const
inline

Definition at line 210 of file FastNBT.h.

◆ IsValid()

bool cParsedNBT::IsValid ( void  ) const
inline

Definition at line 157 of file FastNBT.h.

◆ Parse()

eNBTParseError cParsedNBT::Parse ( void  )
protected

Definition at line 161 of file FastNBT.cpp.

◆ ReadCompound()

eNBTParseError cParsedNBT::ReadCompound ( void  )
protected

Definition at line 202 of file FastNBT.cpp.

◆ ReadList()

eNBTParseError cParsedNBT::ReadList ( eTagType  a_ChildrenType)
protected

Definition at line 244 of file FastNBT.cpp.

◆ ReadString()

eNBTParseError cParsedNBT::ReadString ( size_t &  a_StringStart,
size_t &  a_StringLen 
)
protected

Definition at line 188 of file FastNBT.cpp.

◆ ReadTag()

eNBTParseError cParsedNBT::ReadTag ( void  )
protected

Definition at line 294 of file FastNBT.cpp.

Member Data Documentation

◆ m_Data

ContiguousByteBufferView cParsedNBT::m_Data
protected

Definition at line 302 of file FastNBT.h.

◆ m_Error

eNBTParseError cParsedNBT::m_Error
protected

Definition at line 304 of file FastNBT.h.

◆ m_Pos

size_t cParsedNBT::m_Pos
protected

Definition at line 307 of file FastNBT.h.

◆ m_Tags

std::vector<cFastNBTTag> cParsedNBT::m_Tags
protected

Definition at line 303 of file FastNBT.h.


The documentation for this class was generated from the following files: