47 void bytes(
const void*
data, std::uint64_t length)
noexcept {
49 if (length > std::numeric_limits<std::uint64_t>::max() -
position) {
58 static_cast<const std::byte*
>(
data)
59 +
static_cast<std::size_t
>(begin -
position),
60 static_cast<std::size_t
>(
finish - begin));
65 std::array<std::byte, 8>
bytes{};
66 for (
unsigned i = 0; i != 8; ++i)
67 bytes[i] =
static_cast<std::byte
>(
value >> (8 * i));
87 void bytes(
void* destination, std::size_t length)
noexcept {
94 auto* out =
static_cast<std::byte*
>(destination);
105 const auto count = std::min(length,
cached_size - at);
106 std::memcpy(out,
page.data + at, count);
112 void skip(std::uint64_t length)
noexcept {
117 std::uint64_t
word() noexcept {
118 std::array<std::byte, 8>
bytes{};
120 std::uint64_t
value = 0;
121 for (
unsigned i = 0; i != 8; ++i)
122 value |= std::uint64_t(std::to_integer<unsigned>(
bytes[i])) << (8 * i);
128 if (
value != std::byte{0} &&
value != std::byte{1})
130 return value == std::byte{1};
132 template<
class T>
void integer(T& out)
noexcept {
134 if constexpr (std::is_signed_v<T>) {
135 const auto maximum =
static_cast<std::uint64_t
>(std::numeric_limits<T>::max());
136 const auto minimum =
static_cast<std::uint64_t
>(std::numeric_limits<T>::min());
141 std::int64_t signed_value = 0;
142 std::memcpy(&signed_value, &
value,
sizeof value);
143 out =
static_cast<T
>(signed_value);
145 if (
value > std::numeric_limits<T>::max()) {
149 out =
static_cast<T
>(
value);
152 void real(
double& out)
noexcept {
156 void text(std::string& out,
bool owning) {
157 const auto length =
word();
159 if (length >
remaining() || length > out.max_size()) {
163 if (!owning) {
skip(length);
return; }
164 out.resize(
static_cast<std::size_t
>(length));
165 bytes(out.data(), out.size());
176 for (
unsigned i = 0; i != 8; ++i)
177 bytes_[i] =
static_cast<std::byte
>(
value >> (8 * i));
179 std::uint64_t
size() const noexcept
override {
return bytes_.size(); }
184 std::array<std::byte, 8> bytes_{};
190 std::uint64_t length) noexcept : store_(store), handle_(handle), length_(length) {
193 std::uint64_t
size() const noexcept
override {
return length_; }
195 return store_.carried_failure();
204 std::uint64_t length_;
211 auto status = store.lower_bound(probe, handle);
214 std::array<std::byte, 8> bytes{}, expected{};
217 probe.
read(0, {expected.data(), expected.size()});
219 return store.point(handle, out);
226 const auto rollback = store.rollback();
233 auto status = store.begin();
237 return finish(store, store.put(probe,
value, handle));
240 auto status = store.begin();
244 status = store.erase(handle);
ScratchStatus read(std::uint64_t offset, ScratchBuffer out) const noexcept override
StoreSource(const ScratchReadback &store, ScratchHandle handle, std::uint64_t length) noexcept
std::uint64_t size() const noexcept override
const ReportScratchIoError * carried_failure() const noexcept override
ScratchStatus read(std::uint64_t offset, ScratchBuffer out) const noexcept override
std::uint64_t size() const noexcept override
WordSource(std::uint64_t value) noexcept
const WorkObserver * set_work_observer(const WorkObserver *observer) noexcept
ScratchStatus find(CommandScratchStore &store, std::uint64_t key, ScratchRecordInfo &out) noexcept
thread_local const WorkObserver * work_observer
ScratchStatus finish(CommandScratchStore &store, ScratchStatus status) noexcept
ScratchStatus clear(CommandScratchStore &store) noexcept
void observe_work(WorkOperation operation, std::uint64_t bytes=0) noexcept
ScratchStatus put(CommandScratchStore &store, std::uint64_t key, const ScratchByteSource &value) noexcept
std::uint64_t ScratchHandle
constexpr ScratchHandle scratch_no_handle
void bytes(void *destination, std::size_t length) noexcept
void integer(T &out) noexcept
void text(std::string &out, bool owning)
ScratchStatus finish() const noexcept
void real(double &out) noexcept
std::uint64_t word() noexcept
std::uint64_t remaining() const noexcept
void skip(std::uint64_t length) noexcept
const ScratchByteSource & source
void(* observe)(void *, WorkOperation, std::uint64_t) noexcept
void bytes(const void *data, std::uint64_t length) noexcept
void word(std::uint64_t value) noexcept
ScratchStatus checked_status() const noexcept
void text(const std::string &value) noexcept
ScratchBuffer destination