coastline 0.0.4
Loading...
Searching...
No Matches
savefile.h File Reference
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <string_view>
#include <vector>
Include dependency graph for savefile.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  coastline::SaveFile
 An exclusive lock shared by cooperating save writers, released on destruction or process exit. More...

Namespaces

namespace  coastline

Typedefs

using coastline::SavePayloadValidator = std::function<bool(std::span<const std::uint8_t>)>
 Validate format-specific fields of an internal save's payload under its exclusive process lock.

Functions

std::optional< std::vector< std::uint8_t > > coastline::ReadSaveFile (const std::filesystem::path &path, std::size_t limit)
 Read a complete regular file without allocating beyond a caller-supplied limit.
bool coastline::WriteSaveFile (const std::filesystem::path &path, std::span< const std::uint8_t > bytes)
 Lock and atomically replace a binary save.
bool coastline::WriteSaveFile (const std::filesystem::path &path, std::string_view text)
 Lock and atomically replace a text save.
std::optional< std::vector< std::uint8_t > > coastline::ReadVerifiedSaveFile (const std::filesystem::path &path, std::size_t limit, bool resetInvalid=true, const SavePayloadValidator &validate={})
 Read an internal binary save with its format signature, payload length, and SHA-1 checksum.
bool coastline::WriteVerifiedSaveFile (const std::filesystem::path &path, std::span< const std::uint8_t > bytes)
 Atomically write an internal binary save with a format signature, length, and SHA-1 checksum.