#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
+#include <util/Bytes.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
#include <util/string.hpp>
std::get<std::string>(entry.data));
} else if (is_file_entry) {
const auto& path = std::get<std::string>(entry.data);
- const auto data = util::read_file<std::vector<uint8_t>>(path);
+ const auto data = util::read_file<util::Bytes>(path);
if (!data) {
throw Error(FMT("Failed to read {}: {}", path, data.error()));
}
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
+#include <util/Bytes.hpp>
#include <util/file.hpp>
#include <fcntl.h>
file_size));
}
- const auto data =
- util::read_file<std::vector<uint8_t>>(raw_file_path, file_size);
+ const auto data = util::read_file<util::Bytes>(raw_file_path, file_size);
if (!data) {
throw Error(FMT("Failed to read {}: {}", raw_file_path, data.error()));
}
#ifdef HAVE_REDIS_STORAGE_BACKEND
# include <storage/secondary/RedisStorage.hpp>
#endif
+#include <util/Bytes.hpp>
#include <util/Timer.hpp>
#include <util/Tokenizer.hpp>
#include <util/XXH3_64.hpp>
m_secondary_storages.end(),
[](const auto& entry) { return !entry->config.read_only; });
if (should_put_in_secondary_storage) {
- const auto value = util::read_file<std::vector<uint8_t>>(*path);
+ const auto value = util::read_file<util::Bytes>(*path);
if (!value) {
LOG("Failed to read {}: {}", *path, value.error());
return path; // Don't indicate failure since primary storage was OK.
m_secondary_storages.end(),
[](const auto& entry) { return !entry->config.read_only; });
if (should_put_in_secondary_storage) {
- const auto value = util::read_file<std::vector<uint8_t>>(*path);
+ const auto value = util::read_file<util::Bytes>(*path);
if (!value) {
LOG("Failed to read {}: {}", *path, value.error());
return true; // Don't indicate failure since primary storage was OK.
}
}
-std::optional<std::vector<uint8_t>>
+std::optional<util::Bytes>
Storage::get_from_secondary_storage(const Digest& key)
{
MTR_SCOPE("secondary_storage", "get");
void
Storage::put_in_secondary_storage(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing)
{
MTR_SCOPE("secondary_storage", "put");
#include <storage/secondary/SecondaryStorage.hpp>
#include <storage/types.hpp>
+#include <third_party/nonstd/span.hpp>
+
#include <functional>
#include <memory>
#include <optional>
std::string_view operation_description,
const bool for_writing);
- std::optional<std::vector<uint8_t>>
- get_from_secondary_storage(const Digest& key);
+ std::optional<util::Bytes> get_from_secondary_storage(const Digest& key);
void put_in_secondary_storage(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing);
void remove_from_secondary_storage(const Digest& key);
#include <assertions.hpp>
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
+#include <util/Bytes.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/string.hpp>
public:
FileStorageBackend(const Params& params);
- nonstd::expected<std::optional<std::vector<uint8_t>>, Failure>
+ nonstd::expected<std::optional<util::Bytes>, Failure>
get(const Digest& key) override;
nonstd::expected<bool, Failure> put(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing) override;
nonstd::expected<bool, Failure> remove(const Digest& key) override;
}
}
-nonstd::expected<std::optional<std::vector<uint8_t>>,
- SecondaryStorage::Backend::Failure>
+nonstd::expected<std::optional<util::Bytes>, SecondaryStorage::Backend::Failure>
FileStorageBackend::get(const Digest& key)
{
const auto path = get_entry_path(key);
util::set_timestamps(path);
}
- auto value = util::read_file<std::vector<uint8_t>>(path);
+ auto value = util::read_file<util::Bytes>(path);
if (!value) {
LOG("Failed to read {}: {}", path, value.error());
return nonstd::make_unexpected(Failure::error);
nonstd::expected<bool, SecondaryStorage::Backend::Failure>
FileStorageBackend::put(const Digest& key,
- const std::vector<uint8_t>& value,
+ const nonstd::span<const uint8_t> value,
const bool only_if_missing)
{
const auto path = get_entry_path(key);
public:
HttpStorageBackend(const Params& params);
- nonstd::expected<std::optional<std::vector<uint8_t>>, Failure>
+ nonstd::expected<std::optional<util::Bytes>, Failure>
get(const Digest& key) override;
nonstd::expected<bool, Failure> put(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing) override;
nonstd::expected<bool, Failure> remove(const Digest& key) override;
m_http_client.set_write_timeout(operation_timeout);
}
-nonstd::expected<std::optional<std::vector<uint8_t>>,
- SecondaryStorage::Backend::Failure>
+nonstd::expected<std::optional<util::Bytes>, SecondaryStorage::Backend::Failure>
HttpStorageBackend::get(const Digest& key)
{
const auto url_path = get_entry_path(key);
return std::nullopt;
}
- return std::vector<uint8_t>(result->body.begin(), result->body.end());
+ return util::Bytes(result->body.data(), result->body.size());
}
nonstd::expected<bool, SecondaryStorage::Backend::Failure>
HttpStorageBackend::put(const Digest& key,
- const std::vector<uint8_t>& value,
+ const nonstd::span<const uint8_t> value,
const bool only_if_missing)
{
const auto url_path = get_entry_path(key);
public:
RedisStorageBackend(const SecondaryStorage::Backend::Params& params);
- nonstd::expected<std::optional<std::vector<uint8_t>>, Failure>
+ nonstd::expected<std::optional<util::Bytes>, Failure>
get(const Digest& key) override;
nonstd::expected<bool, Failure> put(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing) override;
nonstd::expected<bool, Failure> remove(const Digest& key) override;
#endif
}
-nonstd::expected<std::optional<std::vector<uint8_t>>,
- SecondaryStorage::Backend::Failure>
+nonstd::expected<std::optional<util::Bytes>, SecondaryStorage::Backend::Failure>
RedisStorageBackend::get(const Digest& key)
{
const auto key_string = get_key_string(key);
if (!reply) {
return nonstd::make_unexpected(reply.error());
} else if ((*reply)->type == REDIS_REPLY_STRING) {
- return std::vector<uint8_t>((*reply)->str, (*reply)->str + (*reply)->len);
+ return util::Bytes((*reply)->str, (*reply)->len);
} else if ((*reply)->type == REDIS_REPLY_NIL) {
return std::nullopt;
} else {
nonstd::expected<bool, SecondaryStorage::Backend::Failure>
RedisStorageBackend::put(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing)
{
const auto key_string = get_key_string(key);
#pragma once
#include <storage/types.hpp>
+#include <util/Bytes.hpp>
#include <third_party/nonstd/expected.hpp>
+#include <third_party/nonstd/span.hpp>
#include <third_party/url.hpp>
#include <chrono>
// Get the value associated with `key`. Returns the value on success or
// std::nullopt if the entry is not present.
- virtual nonstd::expected<std::optional<std::vector<uint8_t>>, Failure>
+ virtual nonstd::expected<std::optional<util::Bytes>, Failure>
get(const Digest& key) = 0;
// Put `value` associated to `key` in the storage. A true `only_if_missing`
// Returns true if the entry was stored, otherwise false.
virtual nonstd::expected<bool, Failure>
put(const Digest& key,
- const std::vector<uint8_t>& value,
+ nonstd::span<const uint8_t> value,
bool only_if_missing = false) = 0;
// Remove `key` and its associated value. Returns true if the entry was