用于格式化打印、序列化、计算哈希等功能
更多...
#include <NBT_Helper.hpp>
|
|
using | DefaultFuncType = std::decay_t<decltype(DefaultFunc)> |
| | 函数的类型,用于模板默认值
|
|
| 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对象进行递归计算哈希
- 模板参数
-
| 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>
直接序列化,按照一定规则输出为String并返回
- 模板参数
-
| bSortCompound | 是否对Compound进行排序 |
| bHexNumType | 是否使用十六进制无损输出值 |
| bSnbtType | 是否对输出为SNBT格式(SNBT下强制为十进制值,忽略bHexNumType参数) |
- 参数
-
| nRoot | 任意NBT_Type中的类型,仅初始化为视图 |
- 返回
- 返回序列化的结果
- 注解
- 注意并非序列化为snbt,一般用于小NBT对象的附加信息输出
该类的文档由以下文件生成: