41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace ReloadableHost
|
|
{
|
|
inline constexpr std::uint32_t kCurrentCheckpointVersion{3};
|
|
|
|
/// Durable workflow state carried across releases.
|
|
struct CheckpointState {
|
|
std::uint64_t counter{0};
|
|
std::string workflow;
|
|
std::uint64_t generation{0};
|
|
};
|
|
|
|
struct CheckpointLimits {
|
|
std::size_t max_bytes{64ULL * 1024ULL};
|
|
std::size_t max_workflow_bytes{4ULL * 1024ULL};
|
|
};
|
|
|
|
/// Encode the current checkpoint schema (bounded).
|
|
[[nodiscard]] Void::Result::Result<std::vector<std::byte>>
|
|
encode_checkpoint(const CheckpointState& state,
|
|
CheckpointLimits limits = {});
|
|
|
|
/// Decode a supported checkpoint and migrate it to the current schema.
|
|
///
|
|
/// v1 (counter) and v2 (counter + workflow) are migrated forward with
|
|
/// defaults for fields they did not have. Corrupt magic, truncation,
|
|
/// oversized payloads and unknown newer versions are rejected.
|
|
[[nodiscard]] Void::Result::Result<CheckpointState>
|
|
decode_checkpoint(std::span<const std::byte> bytes,
|
|
CheckpointLimits limits = {});
|
|
} // namespace ReloadableHost
|