chenjunfu2-nbt-cpp v2.1.0
一个基于CPP20的NBT(Named Binary Tag)库
载入中...
搜索中...
未找到
NBT_Helper类 参考

用于格式化打印、序列化、计算哈希等功能 更多...

#include <NBT_Helper.hpp>

Public 类型

using DefaultFuncType = std::decay_t<decltype(DefaultFunc)>
 函数的类型,用于模板默认值

静态 Public 成员函数

template<bool bSortCompound = true, typename PrintFunc = NBT_Print>
static void Print (const NBT_Node_View< true > nRoot, size_t szPaddingStartLevel=0, const std::string &strLevelPadding=" ", PrintFunc funcPrint=NBT_Print{})
 格式化对齐打印NBT对象
template<bool bSortCompound = true, bool bHexNumType = true, bool bSnbtType = false>
static std::conditional_t< bSnbtType, NBT_Type::String, std::string > Serialize (const NBT_Node_View< true > nRoot)
 直接序列化,按照一定规则输出为String并返回
static void DefaultFunc (NBT_Hash &nbtHash)
 用于插入哈希的示例函数
template<bool bSortCompound = true, typename TB = DefaultFuncType, typename TA = DefaultFuncType>
static NBT_Hash::HASH_T Hash (const NBT_Node_View< true > nRoot, NBT_Hash nbtHash, TB funBefore=DefaultFunc, TA funAfter=DefaultFunc)
 对NBT对象进行递归计算哈希

详细描述

用于格式化打印、序列化、计算哈希等功能

注解
计算哈希需要安装xxhash库

成员函数说明

◆ DefaultFunc()

void NBT_Helper::DefaultFunc ( NBT_Hash & nbtHash)
inlinestatic

用于插入哈希的示例函数

参数
nbtHash哈希对象,可以向内部添加数据,具体请参考NBT_Hash
注解
此函数为默认实现,请根据需要替换

◆ Hash()

template<bool bSortCompound = true, typename TB = DefaultFuncType, typename TA = DefaultFuncType>
NBT_Hash::HASH_T NBT_Helper::Hash ( const NBT_Node_View< true > nRoot,
NBT_Hash nbtHash,
TB funBefore = DefaultFunc,
TA funAfter = DefaultFunc )
inlinestatic

对NBT对象进行递归计算哈希

模板参数
bSortCompound是否对Compound进行排序,以获得一致性哈希结果
TB开始NBT哈希之前调用的仿函数类型
TA结束NBT哈希之后调用的仿函数类型
参数
nRoot任意NBT_Type中的类型,仅初始化为视图
nbtHash哈希对象,使用一个哈希种子初始化,具体请参考NBT_Hash
funBefore开始NBT哈希之前调用的仿函数
funAfter结束NBT哈希之后调用的仿函数
返回
计算的哈希值,可以用于哈希表或比较NBT对象等
注解
注意,递归层数在此函数内没有限制,请注意不要将过深的NBT对象传入导致栈溢出!

◆ Print()

template<bool bSortCompound = true, typename PrintFunc = NBT_Print>
void NBT_Helper::Print ( const NBT_Node_View< true > nRoot,
size_t szPaddingStartLevel = 0,
const std::string & strLevelPadding = "    ",
PrintFunc funcPrint = NBT_Print{} )
inlinestatic

格式化对齐打印NBT对象

模板参数
bSortCompound是否对Compound进行排序
PrintFunc用于输出的仿函数类型,具体格式请参考NBT_Print说明
参数
nRoot任意NBT_Type中的类型,仅初始化为视图
szPaddingStartLevel从指定缩进等级开始打印,值为(size_t)-1则不打印缩进
strLevelPadding用于打印一级的空白内容
funcPrint用于输出的仿函数

◆ Serialize()

template<bool bSortCompound = true, bool bHexNumType = true, bool bSnbtType = false>
std::conditional_t< bSnbtType, NBT_Type::String, std::string > NBT_Helper::Serialize ( const NBT_Node_View< true > nRoot)
inlinestatic

直接序列化,按照一定规则输出为String并返回

模板参数
bSortCompound是否对Compound进行排序
bHexNumType是否使用十六进制无损输出值
bSnbtType是否对输出为SNBT格式(SNBT下强制为十进制值,忽略bHexNumType参数)
参数
nRoot任意NBT_Type中的类型,仅初始化为视图
返回
返回序列化的结果
注解
注意并非序列化为snbt,一般用于小NBT对象的附加信息输出

该类的文档由以下文件生成: