这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能
更多...
#include <NBT_Writer.hpp>
|
| template<typename SortPolicy = DefaultCompoundSort<true>, typename OutputStream, typename InfoFunc = NBT_Print> |
| static bool | WriteNBT (OutputStream &OptStream, const NBT_Type::Compound &tCompound, size_t szStackDepth=512, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 将NBT_Type::Compound对象写入到输出流中
|
| template<typename SortPolicy = DefaultCompoundSort<true>, typename DataType = std::vector<uint8_t>, typename InfoFunc = NBT_Print> |
| static bool | WriteNBT (DataType &tDataOutput, size_t szStartIdx, const NBT_Type::Compound &tCompound, size_t szStackDepth=512, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 将NBT_Type::Compound对象写入到数据容器中
|
| template<typename InfoFunc = NBT_Print> |
| static bool | SimpleWriteNbtFile (const std::filesystem::path &pathFileName, const NBT_Type::Compound &tCompound, InfoFunc funcInfo=InfoFunc{}) noexcept |
| | 将 NBT_Type::Compound 对象以可能压缩的方式写入到文件中
|
这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能
◆ SimpleWriteNbtFile()
template<typename InfoFunc = NBT_Print>
| bool NBT_Writer::SimpleWriteNbtFile |
( |
const std::filesystem::path & | pathFileName, |
|
|
const NBT_Type::Compound & | tCompound, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
将 NBT_Type::Compound 对象以可能压缩的方式写入到文件中
- 模板参数
-
- 参数
-
| pathFileName | 目标文件路径 |
| tCompound | 用于写出的对象 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 写入成功返回 true,失败返回 false
- 注解
- 本函数会先调用 WriteNBT 将 Compound 序列化为二进制数据,然后尝试使用 Zlib 压缩(压缩级别 -1)。 若压缩失败,则直接写出未压缩的数据。最终将结果写入指定文件。如果文件已存在,会被覆盖,文件未存在则创建文件。
◆ WriteNBT() [1/2]
template<typename SortPolicy = DefaultCompoundSort<true>, typename DataType = std::vector<uint8_t>, typename InfoFunc = NBT_Print>
| bool NBT_Writer::WriteNBT |
( |
DataType & | tDataOutput, |
|
|
size_t | szStartIdx, |
|
|
const NBT_Type::Compound & | tCompound, |
|
|
size_t | szStackDepth = 512, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
将NBT_Type::Compound对象写入到数据容器中
- 模板参数
-
| SortPolicy | 用于进行Compound写出前排序的可调用类型,或不进行排序的提示标签类型 |
| DataType | 数据容器类型 |
| InfoFunc | 信息输出仿函数类型 |
- 参数
-
| [out] | tDataOutput | 输出数据容器 |
| szStartIdx | 数据起始索引,用于指定起始写入位置,设置为tDataOutput.size()则可以进行拼接,设置为0则清空容器 |
| tCompound | 用于写出的对象 |
| szStackDepth | 递归最大深度,防止栈溢出 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 写入成功返回true,失败返回false
- 注解
- 函数可以通过设置szStartIdx = tDataOutput.size(),把多个Compound对象的数据流合并到同一个tDataOutput对象内。如果多个对象中有重复、同名的NBT键, 虽然可以合并到流中,但是如果对这个流进行读取,读取例程为了保证在同一个Compound中的键的唯一性,会丢失部分信息,具体请参考ReadNBT接口的说明。 此函数是WriteNBT的标准库容器版本,其它信息请参考WriteNBT(OutputStream)版本的详细说明。
◆ WriteNBT() [2/2]
template<typename SortPolicy = DefaultCompoundSort<true>, typename OutputStream, typename InfoFunc = NBT_Print>
| bool NBT_Writer::WriteNBT |
( |
OutputStream & | OptStream, |
|
|
const NBT_Type::Compound & | tCompound, |
|
|
size_t | szStackDepth = 512, |
|
|
InfoFunc | funcInfo = InfoFunc{} ) |
|
inlinestaticnoexcept |
将NBT_Type::Compound对象写入到输出流中
- 模板参数
-
| SortPolicy | 用于进行Compound写出前排序的可调用类型,或不进行排序的提示标签类型 |
| OutputStream | 输出流类型,必须符合DefaultOutputStream类型的接口 |
| InfoFunc | 信息输出仿函数类型 |
- 参数
-
| [out] | OptStream | 输出流对象 |
| tCompound | 用于写出的对象 |
| szStackDepth | 递归最大深度,防止栈溢出 |
| funcInfo | 错误信息处理仿函数 |
- 返回
- 写入成功返回true,失败返回false
- 注解
- 错误与警告信息都输出到funcInfo,错误会导致函数结束剩下的写出任务,并进行栈回溯输出,最终返回false。警告则只会输出一次信息,然后继续执行,如果没有任何错误但是存在警告,函数仍将返回true。
该类的文档由以下文件生成: