这个类用于提供从NBT二进制流读取到NBT_Type::Compound对象的反序列化功能
更多...
#include <NBT_Reader.hpp>
|
| template<bool bUnwrapMixedList = true, typename InputStream, typename InfoFunc = NBT_Print> |
| static bool | ReadNBT (InputStream &IptStream, NBT_Type::Compound &tCompound, size_t szStackDepth=512, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 从输入流中读取NBT数据到NBT_Type::Compound对象中
|
| template<bool bUnwrapMixedList = true, typename DataType = std::vector<uint8_t>, typename InfoFunc = NBT_Print> |
| static bool | ReadNBT (const DataType &tDataInput, size_t szStartIdx, NBT_Type::Compound &tCompound, size_t szStackDepth=512, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 从数据容器中读取NBT数据到NBT_Type::Compound对象中
|
| template<typename InfoFunc = NBT_Print> |
| static bool | SimpleReadNbtFile (const std::filesystem::path &pathFileName, NBT_Type::Compound &tCompound, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 从可能被压缩的文件中读取 NBT 数据到 NBT_Type::Compound 对象中
|
这个类用于提供从NBT二进制流读取到NBT_Type::Compound对象的反序列化功能
◆ ReadNBT() [1/2]
template<bool bUnwrapMixedList = true, typename DataType = std::vector<uint8_t>, typename InfoFunc = NBT_Print>
| bool NBT_Reader::ReadNBT |
( |
const DataType & | tDataInput, |
|
|
size_t | szStartIdx, |
|
|
NBT_Type::Compound & | tCompound, |
|
|
size_t | szStackDepth = 512, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
从数据容器中读取NBT数据到NBT_Type::Compound对象中
- 模板参数
-
| bUnwrapMixedList | 是否自动解包列表中的打包Compound |
| DataType | 数据容器类型 |
| InfoFunc | 错误信息输出仿函数类型 |
- 参数
-
| tDataInput | 输入数据容器 |
| szStartIdx | 数据起始索引,会忽略tDataInput中长度为szStartIndex的数据 |
| [out] | tCompound | 用于返回读取结果的对象 |
| szStackDepth | 递归最大深度深度,防止栈溢出 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 读取成功返回true,失败返回false
- 注解
- 此函数是ReadNBT的标准库容器版本,其它信息请参考ReadNBT(InputStream)版本的详细说明
◆ ReadNBT() [2/2]
template<bool bUnwrapMixedList = true, typename InputStream, typename InfoFunc = NBT_Print>
| bool NBT_Reader::ReadNBT |
( |
InputStream & | IptStream, |
|
|
NBT_Type::Compound & | tCompound, |
|
|
size_t | szStackDepth = 512, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
从输入流中读取NBT数据到NBT_Type::Compound对象中
- 模板参数
-
| bUnwrapMixedList | 是否自动解包列表中的打包Compound |
| InputStream | 输入流类型,必须符合DefaultInputStream类型的接口 |
| InfoFunc | 错误信息输出仿函数类型 |
- 参数
-
| IptStream | 输入流对象 |
| [out] | tCompound | 用于返回读取结果的对象 |
| szStackDepth | 递归最大深度深度,防止栈溢出 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 读取成功返回true,失败返回false
- 注解
- 错误与警告信息都输出到funcInfo,错误会导致函数结束剩下的写出任务,并进行栈回溯输出,最终返回false。警告则只会输出一次信息,然后继续执行,如果没有任何错误但是存在警告,函数仍将返回true。 函数不会清除tCompound对象的数据,所以可以通过多次调用此函数,把多个NBT数据流合并到同一个tCompound对象内, 但是如果多个流中有重复、同名的NBT键,则会产生冲突,为了保证键的唯一性,后来的值会替换原先的值,并通过funcInfo产生一个警告信息。
◆ SimpleReadNbtFile()
template<typename InfoFunc = NBT_Print>
| bool NBT_Reader::SimpleReadNbtFile |
( |
const std::filesystem::path & | pathFileName, |
|
|
NBT_Type::Compound & | tCompound, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
从可能被压缩的文件中读取 NBT 数据到 NBT_Type::Compound 对象中
- 模板参数
-
- 参数
-
| pathFileName | 源文件路径 |
| [out] | tCompound | 用于返回读取结果的对象 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 读取成功返回 true,失败返回 false
- 注解
- 本函数会读取整个文件内容,先尝试使用 Zlib 解压。若解压失败,则假定文件未压缩,直接使用原始数据。 然后调用 ReadNBT 解析数据到 Compound 对象。如果文件不存在,则会失败。
该类的文档由以下文件生成: