QcSaveFile Namespace
The binary save file container shared by every world file except world.json: [magic][quint16 version][quint32 payload size][quint32 crc32][payload]. More...
| Header: | #include <server/storage/QcSaveFile.h> |
Classes
| struct | Payload |
Variables
| const quint16 | baseVersion |
| const int | maxDamagedCopies |
| const QDataStream::Version | streamVersion |
Functions
| QByteArray | bytes(QByteArrayView magic, const QByteArray &payload, quint16 version = baseVersion) |
| QString | keepAside(const QString &path) |
| QcResult<QcSaveFile::Payload> | parse(const QByteArray &data, const QString &path, QByteArrayView magic, quint16 newestVersion = baseVersion) |
| QcResult<QcSaveFile::Payload> | read(const QString &path, QByteArrayView magic, quint16 newestVersion = baseVersion) |
| QcStatus | write(const QString &path, QByteArrayView magic, const QByteArray &payload, quint16 version = baseVersion) |
| void | writeStack(QDataStream &stream, const QcItemStack &stack, const QcContentRegistry &content) |
Detailed Description
Readers accept every format version from baseVersion up to their current one.
Classes
class Payload
The payload of a file and its format version (at most the newest one the reader asked for). More...
Variable Documentation
const quint16 QcSaveFile::baseVersion
The first format version of every file.
const int QcSaveFile::maxDamagedCopies
Damaged copies kept aside per file at most (<path>.damaged, .damaged.2, …).
const QDataStream::Version QcSaveFile::streamVersion
The QDataStream version of every payload.
Function Documentation
QByteArray QcSaveFile::bytes(QByteArrayView magic, const QByteArray &payload, quint16 version = baseVersion)
Returns the bytes write() puts into a file for magic, payload and version.
QString QcSaveFile::keepAside(const QString &path)
Copies the damaged file path to the first free name <path>.damaged, .damaged.2, … (access.json). Returns that name, or empty when copying failed or all names are taken.
QcResult<QcSaveFile::Payload> QcSaveFile::parse(const QByteArray &data, const QString &path, QByteArrayView magic, quint16 newestVersion = baseVersion)
Returns the same for data, the bytes of a file (path names it in messages), with magic and newestVersion.
QcResult<QcSaveFile::Payload> QcSaveFile::read(const QString &path, QByteArrayView magic, quint16 newestVersion = baseVersion)
Returns the payload of the file path, which must start with magic and have a format from baseVersion to newestVersion and a matching checksum; an error otherwise.
QcStatus QcSaveFile::write(const QString &path, QByteArrayView magic, const QByteArray &payload, quint16 version = baseVersion)
Writes payload with magic and format version to path (replacing the file as a whole). Returns an error when it cannot be written.
void QcSaveFile::writeStack(QDataStream &stream, const QcItemStack &stack, const QcContentRegistry &content)
Writes stack to stream by item name (from content), count and damage, then its data (QcItemDataCodec); empty stacks and invalid items as an empty name.