46 void bytes(
const void*
data, std::uint64_t length)
noexcept {
48 if (length > std::numeric_limits<std::uint64_t>::max() -
position) {
57 static_cast<const std::byte*
>(
data)
58 +
static_cast<std::size_t
>(begin -
position),
59 static_cast<std::size_t
>(
finish - begin));
64 std::array<std::byte, 8>
bytes{};
65 for (
unsigned i = 0; i != 8; ++i)
66 bytes[i] =
static_cast<std::byte
>(
value >> (8 * i));
86 void bytes(
void* destination, std::size_t length)
noexcept {
93 auto* out =
static_cast<std::byte*
>(destination);
104 const auto count = std::min(length,
cached_size - at);
105 std::memcpy(out,
page.data + at, count);
111 void skip(std::uint64_t length)
noexcept {
116 std::uint64_t
word() noexcept {
117 std::array<std::byte, 8>
bytes{};
119 std::uint64_t
value = 0;
120 for (
unsigned i = 0; i != 8; ++i)
121 value |= std::uint64_t(std::to_integer<unsigned>(
bytes[i])) << (8 * i);
127 if (
value != std::byte{0} &&
value != std::byte{1})
129 return value == std::byte{1};
131 template<
class T>
void integer(T& out)
noexcept {
133 if constexpr (std::is_signed_v<T>) {
134 const auto maximum =
static_cast<std::uint64_t
>(std::numeric_limits<T>::max());
135 const auto minimum =
static_cast<std::uint64_t
>(std::numeric_limits<T>::min());
140 std::int64_t signed_value = 0;
141 std::memcpy(&signed_value, &
value,
sizeof value);
142 out =
static_cast<T
>(signed_value);
144 if (
value > std::numeric_limits<T>::max()) {
148 out =
static_cast<T
>(
value);
151 void real(
double& out)
noexcept {
155 void text(std::string& out,
bool owning) {
156 const auto length =
word();
158 if (length >
remaining() || length > out.max_size()) {
162 if (!owning) {
skip(length);
return; }
163 out.resize(
static_cast<std::size_t
>(length));
164 bytes(out.data(), out.size());
175 for (
unsigned i = 0; i != 8; ++i)
176 bytes_[i] =
static_cast<std::byte
>(
value >> (8 * i));
178 std::uint64_t
size() const noexcept
override {
return bytes_.size(); }
183 std::array<std::byte, 8> bytes_{};
189 std::uint64_t length) noexcept : store_(store), handle_(handle), length_(length) {
192 std::uint64_t
size() const noexcept
override {
return length_; }
194 return store_.carried_failure();
203 std::uint64_t length_;
210 auto status = store.lower_bound(probe, handle);
213 std::array<std::byte, 8> bytes{}, expected{};
216 probe.
read(0, {expected.data(), expected.size()});
218 return store.point(handle, out);
225 const auto rollback = store.rollback();
232 auto status = store.begin();
236 return finish(store, store.put(probe,
value, handle));
239 auto status = store.begin();
243 status = store.erase(handle);
247 return finish(store, status);
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