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

这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能 更多...

#include <NBT_Writer.hpp>

静态 Public 成员函数

template<bool bSortCompound = true, typename OutputStream, typename InfoFunc = NBT_Print>
static bool WriteNBT (OutputStream &OptStream, const NBT_Type::Compound &tCompound, size_t szStackDepth=512, InfoFunc funcInfo=NBT_Print{}) noexcept
 将NBT_Type::Compound对象写入到输出流中
template<bool bSortCompound = 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=NBT_Print{}) noexcept
 将NBT_Type::Compound对象写入到数据容器中

详细描述

这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能

成员函数说明

◆ WriteNBT() [1/2]

template<bool bSortCompound = 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 = NBT_Print{} )
inlinestaticnoexcept

将NBT_Type::Compound对象写入到数据容器中

模板参数
bSortCompound是否对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<bool bSortCompound = true, typename OutputStream, typename InfoFunc = NBT_Print>
bool NBT_Writer::WriteNBT ( OutputStream & OptStream,
const NBT_Type::Compound & tCompound,
size_t szStackDepth = 512,
InfoFunc funcInfo = NBT_Print{} )
inlinestaticnoexcept

将NBT_Type::Compound对象写入到输出流中

模板参数
bSortCompound是否对Compound对象内部的键进行排序,以获得一致性的输出结果
OutputStream输出流类型,必须符合DefaultOutputStream类型的接口
InfoFunc信息输出仿函数类型
参数
[out]OptStream输出流对象
tCompound用于写出的对象
szStackDepth递归最大深度,防止栈溢出
funcInfo错误信息处理仿函数
返回
写入成功返回true,失败返回false
注解
错误与警告信息都输出到funcInfo,错误会导致函数结束剩下的写出任务,并进行栈回溯输出,最终返回false。警告则只会输出一次信息,然后继续执行,如果没有任何错误但是存在警告,函数仍将返回true。

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