pw_span: Switch from pw::span to std::span
Replace pw::span with std::span and "pw_span/span.h" with <span>
throughout the codebase.
Change-Id: Ib1fa873168b6093794e861611d750fcad6285d6c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/12801
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_kvs/alignment.cc b/pw_kvs/alignment.cc
index 081d6c8..198ec14 100644
--- a/pw_kvs/alignment.cc
+++ b/pw_kvs/alignment.cc
@@ -18,7 +18,7 @@
namespace pw {
-StatusWithSize AlignedWriter::Write(span<const std::byte> data) {
+StatusWithSize AlignedWriter::Write(std::span<const std::byte> data) {
while (!data.empty()) {
size_t to_copy = std::min(write_size_ - bytes_in_buffer_, data.size());
diff --git a/pw_kvs/alignment_test.cc b/pw_kvs/alignment_test.cc
index 2b25e94..0f3dc89 100644
--- a/pw_kvs/alignment_test.cc
+++ b/pw_kvs/alignment_test.cc
@@ -125,11 +125,11 @@
"123456789_123456789_123456789_123456789_123456789_" // 50
"123456789_123456789_123456789_123456789_123456789_"; // 100
-const span<const byte> kBytes = as_bytes(span(kData));
+const std::span<const byte> kBytes = std::as_bytes(std::span(kData));
// The output function checks that the data is properly aligned and matches
// the expected value (should always be 123456789_...).
-OutputToFunction check_against_data([](span<const byte> data) {
+OutputToFunction check_against_data([](std::span<const byte> data) {
EXPECT_EQ(data.size() % kAlignment, 0u);
EXPECT_EQ(kData.substr(0, data.size()),
std::string_view(reinterpret_cast<const char*>(data.data()),
@@ -168,14 +168,14 @@
static size_t called_with_bytes;
called_with_bytes = 0;
- OutputToFunction output([](span<const byte> data) {
+ OutputToFunction output([](std::span<const byte> data) {
called_with_bytes += data.size();
return StatusWithSize(data.size());
});
{
AlignedWriterBuffer<64> writer(3, output);
- writer.Write(as_bytes(span("What is this?")));
+ writer.Write(std::as_bytes(std::span("What is this?")));
EXPECT_EQ(called_with_bytes, 0u); // Buffer not full; no output yet.
}
@@ -191,7 +191,7 @@
enum { kKeepGoing, kBreakOnNext, kBroken } state = kKeepGoing;
private:
- StatusWithSize DoWrite(span<const byte> data) override {
+ StatusWithSize DoWrite(std::span<const byte> data) override {
switch (state) {
case kKeepGoing:
return StatusWithSize(data.size());
@@ -211,10 +211,11 @@
{
AlignedWriterBuffer<4> writer(3, output);
- writer.Write(as_bytes(span("Everything is fine.")));
+ writer.Write(std::as_bytes(std::span("Everything is fine.")));
output.state = OutputWithErrorInjection::kBreakOnNext;
EXPECT_EQ(Status::UNKNOWN,
- writer.Write(as_bytes(span("No more writes, okay?"))).status());
+ writer.Write(std::as_bytes(std::span("No more writes, okay?")))
+ .status());
writer.Flush();
}
}
@@ -223,34 +224,36 @@
static Status return_status;
return_status = Status::OK;
- OutputToFunction output([](span<const byte> data) {
+ OutputToFunction output([](std::span<const byte> data) {
return StatusWithSize(return_status, data.size());
});
AlignedWriterBuffer<22> writer(10, output);
- StatusWithSize result = writer.Write(as_bytes(span("12345678901"sv)));
+ StatusWithSize result =
+ writer.Write(std::as_bytes(std::span("12345678901"sv)));
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(0u, result.size()); // No writes; haven't filled buffer.
- result = writer.Write(as_bytes(span("2345678901"sv)));
+ result = writer.Write(std::as_bytes(std::span("2345678901"sv)));
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(20u, result.size());
return_status = Status::PERMISSION_DENIED;
- result = writer.Write(as_bytes(span("2345678901234567890"sv)));
+ result = writer.Write(std::as_bytes(std::span("2345678901234567890"sv)));
EXPECT_EQ(Status::PERMISSION_DENIED, result.status());
EXPECT_EQ(40u, result.size());
}
TEST(AlignedWriter, Flush_Ok_ReturnsTotalBytesWritten) {
OutputToFunction output(
- [](span<const byte> data) { return StatusWithSize(data.size()); });
+ [](std::span<const byte> data) { return StatusWithSize(data.size()); });
AlignedWriterBuffer<4> writer(2, output);
- EXPECT_EQ(Status::OK, writer.Write(as_bytes(span("12345678901"sv))).status());
+ EXPECT_EQ(Status::OK,
+ writer.Write(std::as_bytes(std::span("12345678901"sv))).status());
StatusWithSize result = writer.Flush();
EXPECT_EQ(Status::OK, result.status());
@@ -258,13 +261,13 @@
}
TEST(AlignedWriter, Flush_Error_ReturnsTotalBytesWritten) {
- OutputToFunction output([](span<const byte> data) {
+ OutputToFunction output([](std::span<const byte> data) {
return StatusWithSize(Status::ABORTED, data.size());
});
AlignedWriterBuffer<20> writer(10, output);
- EXPECT_EQ(0u, writer.Write(as_bytes(span("12345678901"sv))).size());
+ EXPECT_EQ(0u, writer.Write(std::as_bytes(std::span("12345678901"sv))).size());
StatusWithSize result = writer.Flush();
EXPECT_EQ(Status::ABORTED, result.status());
@@ -277,7 +280,7 @@
void BreakOnIndex(size_t index) { break_on_index_ = index; }
private:
- StatusWithSize DoRead(span<byte> data) override {
+ StatusWithSize DoRead(std::span<byte> data) override {
EXPECT_LE(index_ + data.size(), kBytes.size());
if (index_ + data.size() > kBytes.size()) {
diff --git a/pw_kvs/checksum.cc b/pw_kvs/checksum.cc
index f5db069..0a885f7 100644
--- a/pw_kvs/checksum.cc
+++ b/pw_kvs/checksum.cc
@@ -20,7 +20,7 @@
using std::byte;
-Status ChecksumAlgorithm::Verify(span<const byte> checksum) const {
+Status ChecksumAlgorithm::Verify(std::span<const byte> checksum) const {
if (checksum.size() < size_bytes()) {
return Status::INVALID_ARGUMENT;
}
diff --git a/pw_kvs/checksum_test.cc b/pw_kvs/checksum_test.cc
index 4f0d8c5..0db5ed2 100644
--- a/pw_kvs/checksum_test.cc
+++ b/pw_kvs/checksum_test.cc
@@ -32,19 +32,20 @@
ChecksumAlgorithm& algo = crc16_algo;
algo.Update(kString.data(), kString.size());
- EXPECT_EQ(Status::OK, algo.Verify(as_bytes(span(&kStringCrc, 1))));
+ EXPECT_EQ(Status::OK, algo.Verify(std::as_bytes(std::span(&kStringCrc, 1))));
}
TEST(Checksum, Verify_Failure) {
ChecksumCrc16 algo;
- EXPECT_EQ(Status::DATA_LOSS, algo.Verify(as_bytes(span(kString.data(), 2))));
+ EXPECT_EQ(Status::DATA_LOSS,
+ algo.Verify(std::as_bytes(std::span(kString.data(), 2))));
}
TEST(Checksum, Verify_InvalidSize) {
ChecksumCrc16 algo;
EXPECT_EQ(Status::INVALID_ARGUMENT, algo.Verify({}));
EXPECT_EQ(Status::INVALID_ARGUMENT,
- algo.Verify(as_bytes(span(kString.substr(0, 1)))));
+ algo.Verify(std::as_bytes(std::span(kString.substr(0, 1)))));
}
TEST(Checksum, Verify_LargerState_ComparesToTruncatedData) {
@@ -52,17 +53,17 @@
ChecksumCrc16 algo;
ASSERT_GT(sizeof(crc), algo.size_bytes());
- algo.Update(as_bytes(span(kString)));
+ algo.Update(std::as_bytes(std::span(kString)));
EXPECT_EQ(Status::OK, algo.Verify(crc));
}
TEST(Checksum, Reset) {
ChecksumCrc16 crc_algo;
- crc_algo.Update(as_bytes(span(kString)));
+ crc_algo.Update(std::as_bytes(std::span(kString)));
crc_algo.Reset();
- span state = crc_algo.Finish();
+ std::span state = crc_algo.Finish();
EXPECT_EQ(state[0], byte{0xFF});
EXPECT_EQ(state[1], byte{0xFF});
}
@@ -76,13 +77,13 @@
TEST(IgnoreChecksum, NeverUpdate_VerifyWithData) {
IgnoreChecksum checksum;
- EXPECT_EQ(Status::OK, checksum.Verify(as_bytes(span(kString))));
+ EXPECT_EQ(Status::OK, checksum.Verify(std::as_bytes(std::span(kString))));
}
TEST(IgnoreChecksum, AfterUpdate_Verify) {
IgnoreChecksum checksum;
- checksum.Update(as_bytes(span(kString)));
+ checksum.Update(std::as_bytes(std::span(kString)));
EXPECT_EQ(Status::OK, checksum.Verify({}));
}
@@ -91,7 +92,7 @@
constexpr std::string_view kData =
"123456789_123456789_123456789_123456789_123456789_" // 50
"123456789_123456789_123456789_123456789_123456789_"; // 100
-const span<const byte> kBytes = as_bytes(span(kData));
+const std::span<const byte> kBytes = std::as_bytes(std::span(kData));
class PickyChecksum final : public AlignedChecksum<kAlignment, 32> {
public:
@@ -101,7 +102,7 @@
void FinalizeAligned() override { EXPECT_EQ(kData.size(), size_); }
- void UpdateAligned(span<const std::byte> data) override {
+ void UpdateAligned(std::span<const std::byte> data) override {
ASSERT_EQ(data.size() % kAlignment, 0u);
EXPECT_EQ(kData.substr(0, data.size()),
std::string_view(reinterpret_cast<const char*>(data.data()),
diff --git a/pw_kvs/entry.cc b/pw_kvs/entry.cc
index 801a636..3343548 100644
--- a/pw_kvs/entry.cc
+++ b/pw_kvs/entry.cc
@@ -34,7 +34,7 @@
EntryHeader header;
TRY(partition.Read(address, sizeof(header), &header));
- if (partition.AppearsErased(as_bytes(span(&header.magic, 1)))) {
+ if (partition.AppearsErased(std::as_bytes(std::span(&header.magic, 1)))) {
return Status::NOT_FOUND;
}
if (header.key_length_bytes > kMaxKeyLength) {
@@ -69,7 +69,7 @@
Address address,
const EntryFormat& format,
string_view key,
- span<const byte> value,
+ std::span<const byte> value,
uint16_t value_size_bytes,
uint32_t transaction_id)
: Entry(&partition,
@@ -83,19 +83,21 @@
.value_size_bytes = value_size_bytes,
.transaction_id = transaction_id}) {
if (checksum_algo_ != nullptr) {
- span<const byte> checksum = CalculateChecksum(key, value);
+ std::span<const byte> checksum = CalculateChecksum(key, value);
std::memcpy(&header_.checksum,
checksum.data(),
std::min(checksum.size(), sizeof(header_.checksum)));
}
}
-StatusWithSize Entry::Write(string_view key, span<const byte> value) const {
+StatusWithSize Entry::Write(string_view key,
+ std::span<const byte> value) const {
FlashPartition::Output flash(partition(), address_);
- return AlignedWrite<64>(
- flash,
- alignment_bytes(),
- {as_bytes(span(&header_, 1)), as_bytes(span(key)), value});
+ return AlignedWrite<64>(flash,
+ alignment_bytes(),
+ {std::as_bytes(std::span(&header_, 1)),
+ std::as_bytes(std::span(key)),
+ value});
}
Status Entry::Update(const EntryFormat& new_format,
@@ -132,7 +134,8 @@
return writer.Flush();
}
-StatusWithSize Entry::ReadValue(span<byte> buffer, size_t offset_bytes) const {
+StatusWithSize Entry::ReadValue(std::span<byte> buffer,
+ size_t offset_bytes) const {
if (offset_bytes > value_size()) {
return StatusWithSize::OUT_OF_RANGE;
}
@@ -151,7 +154,7 @@
return StatusWithSize(read_size);
}
-Status Entry::ValueMatches(span<const std::byte> value) const {
+Status Entry::ValueMatches(std::span<const std::byte> value) const {
if (value_size() != value.size_bytes()) {
return Status::NOT_FOUND;
}
@@ -163,7 +166,7 @@
std::array<std::byte, 2 * kMinAlignmentBytes> buffer;
while (address < end) {
const size_t read_size = std::min(size_t(end - address), buffer.size());
- TRY(partition_->Read(address, span(buffer).first(read_size)));
+ TRY(partition_->Read(address, std::span(buffer).first(read_size)));
if (std::memcmp(buffer.data(), value_ptr, read_size) != 0) {
return Status::NOT_FOUND;
@@ -176,7 +179,8 @@
return Status::OK;
}
-Status Entry::VerifyChecksum(string_view key, span<const byte> value) const {
+Status Entry::VerifyChecksum(string_view key,
+ std::span<const byte> value) const {
if (checksum_algo_ == nullptr) {
return header_.checksum == 0 ? Status::OK : Status::DATA_LOSS;
}
@@ -247,8 +251,8 @@
PW_LOG_DEBUG(" Alignment = 0x%x", unsigned(alignment_bytes()));
}
-span<const byte> Entry::CalculateChecksum(const string_view key,
- span<const byte> value) const {
+std::span<const byte> Entry::CalculateChecksum(
+ const string_view key, std::span<const byte> value) const {
checksum_algo_->Reset();
{
@@ -256,7 +260,7 @@
header_for_checksum.checksum = 0;
checksum_algo_->Update(&header_for_checksum, sizeof(header_for_checksum));
- checksum_algo_->Update(as_bytes(span(key)));
+ checksum_algo_->Update(std::as_bytes(std::span(key)));
checksum_algo_->Update(value);
}
@@ -283,7 +287,7 @@
std::array<std::byte, 2 * kMinAlignmentBytes> buffer;
while (address < end) {
const size_t read_size = std::min(size_t(end - address), buffer.size());
- TRY(partition_->Read(address, span(buffer).first(read_size)));
+ TRY(partition_->Read(address, std::span(buffer).first(read_size)));
checksum_algo_->Update(buffer.data(), read_size);
address += read_size;
@@ -291,7 +295,7 @@
AddPaddingBytesToChecksum();
- span checksum = checksum_algo_->Finish();
+ std::span checksum = checksum_algo_->Finish();
std::memcpy(&header_.checksum,
checksum.data(),
std::min(checksum.size(), sizeof(header_.checksum)));
diff --git a/pw_kvs/entry_cache.cc b/pw_kvs/entry_cache.cc
index 599ae80..116f27f 100644
--- a/pw_kvs/entry_cache.cc
+++ b/pw_kvs/entry_cache.cc
@@ -44,7 +44,7 @@
// Remove the back entry of the address list.
addresses_.back() = kNoAddress;
- addresses_ = span(addresses_.begin(), addresses_.size() - 1);
+ addresses_ = std::span(addresses_.begin(), addresses_.size() - 1);
break;
}
}
@@ -123,7 +123,7 @@
// TODO(hepler): DCHECK(!full());
Address* first_address = ResetAddresses(descriptors_.size(), entry_address);
descriptors_.push_back(descriptor);
- return EntryMetadata(descriptors_.back(), span(first_address, 1));
+ return EntryMetadata(descriptors_.back(), std::span(first_address, 1));
}
// TODO: This method is the trigger of the O(valid_entries * all_entries) time
@@ -214,7 +214,8 @@
}
}
-span<EntryCache::Address> EntryCache::addresses(size_t descriptor_index) const {
+std::span<EntryCache::Address> EntryCache::addresses(
+ size_t descriptor_index) const {
Address* const addresses = first_address(descriptor_index);
size_t size = 0;
@@ -222,7 +223,7 @@
size += 1;
}
- return span(addresses, size);
+ return std::span(addresses, size);
}
EntryCache::Address* EntryCache::ResetAddresses(size_t descriptor_index,
diff --git a/pw_kvs/entry_test.cc b/pw_kvs/entry_test.cc
index 553ed52..d250039 100644
--- a/pw_kvs/entry_test.cc
+++ b/pw_kvs/entry_test.cc
@@ -14,6 +14,7 @@
#include "pw_kvs/internal/entry.h"
+#include <span>
#include <string_view>
#include "gtest/gtest.h"
@@ -24,7 +25,6 @@
#include "pw_kvs/flash_memory.h"
#include "pw_kvs/format.h"
#include "pw_kvs_private/byte_utils.h"
-#include "pw_span/span.h"
namespace pw::kvs::internal {
namespace {
@@ -58,8 +58,8 @@
FakeFlashMemoryBuffer<64, 2> flash(16);
FlashPartition partition(&flash, 0, flash.sector_count());
- auto entry =
- Entry::Valid(partition, 1, kFormat, "k", as_bytes(span("123")), 9876);
+ auto entry = Entry::Valid(
+ partition, 1, kFormat, "k", std::as_bytes(std::span("123")), 9876);
EXPECT_FALSE(entry.deleted());
EXPECT_EQ(entry.magic(), kFormat.magic);
@@ -138,7 +138,7 @@
TEST_F(ValidEntryInFlash, ReadValue) {
char value[32] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)));
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)));
ASSERT_EQ(Status::OK, result.status());
EXPECT_EQ(result.size(), entry_.value_size());
@@ -147,7 +147,7 @@
TEST_F(ValidEntryInFlash, ReadValue_BufferTooSmall) {
char value[3] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)));
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)));
ASSERT_EQ(Status::RESOURCE_EXHAUSTED, result.status());
EXPECT_EQ(3u, result.size());
@@ -158,7 +158,7 @@
TEST_F(ValidEntryInFlash, ReadValue_WithOffset) {
char value[3] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)), 3);
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)), 3);
ASSERT_EQ(Status::OK, result.status());
EXPECT_EQ(3u, result.size());
@@ -169,7 +169,7 @@
TEST_F(ValidEntryInFlash, ReadValue_WithOffset_BufferTooSmall) {
char value[1] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)), 4);
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)), 4);
ASSERT_EQ(Status::RESOURCE_EXHAUSTED, result.status());
EXPECT_EQ(1u, result.size());
@@ -178,7 +178,7 @@
TEST_F(ValidEntryInFlash, ReadValue_WithOffset_EmptyRead) {
char value[16] = {'?'};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)), 6);
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)), 6);
ASSERT_EQ(Status::OK, result.status());
EXPECT_EQ(0u, result.size());
@@ -187,7 +187,7 @@
TEST_F(ValidEntryInFlash, ReadValue_WithOffset_PastEnd) {
char value[16] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)), 7);
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)), 7);
EXPECT_EQ(Status::OUT_OF_RANGE, result.status());
EXPECT_EQ(0u, result.size());
@@ -254,7 +254,7 @@
TEST_F(TombstoneEntryInFlash, ReadValue) {
char value[32] = {};
- auto result = entry_.ReadValue(as_writable_bytes(span(value)));
+ auto result = entry_.ReadValue(std::as_writable_bytes(std::span(value)));
ASSERT_EQ(Status::OK, result.status());
EXPECT_EQ(0u, result.size());
@@ -366,7 +366,7 @@
EXPECT_EQ(0u, result.size());
}
-constexpr uint32_t ByteSum(span<const byte> bytes, uint32_t value = 0) {
+constexpr uint32_t ByteSum(std::span<const byte> bytes, uint32_t value = 0) {
for (byte b : bytes) {
value += unsigned(b);
}
@@ -376,11 +376,12 @@
// Sums the bytes, adding one to each byte so that zeroes change the checksum.
class ChecksumSummation final : public ChecksumAlgorithm {
public:
- ChecksumSummation() : ChecksumAlgorithm(as_bytes(span(&sum_, 1))), sum_(0) {}
+ ChecksumSummation()
+ : ChecksumAlgorithm(std::as_bytes(std::span(&sum_, 1))), sum_(0) {}
void Reset() override { sum_ = 0; }
- void Update(span<const byte> data) override {
+ void Update(std::span<const byte> data) override {
for (byte b : data) {
sum_ += unsigned(b) + 1; // Add 1 so zero-value bytes affect checksum.
}
diff --git a/pw_kvs/fake_flash_memory.cc b/pw_kvs/fake_flash_memory.cc
index 95987f3..39f5590 100644
--- a/pw_kvs/fake_flash_memory.cc
+++ b/pw_kvs/fake_flash_memory.cc
@@ -20,7 +20,7 @@
namespace pw::kvs {
-Status FlashError::Check(span<FlashError> errors,
+Status FlashError::Check(std::span<FlashError> errors,
FlashMemory::Address address,
size_t size) {
for (auto& error : errors) {
@@ -77,7 +77,8 @@
return Status::OK;
}
-StatusWithSize FakeFlashMemory::Read(Address address, span<std::byte> output) {
+StatusWithSize FakeFlashMemory::Read(Address address,
+ std::span<std::byte> output) {
if (address + output.size() >= sector_count() * size_bytes()) {
return StatusWithSize::OUT_OF_RANGE;
}
@@ -89,7 +90,7 @@
}
StatusWithSize FakeFlashMemory::Write(Address address,
- span<const std::byte> data) {
+ std::span<const std::byte> data) {
if (address % alignment_bytes() != 0 ||
data.size() % alignment_bytes() != 0) {
PW_LOG_ERROR("Unaligned write; address %x, size %u B, alignment %u",
diff --git a/pw_kvs/flash_memory.cc b/pw_kvs/flash_memory.cc
index 242f13e..30af38f 100644
--- a/pw_kvs/flash_memory.cc
+++ b/pw_kvs/flash_memory.cc
@@ -28,13 +28,13 @@
using std::byte;
-StatusWithSize FlashPartition::Output::DoWrite(span<const byte> data) {
+StatusWithSize FlashPartition::Output::DoWrite(std::span<const byte> data) {
TRY_WITH_SIZE(flash_.Write(address_, data));
address_ += data.size();
return StatusWithSize(data.size());
}
-StatusWithSize FlashPartition::Input::DoRead(span<byte> data) {
+StatusWithSize FlashPartition::Input::DoRead(std::span<byte> data) {
StatusWithSize result = flash_.Read(address_, data);
address_ += result.size();
return result;
@@ -49,12 +49,13 @@
return flash_.Erase(PartitionToFlashAddress(address), num_sectors);
}
-StatusWithSize FlashPartition::Read(Address address, span<byte> output) {
+StatusWithSize FlashPartition::Read(Address address, std::span<byte> output) {
TRY_WITH_SIZE(CheckBounds(address, output.size()));
return flash_.Read(PartitionToFlashAddress(address), output);
}
-StatusWithSize FlashPartition::Write(Address address, span<const byte> data) {
+StatusWithSize FlashPartition::Write(Address address,
+ std::span<const byte> data) {
if (permission_ == PartitionPermission::kReadOnly) {
return StatusWithSize::PERMISSION_DENIED;
}
@@ -102,7 +103,7 @@
return Status::OK;
}
-bool FlashPartition::AppearsErased(span<const byte> data) const {
+bool FlashPartition::AppearsErased(std::span<const byte> data) const {
for (byte b : data) {
if (b != flash_.erased_memory_content()) {
return false;
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 68a8412..a106592 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -39,7 +39,7 @@
} // namespace
KeyValueStore::KeyValueStore(FlashPartition* partition,
- span<const EntryFormat> formats,
+ std::span<const EntryFormat> formats,
const Options& options,
size_t redundancy,
Vector<SectorDescriptor>& sector_descriptor_list,
@@ -385,7 +385,7 @@
address += Entry::kMinAlignmentBytes) {
uint32_t magic;
StatusWithSize read_result =
- partition_.Read(address, as_writable_bytes(span(&magic, 1)));
+ partition_.Read(address, std::as_writable_bytes(std::span(&magic, 1)));
if (!read_result.ok()) {
continue;
}
@@ -400,7 +400,7 @@
}
StatusWithSize KeyValueStore::Get(string_view key,
- span<byte> value_buffer,
+ std::span<byte> value_buffer,
size_t offset_bytes) const {
TRY_WITH_SIZE(CheckReadOperation(key));
@@ -410,7 +410,7 @@
return Get(key, metadata, value_buffer, offset_bytes);
}
-Status KeyValueStore::PutBytes(string_view key, span<const byte> value) {
+Status KeyValueStore::PutBytes(string_view key, std::span<const byte> value) {
TRY(CheckWriteOperation(key));
DBG("Writing key/value; key length=%u, value length=%u",
unsigned(key.size()),
@@ -537,7 +537,7 @@
StatusWithSize KeyValueStore::Get(string_view key,
const EntryMetadata& metadata,
- span<std::byte> value_buffer,
+ std::span<std::byte> value_buffer,
size_t offset_bytes) const {
Entry entry;
@@ -584,7 +584,7 @@
}
StatusWithSize result =
- Get(key, metadata, span(static_cast<byte*>(value), size_bytes), 0);
+ Get(key, metadata, std::span(static_cast<byte*>(value), size_bytes), 0);
return result.status();
}
@@ -624,7 +624,7 @@
Status KeyValueStore::WriteEntryForExistingKey(EntryMetadata& metadata,
EntryState new_state,
string_view key,
- span<const byte> value) {
+ std::span<const byte> value) {
// Read the original entry to get the size for sector accounting purposes.
Entry entry;
TRY(ReadEntry(metadata, entry));
@@ -633,7 +633,7 @@
}
Status KeyValueStore::WriteEntryForNewKey(string_view key,
- span<const byte> value) {
+ std::span<const byte> value) {
if (entry_cache_.full()) {
WRN("KVS full: trying to store a new entry, but can't. Have %u entries",
unsigned(entry_cache_.total_entries()));
@@ -644,7 +644,7 @@
}
Status KeyValueStore::WriteEntry(string_view key,
- span<const byte> value,
+ std::span<const byte> value,
EntryState new_state,
EntryMetadata* prior_metadata,
const Entry* prior_entry) {
@@ -721,7 +721,7 @@
size_t write_size) {
for (size_t i = 0; i < redundancy(); i++) {
SectorDescriptor* sector;
- TRY(GetSectorForWrite(§or, write_size, span(write_addresses, i)));
+ TRY(GetSectorForWrite(§or, write_size, std::span(write_addresses, i)));
write_addresses[i] = sectors_.NextWritableAddress(*sector);
DBG("Found space for entry in sector %u at address %u",
@@ -739,7 +739,7 @@
// RESOURCE_EXHAUSTED: No sector available with the needed space.
Status KeyValueStore::GetSectorForWrite(SectorDescriptor** sector,
size_t entry_size,
- span<const Address> reserved) {
+ std::span<const Address> reserved) {
Status result = sectors_.FindSpace(sector, entry_size, reserved);
size_t gc_sector_count = 0;
@@ -793,7 +793,7 @@
Status KeyValueStore::AppendEntry(const Entry& entry,
string_view key,
- span<const byte> value) {
+ std::span<const byte> value) {
const StatusWithSize result = entry.Write(key, value);
SectorDescriptor& sector = sectors_.FromAddress(entry.address());
@@ -839,9 +839,10 @@
return result;
}
-Status KeyValueStore::RelocateEntry(const EntryMetadata& metadata,
- KeyValueStore::Address& address,
- span<const Address> reserved_addresses) {
+Status KeyValueStore::RelocateEntry(
+ const EntryMetadata& metadata,
+ KeyValueStore::Address& address,
+ std::span<const Address> reserved_addresses) {
Entry entry;
TRY(ReadEntry(metadata, entry));
@@ -937,10 +938,11 @@
if (error_detected_ && options_.recovery != ErrorRecovery::kManual) {
TRY(Repair());
}
- return GarbageCollect(span<const Address>());
+ return GarbageCollect(std::span<const Address>());
}
-Status KeyValueStore::GarbageCollect(span<const Address> reserved_addresses) {
+Status KeyValueStore::GarbageCollect(
+ std::span<const Address> reserved_addresses) {
DBG("Garbage Collect a single sector");
for (Address address : reserved_addresses) {
DBG(" Avoid address %u", unsigned(address));
@@ -962,7 +964,7 @@
Status KeyValueStore::RelocateKeyAddressesInSector(
SectorDescriptor& sector_to_gc,
const EntryMetadata& metadata,
- span<const Address> reserved_addresses) {
+ std::span<const Address> reserved_addresses) {
for (FlashPartition::Address& address : metadata.addresses()) {
if (sectors_.AddressInSector(sector_to_gc, address)) {
DBG(" Relocate entry for Key 0x%08" PRIx32 ", sector %u",
@@ -976,7 +978,8 @@
};
Status KeyValueStore::GarbageCollectSector(
- SectorDescriptor& sector_to_gc, span<const Address> reserved_addresses) {
+ SectorDescriptor& sector_to_gc,
+ std::span<const Address> reserved_addresses) {
DBG(" Garbage Collect sector %u", sectors_.Index(sector_to_gc));
// Step 1: Move any valid entries in the GC sector to other sectors
if (sector_to_gc.valid_bytes() != 0) {
@@ -1121,7 +1124,7 @@
}
if (empty_sector_found == false) {
DBG(" No empty sector found, attempting to GC a free sector");
- Status sector_status = GarbageCollect(span<const Address, 0>());
+ Status sector_status = GarbageCollect(std::span<const Address, 0>());
if (repair_status.ok() && !sector_status.ok()) {
DBG(" Unable to free an empty sector");
repair_status = sector_status;
@@ -1207,7 +1210,7 @@
KeyValueStore::Entry KeyValueStore::CreateEntry(Address address,
string_view key,
- span<const byte> value,
+ std::span<const byte> value,
EntryState state) {
// Always bump the transaction ID when creating a new entry.
//
diff --git a/pw_kvs/key_value_store_binary_format_test.cc b/pw_kvs/key_value_store_binary_format_test.cc
index 079396d..5921e82 100644
--- a/pw_kvs/key_value_store_binary_format_test.cc
+++ b/pw_kvs/key_value_store_binary_format_test.cc
@@ -33,7 +33,7 @@
constexpr size_t kMaxEntries = 256;
constexpr size_t kMaxUsableSectors = 256;
-constexpr uint32_t SimpleChecksum(span<const byte> data, uint32_t state) {
+constexpr uint32_t SimpleChecksum(std::span<const byte> data, uint32_t state) {
for (byte b : data) {
state += uint32_t(b);
}
@@ -43,18 +43,19 @@
template <typename State>
class ChecksumFunction final : public ChecksumAlgorithm {
public:
- ChecksumFunction(State (&algorithm)(span<const byte>, State))
- : ChecksumAlgorithm(as_bytes(span(&state_, 1))), algorithm_(algorithm) {}
+ ChecksumFunction(State (&algorithm)(std::span<const byte>, State))
+ : ChecksumAlgorithm(std::as_bytes(std::span(&state_, 1))),
+ algorithm_(algorithm) {}
void Reset() override { state_ = {}; }
- void Update(span<const byte> data) override {
+ void Update(std::span<const byte> data) override {
state_ = algorithm_(data, state_);
}
private:
State state_;
- State (&algorithm_)(span<const byte>, State);
+ State (&algorithm_)(std::span<const byte>, State);
};
ChecksumFunction<uint32_t> default_checksum(SimpleChecksum);
@@ -68,7 +69,8 @@
}
// Creates a buffer containing a valid entry at compile time.
-template <uint32_t (*kChecksum)(span<const byte>, uint32_t) = &SimpleChecksum,
+template <uint32_t (*kChecksum)(std::span<const byte>,
+ uint32_t) = &SimpleChecksum,
size_t kAlignmentBytes = sizeof(internal::EntryHeader),
size_t kKeyLengthWithNull,
size_t kValueSize>
@@ -85,7 +87,7 @@
uint16_t(kValueSize),
id,
ByteStr(key),
- span(value),
+ std::span(value),
EntryPadding<kAlignmentBytes, kKeyLength, kValueSize>());
// Calculate the checksum
@@ -99,7 +101,8 @@
}
// Creates a buffer containing a deleted entry at compile time.
-template <uint32_t (*kChecksum)(span<const byte>, uint32_t) = &SimpleChecksum,
+template <uint32_t (*kChecksum)(std::span<const byte>,
+ uint32_t) = &SimpleChecksum,
size_t kAlignmentBytes = sizeof(internal::EntryHeader),
size_t kKeyLengthWithNull>
constexpr auto MakeDeletedEntry(uint32_t magic,
@@ -166,7 +169,7 @@
partition_(&flash_),
kvs_(&partition_, default_format, kNoGcOptions) {}
- void InitFlashTo(span<const byte> contents) {
+ void InitFlashTo(std::span<const byte> contents) {
partition_.Erase();
std::memcpy(flash_.buffer().data(), contents.data(), contents.size());
}
@@ -329,7 +332,7 @@
EXPECT_EQ(1u, kvs_.size());
- auto result = kvs_.Get("my_key", as_writable_bytes(span(buffer)));
+ auto result = kvs_.Get("my_key", std::as_writable_bytes(std::span(buffer)));
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(sizeof("version 7") - 1, result.size());
EXPECT_STREQ("version 7", buffer);
@@ -346,7 +349,7 @@
EXPECT_EQ(Status::UNAVAILABLE, kvs_.Put("key1", ByteStr("value1")));
- EXPECT_EQ(Status::NOT_FOUND, kvs_.Get("key1", span<byte>()).status());
+ EXPECT_EQ(Status::NOT_FOUND, kvs_.Get("key1", std::span<byte>()).status());
ASSERT_TRUE(kvs_.empty());
auto stats = kvs_.GetStorageStats();
@@ -373,7 +376,7 @@
{.magic = kMagic, .checksum = &default_checksum},
kRecoveryNoGcOptions) {}
- void InitFlashTo(span<const byte> contents) {
+ void InitFlashTo(std::span<const byte> contents) {
partition_.Erase();
std::memcpy(flash_.buffer().data(), contents.data(), contents.size());
}
@@ -549,7 +552,7 @@
EXPECT_EQ(1u, kvs_.size());
- auto result = kvs_.Get("my_key", as_writable_bytes(span(buffer)));
+ auto result = kvs_.Get("my_key", std::as_writable_bytes(std::span(buffer)));
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(sizeof("version 7") - 1, result.size());
EXPECT_STREQ("version 7", buffer);
@@ -567,7 +570,7 @@
EXPECT_EQ(Status::UNAVAILABLE, kvs_.Put("key1", ByteStr("value1")));
EXPECT_EQ(true, kvs_.error_detected());
- EXPECT_EQ(Status::NOT_FOUND, kvs_.Get("key1", span<byte>()).status());
+ EXPECT_EQ(Status::NOT_FOUND, kvs_.Get("key1", std::span<byte>()).status());
ASSERT_TRUE(kvs_.empty());
auto stats = kvs_.GetStorageStats();
@@ -591,7 +594,7 @@
constexpr uint32_t kAltMagic = 0xbadD00D;
-constexpr uint32_t AltChecksum(span<const byte> data, uint32_t state) {
+constexpr uint32_t AltChecksum(std::span<const byte> data, uint32_t state) {
for (byte b : data) {
state = (state << 8) | uint32_t(byte(state >> 24) ^ b);
}
@@ -603,7 +606,7 @@
constexpr auto kAltEntry =
MakeValidEntry<AltChecksum>(kAltMagic, 32, "A Key", ByteStr("XD"));
-constexpr uint32_t NoChecksum(span<const byte>, uint32_t) { return 0; }
+constexpr uint32_t NoChecksum(std::span<const byte>, uint32_t) { return 0; }
constexpr uint32_t kNoChecksumMagic = 0x6000061e;
constexpr auto kNoChecksumEntry =
@@ -640,13 +643,14 @@
KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors, 2, 3> kvs_;
};
-#define ASSERT_CONTAINS_ENTRY(key, str_value) \
- do { \
- char val[sizeof(str_value)] = {}; \
- StatusWithSize stat = kvs_.Get(key, as_writable_bytes(span(val))); \
- ASSERT_EQ(Status::OK, stat.status()); \
- ASSERT_EQ(sizeof(str_value) - 1, stat.size()); \
- ASSERT_STREQ(str_value, val); \
+#define ASSERT_CONTAINS_ENTRY(key, str_value) \
+ do { \
+ char val[sizeof(str_value)] = {}; \
+ StatusWithSize stat = \
+ kvs_.Get(key, std::as_writable_bytes(std::span(val))); \
+ ASSERT_EQ(Status::OK, stat.status()); \
+ ASSERT_EQ(sizeof(str_value) - 1, stat.size()); \
+ ASSERT_STREQ(str_value, val); \
} while (0)
TEST_F(InitializedRedundantMultiMagicKvs, AllEntriesArePresent) {
@@ -756,8 +760,9 @@
EXPECT_EQ(stats.missing_redundant_entries_recovered, 0u);
char val[20] = {};
- EXPECT_EQ(Status::OK,
- kvs_.Get("new key", as_writable_bytes(span(val))).status());
+ EXPECT_EQ(
+ Status::OK,
+ kvs_.Get("new key", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::OK, kvs_.FullMaintenance());
stats = kvs_.GetStorageStats();
@@ -767,8 +772,9 @@
EXPECT_EQ(stats.corrupt_sectors_recovered, 0u);
EXPECT_EQ(stats.missing_redundant_entries_recovered, 0u);
- EXPECT_EQ(Status::OK,
- kvs_.Get("new key", as_writable_bytes(span(val))).status());
+ EXPECT_EQ(
+ Status::OK,
+ kvs_.Get("new key", std::as_writable_bytes(std::span(val))).status());
}
TEST_F(InitializedRedundantMultiMagicKvs, DataLossAfterLosingBothCopies) {
@@ -776,15 +782,15 @@
char val[20] = {};
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("key1", as_writable_bytes(span(val))).status());
+ kvs_.Get("key1", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("k2", as_writable_bytes(span(val))).status());
+ kvs_.Get("k2", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("k3y", as_writable_bytes(span(val))).status());
+ kvs_.Get("k3y", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("A Key", as_writable_bytes(span(val))).status());
+ kvs_.Get("A Key", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("kee", as_writable_bytes(span(val))).status());
+ kvs_.Get("kee", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(true, kvs_.error_detected());
@@ -820,13 +826,14 @@
ASSERT_CONTAINS_ENTRY("A Key", "New value!");
}
-#define ASSERT_KVS_CONTAINS_ENTRY(kvs, key, str_value) \
- do { \
- char val[sizeof(str_value)] = {}; \
- StatusWithSize stat = kvs.Get(key, as_writable_bytes(span(val))); \
- ASSERT_EQ(Status::OK, stat.status()); \
- ASSERT_EQ(sizeof(str_value) - 1, stat.size()); \
- ASSERT_STREQ(str_value, val); \
+#define ASSERT_KVS_CONTAINS_ENTRY(kvs, key, str_value) \
+ do { \
+ char val[sizeof(str_value)] = {}; \
+ StatusWithSize stat = \
+ kvs.Get(key, std::as_writable_bytes(std::span(val))); \
+ ASSERT_EQ(Status::OK, stat.status()); \
+ ASSERT_EQ(sizeof(str_value) - 1, stat.size()); \
+ ASSERT_STREQ(str_value, val); \
} while (0)
TEST_F(InitializedRedundantMultiMagicKvs, UpdateEntryFormat) {
@@ -932,13 +939,13 @@
char val[20] = {};
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("key1", as_writable_bytes(span(val))).status());
+ kvs_.Get("key1", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("k2", as_writable_bytes(span(val))).status());
+ kvs_.Get("k2", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("k3y", as_writable_bytes(span(val))).status());
+ kvs_.Get("k3y", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(Status::DATA_LOSS,
- kvs_.Get("4k", as_writable_bytes(span(val))).status());
+ kvs_.Get("4k", std::as_writable_bytes(std::span(val))).status());
EXPECT_EQ(true, kvs_.error_detected());
diff --git a/pw_kvs/key_value_store_fuzz_test.cc b/pw_kvs/key_value_store_fuzz_test.cc
index 8ef1ebc..2a34750 100644
--- a/pw_kvs/key_value_store_fuzz_test.cc
+++ b/pw_kvs/key_value_store_fuzz_test.cc
@@ -63,7 +63,7 @@
for (unsigned value_size = 0; value_size < sizeof(value); ++value_size) {
ASSERT_EQ(Status::OK,
kvs_.Put(std::string_view(value, key_size),
- as_bytes(span(value, value_size))));
+ std::as_bytes(std::span(value, value_size))));
}
}
}
diff --git a/pw_kvs/key_value_store_test.cc b/pw_kvs/key_value_store_test.cc
index 1333364..35840ef 100644
--- a/pw_kvs/key_value_store_test.cc
+++ b/pw_kvs/key_value_store_test.cc
@@ -21,6 +21,7 @@
#include <array>
#include <cstdio>
#include <cstring>
+#include <span>
#if DUMP_KVS_STATE_TO_FILE
#include <vector>
@@ -34,7 +35,6 @@
#include "pw_kvs_private/byte_utils.h"
#include "pw_kvs_private/macros.h"
#include "pw_log/log.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_string/string_builder.h"
@@ -76,7 +76,7 @@
static_assert(kAsBytesTest[14] == std::byte{0xff});
// Test that the ConvertsToSpan trait correctly idenitifies types that convert
-// to span.
+// to std::span.
static_assert(!ConvertsToSpan<int>());
static_assert(!ConvertsToSpan<void>());
static_assert(!ConvertsToSpan<std::byte>());
@@ -97,12 +97,12 @@
static_assert(ConvertsToSpan<char[35]>());
static_assert(ConvertsToSpan<const int[35]>());
-static_assert(ConvertsToSpan<span<int>>());
-static_assert(ConvertsToSpan<span<byte>>());
-static_assert(ConvertsToSpan<span<const int*>>());
-static_assert(ConvertsToSpan<span<bool>&&>());
-static_assert(ConvertsToSpan<const span<bool>&>());
-static_assert(ConvertsToSpan<span<bool>&&>());
+static_assert(ConvertsToSpan<std::span<int>>());
+static_assert(ConvertsToSpan<std::span<byte>>());
+static_assert(ConvertsToSpan<std::span<const int*>>());
+static_assert(ConvertsToSpan<std::span<bool>&&>());
+static_assert(ConvertsToSpan<const std::span<bool>&>());
+static_assert(ConvertsToSpan<std::span<bool>&&>());
// This is a self contained flash unit with both memory and a single partition.
template <uint32_t sector_size_bytes, uint16_t sector_count>
@@ -125,7 +125,7 @@
}
std::vector<std::byte> out_vec(memory.size_bytes());
Status status =
- memory.Read(0, pw::span<std::byte>(out_vec.data(), out_vec.size()));
+ memory.Read(0, std::span<std::byte>(out_vec.data(), out_vec.size()));
if (status != Status::OK) {
fclose(out_file);
return status;
@@ -233,9 +233,9 @@
buffer[0] = static_cast<byte>(static_cast<uint8_t>(buffer[0]) + 1);
ASSERT_EQ(Status::OK,
kvs_.Put(key,
- span(buffer.data(),
- chunk_len - kvs_attr.ChunkHeaderSize() -
- kvs_attr.KeySize())));
+ std::span(buffer.data(),
+ chunk_len - kvs_attr.ChunkHeaderSize() -
+ kvs_attr.KeySize())));
size_to_fill -= chunk_len;
chunk_len = std::min(size_to_fill, kMaxPutSize);
}
@@ -251,7 +251,8 @@
std::array<char, 8> value{'v', 'a', 'l', 'u', 'e', '6', '7', '\0'};
for (int i = 0; i < 1000; ++i) {
- ASSERT_EQ(Status::OK, kvs_.Put("The Key!", as_bytes(span(value))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("The Key!", std::as_bytes(std::span(value))));
}
}
@@ -259,7 +260,8 @@
std::array<char, 7> value{'v', 'a', 'l', 'u', 'e', '6', '\0'};
for (int i = 0; i < 1000; ++i) {
- ASSERT_EQ(Status::OK, kvs_.Put("The Key!", as_bytes(span(value))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("The Key!", std::as_bytes(std::span(value))));
}
}
@@ -279,7 +281,7 @@
// Use the large_test_flash as a big chunk of data for the Put statement.
ASSERT_GT(sizeof(large_test_flash), max_value_size + 2 * sizeof(EntryHeader));
- auto big_data = as_bytes(span(&large_test_flash, 1));
+ auto big_data = std::as_bytes(std::span(&large_test_flash, 1));
EXPECT_EQ(Status::OK, kvs_.Put("K", big_data.subspan(0, max_value_size)));
@@ -301,7 +303,7 @@
TEST_F(EmptyInitializedKvs, PutAndGetByValue_Span) {
float input[] = {1.0, -3.5};
- ASSERT_EQ(Status::OK, kvs_.Put("key", span(input)));
+ ASSERT_EQ(Status::OK, kvs_.Put("key", std::span(input)));
float output[2] = {};
ASSERT_EQ(Status::OK, kvs_.Get("key", &output));
@@ -325,41 +327,48 @@
}
TEST_F(EmptyInitializedKvs, Get_Simple) {
- ASSERT_EQ(Status::OK, kvs_.Put("Charles", as_bytes(span("Mingus"))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("Charles", std::as_bytes(std::span("Mingus"))));
char value[16];
- auto result = kvs_.Get("Charles", as_writable_bytes(span(value)));
+ auto result = kvs_.Get("Charles", std::as_writable_bytes(std::span(value)));
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(sizeof("Mingus"), result.size());
EXPECT_STREQ("Mingus", value);
}
TEST_F(EmptyInitializedKvs, Get_WithOffset) {
- ASSERT_EQ(Status::OK, kvs_.Put("Charles", as_bytes(span("Mingus"))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("Charles", std::as_bytes(std::span("Mingus"))));
char value[16];
- auto result = kvs_.Get("Charles", as_writable_bytes(span(value)), 4);
+ auto result =
+ kvs_.Get("Charles", std::as_writable_bytes(std::span(value)), 4);
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(sizeof("Mingus") - 4, result.size());
EXPECT_STREQ("us", value);
}
TEST_F(EmptyInitializedKvs, Get_WithOffset_FillBuffer) {
- ASSERT_EQ(Status::OK, kvs_.Put("Charles", as_bytes(span("Mingus"))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("Charles", std::as_bytes(std::span("Mingus"))));
char value[4] = {};
- auto result = kvs_.Get("Charles", as_writable_bytes(span(value, 3)), 1);
+ auto result =
+ kvs_.Get("Charles", std::as_writable_bytes(std::span(value, 3)), 1);
EXPECT_EQ(Status::RESOURCE_EXHAUSTED, result.status());
EXPECT_EQ(3u, result.size());
EXPECT_STREQ("ing", value);
}
TEST_F(EmptyInitializedKvs, Get_WithOffset_PastEnd) {
- ASSERT_EQ(Status::OK, kvs_.Put("Charles", as_bytes(span("Mingus"))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put("Charles", std::as_bytes(std::span("Mingus"))));
char value[16];
- auto result =
- kvs_.Get("Charles", as_writable_bytes(span(value)), sizeof("Mingus") + 1);
+ auto result = kvs_.Get("Charles",
+ std::as_writable_bytes(std::span(value)),
+ sizeof("Mingus") + 1);
EXPECT_EQ(Status::OUT_OF_RANGE, result.status());
EXPECT_EQ(0u, result.size());
}
@@ -389,7 +398,7 @@
}
TEST_F(EmptyInitializedKvs, Delete_GetDeletedKey_ReturnsNotFound) {
- ASSERT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("123"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("123"))));
ASSERT_EQ(Status::OK, kvs_.Delete("kEy"));
EXPECT_EQ(Status::NOT_FOUND, kvs_.Get("kEy", {}).status());
@@ -397,10 +406,10 @@
}
TEST_F(EmptyInitializedKvs, Delete_AddBackKey_PersistsAfterInitialization) {
- ASSERT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("123"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("123"))));
ASSERT_EQ(Status::OK, kvs_.Delete("kEy"));
- EXPECT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("45678"))));
+ EXPECT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("45678"))));
char data[6] = {};
ASSERT_EQ(Status::OK, kvs_.Get("kEy", &data));
EXPECT_STREQ(data, "45678");
@@ -410,14 +419,14 @@
default_format);
ASSERT_EQ(Status::OK, new_kvs.Init());
- EXPECT_EQ(Status::OK, new_kvs.Put("kEy", as_bytes(span("45678"))));
+ EXPECT_EQ(Status::OK, new_kvs.Put("kEy", std::as_bytes(std::span("45678"))));
char new_data[6] = {};
EXPECT_EQ(Status::OK, new_kvs.Get("kEy", &new_data));
EXPECT_STREQ(data, "45678");
}
TEST_F(EmptyInitializedKvs, Delete_AllItems_KvsIsEmpty) {
- ASSERT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("123"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("123"))));
ASSERT_EQ(Status::OK, kvs_.Delete("kEy"));
EXPECT_EQ(0u, kvs_.size());
@@ -476,7 +485,7 @@
}
TEST_F(EmptyInitializedKvs, Iteration_OneItem) {
- ASSERT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("123"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("123"))));
for (KeyValueStore::Item entry : kvs_) {
EXPECT_STREQ(entry.key(), "kEy"); // Make sure null-terminated.
@@ -488,11 +497,11 @@
}
TEST_F(EmptyInitializedKvs, Iteration_GetWithOffset) {
- ASSERT_EQ(Status::OK, kvs_.Put("key", as_bytes(span("not bad!"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("key", std::as_bytes(std::span("not bad!"))));
for (KeyValueStore::Item entry : kvs_) {
char temp[5];
- auto result = entry.Get(as_writable_bytes(span(temp)), 4);
+ auto result = entry.Get(std::as_writable_bytes(std::span(temp)), 4);
EXPECT_EQ(Status::OK, result.status());
EXPECT_EQ(5u, result.size());
EXPECT_STREQ("bad!", temp);
@@ -530,7 +539,7 @@
}
TEST_F(EmptyInitializedKvs, Iteration_EmptyAfterDeletion) {
- ASSERT_EQ(Status::OK, kvs_.Put("kEy", as_bytes(span("123"))));
+ ASSERT_EQ(Status::OK, kvs_.Put("kEy", std::as_bytes(std::span("123"))));
ASSERT_EQ(Status::OK, kvs_.Delete("kEy"));
for (KeyValueStore::Item entry : kvs_) {
@@ -570,9 +579,9 @@
}
// Delete and re-add everything
ASSERT_EQ(Status::OK, kvs_.Delete(key1));
- ASSERT_EQ(Status::OK, kvs_.Put(key1, span(buf1, size1)));
+ ASSERT_EQ(Status::OK, kvs_.Put(key1, std::span(buf1, size1)));
ASSERT_EQ(Status::OK, kvs_.Delete(key2));
- ASSERT_EQ(Status::OK, kvs_.Put(key2, span(buf2, size2)));
+ ASSERT_EQ(Status::OK, kvs_.Put(key2, std::span(buf2, size2)));
for (size_t j = 0; j < keys.size(); j++) {
ASSERT_EQ(Status::OK, kvs_.Delete(keys[j]));
ASSERT_EQ(Status::OK, kvs_.Put(keys[j], j));
@@ -581,9 +590,9 @@
// Re-enable and verify
ASSERT_EQ(Status::OK, kvs_.Init());
static byte buf[4 * 1024];
- ASSERT_EQ(Status::OK, kvs_.Get(key1, span(buf, size1)).status());
+ ASSERT_EQ(Status::OK, kvs_.Get(key1, std::span(buf, size1)).status());
ASSERT_EQ(std::memcmp(buf, buf1, size1), 0);
- ASSERT_EQ(Status::OK, kvs_.Get(key2, span(buf, size2)).status());
+ ASSERT_EQ(Status::OK, kvs_.Get(key2, std::span(buf, size2)).status());
ASSERT_EQ(std::memcmp(buf2, buf2, size2), 0);
for (size_t j = 0; j < keys.size(); j++) {
size_t ret = 1000;
@@ -596,8 +605,9 @@
TEST_F(EmptyInitializedKvs, Basic) {
// Add some data
uint8_t value1 = 0xDA;
- ASSERT_EQ(Status::OK,
- kvs_.Put(keys[0], as_bytes(span(&value1, sizeof(value1)))));
+ ASSERT_EQ(
+ Status::OK,
+ kvs_.Put(keys[0], std::as_bytes(std::span(&value1, sizeof(value1)))));
uint32_t value2 = 0xBAD0301f;
ASSERT_EQ(Status::OK, kvs_.Put(keys[1], value2));
@@ -617,10 +627,10 @@
// Verify it was erased
EXPECT_EQ(kvs_.Get(keys[0], &test1), Status::NOT_FOUND);
test2 = 0;
- ASSERT_EQ(
- Status::OK,
- kvs_.Get(keys[1], span(reinterpret_cast<byte*>(&test2), sizeof(test2)))
- .status());
+ ASSERT_EQ(Status::OK,
+ kvs_.Get(keys[1],
+ std::span(reinterpret_cast<byte*>(&test2), sizeof(test2)))
+ .status());
EXPECT_EQ(test2, value2);
// Delete other key
@@ -818,7 +828,7 @@
// Add two entries with different keys and values.
uint8_t value1 = 0xDA;
- ASSERT_OK(kvs.Put(key1, as_bytes(span(&value1, sizeof(value1)))));
+ ASSERT_OK(kvs.Put(key1, std::as_bytes(std::span(&value1, sizeof(value1)))));
EXPECT_EQ(kvs.size(), 1u);
uint32_t value2 = 0xBAD0301f;
@@ -996,20 +1006,22 @@
const uint8_t kValue1 = 0xDA;
const uint8_t kValue2 = 0x12;
const char* key = "the_key";
- ASSERT_EQ(Status::OK, kvs_.Put(key, as_bytes(span(&kValue1, 1))));
+ ASSERT_EQ(Status::OK, kvs_.Put(key, std::as_bytes(std::span(&kValue1, 1))));
// Verify
uint8_t value;
- ASSERT_EQ(Status::OK,
- kvs_.Get(key, as_writable_bytes(span(&value, 1))).status());
+ ASSERT_EQ(
+ Status::OK,
+ kvs_.Get(key, std::as_writable_bytes(std::span(&value, 1))).status());
EXPECT_EQ(kValue1, value);
// Write new value for key
- ASSERT_EQ(Status::OK, kvs_.Put(key, as_bytes(span(&kValue2, 1))));
+ ASSERT_EQ(Status::OK, kvs_.Put(key, std::as_bytes(std::span(&kValue2, 1))));
// Verify
- ASSERT_EQ(Status::OK,
- kvs_.Get(key, as_writable_bytes(span(&value, 1))).status());
+ ASSERT_EQ(
+ Status::OK,
+ kvs_.Get(key, std::as_writable_bytes(std::span(&value, 1))).status());
EXPECT_EQ(kValue2, value);
// Verify only 1 element exists
@@ -1035,11 +1047,11 @@
// the only entries in the env. The size of this initial entry
// we vary between no bytes to sizeof(set_buf).
ASSERT_EQ(Status::OK,
- kvs_.Put("const_entry", span(set_buf, test_iteration)));
+ kvs_.Put("const_entry", std::span(set_buf, test_iteration)));
// The value we read back should be the last value we set
std::memset(get_buf, 0, sizeof(get_buf));
- result = kvs_.Get("const_entry", span(get_buf));
+ result = kvs_.Get("const_entry", std::span(get_buf));
ASSERT_EQ(Status::OK, result.status());
ASSERT_EQ(result.size(), test_iteration);
for (size_t j = 0; j < test_iteration; j++) {
@@ -1053,10 +1065,11 @@
std::byte get_entry_buf[sizeof(set_entry_buf)];
for (size_t i = 0; i < 5; i++) {
set_entry[0] = static_cast<std::byte>(i);
- ASSERT_EQ(Status::OK,
- kvs_.Put("test_entry", span(set_entry, sizeof(set_entry_buf))));
+ ASSERT_EQ(
+ Status::OK,
+ kvs_.Put("test_entry", std::span(set_entry, sizeof(set_entry_buf))));
std::memset(get_entry_buf, 0, sizeof(get_entry_buf));
- result = kvs_.Get("test_entry", span(get_entry_buf));
+ result = kvs_.Get("test_entry", std::span(get_entry_buf));
ASSERT_TRUE(result.ok());
ASSERT_EQ(result.size(), sizeof(get_entry_buf));
for (uint32_t j = 0; j < sizeof(set_entry_buf); j++) {
@@ -1066,7 +1079,7 @@
// Check that the const entry is still present and has the right value
std::memset(get_buf, 0, sizeof(get_buf));
- result = kvs_.Get("const_entry", span(get_buf));
+ result = kvs_.Get("const_entry", std::span(get_buf));
ASSERT_TRUE(result.ok());
ASSERT_EQ(result.size(), test_iteration);
for (size_t j = 0; j < test_iteration; j++) {
@@ -1086,14 +1099,15 @@
for (size_t i = 0; i < kTestBufferSize; i++) {
buffer[i] = byte(i);
}
- ASSERT_EQ(Status::OK, kvs_.Put(key, span(buffer.data(), kTestBufferSize)));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put(key, std::span(buffer.data(), kTestBufferSize)));
EXPECT_EQ(kvs_.size(), 1u);
// Read in small chunks and verify
for (unsigned i = 0; i < kTestBufferSize / kReadSize; i++) {
std::memset(buffer.data(), 0, buffer.size());
StatusWithSize result =
- kvs_.Get(key, span(buffer.data(), kReadSize), i * kReadSize);
+ kvs_.Get(key, std::span(buffer.data(), kReadSize), i * kReadSize);
ASSERT_EQ(kReadSize, result.size());
@@ -1145,11 +1159,11 @@
std::memset(
buffer.data(), static_cast<int>(kKey0Pattern), kvs_attr.DataSize());
ASSERT_EQ(Status::OK,
- kvs_.Put(keys[0], span(buffer.data(), kvs_attr.DataSize())));
+ kvs_.Put(keys[0], std::span(buffer.data(), kvs_attr.DataSize())));
bytes_remaining -= kvs_attr.MinPutSize();
std::memset(buffer.data(), 1, kvs_attr.DataSize());
ASSERT_EQ(Status::OK,
- kvs_.Put(keys[2], span(buffer.data(), kvs_attr.DataSize())));
+ kvs_.Put(keys[2], std::span(buffer.data(), kvs_attr.DataSize())));
bytes_remaining -= kvs_attr.MinPutSize();
EXPECT_EQ(kvs_.size(), 2u);
ASSERT_EQ(Status::OK, kvs_.Delete(keys[2]));
@@ -1162,9 +1176,9 @@
// Verify key[0]
std::memset(buffer.data(), 0, kvs_attr.DataSize());
- ASSERT_EQ(
- Status::OK,
- kvs_.Get(keys[0], span(buffer.data(), kvs_attr.DataSize())).status());
+ ASSERT_EQ(Status::OK,
+ kvs_.Get(keys[0], std::span(buffer.data(), kvs_attr.DataSize()))
+ .status());
for (uint32_t i = 0; i < kvs_attr.DataSize(); i++) {
EXPECT_EQ(buffer[i], kKey0Pattern);
}
@@ -1178,7 +1192,8 @@
EXPECT_EQ(kvs_.size(), 1u);
ASSERT_EQ(Status::OK, kvs_.Delete(keys[0]));
EXPECT_EQ(kvs_.Get(keys[0], &value), Status::NOT_FOUND);
- ASSERT_EQ(Status::OK, kvs_.Put(keys[1], as_bytes(span(&kValue1, 1))));
+ ASSERT_EQ(Status::OK,
+ kvs_.Put(keys[1], std::as_bytes(std::span(&kValue1, 1))));
ASSERT_EQ(Status::OK, kvs_.Put(keys[2], kValue2));
ASSERT_EQ(Status::OK, kvs_.Delete(keys[1]));
EXPECT_EQ(Status::OK, kvs_.Get(keys[2], &value));
@@ -1264,15 +1279,16 @@
new_keyvalue_size -= kValueLessThanChunkHeaderSize;
std::memset(buffer.data(), static_cast<int>(kTestPattern), new_keyvalue_size);
ASSERT_EQ(Status::OK,
- kvs_.Put(kNewKey, span(buffer.data(), new_keyvalue_size)));
+ kvs_.Put(kNewKey, std::span(buffer.data(), new_keyvalue_size)));
// In failed corner case, adding new key is deceptively successful. It isn't
// until KVS is disabled and reenabled that issue can be detected.
ASSERT_EQ(Status::OK, kvs_.Init());
// Might as well check that new key-value is what we expect it to be
- ASSERT_EQ(Status::OK,
- kvs_.Get(kNewKey, span(buffer.data(), new_keyvalue_size)).status());
+ ASSERT_EQ(
+ Status::OK,
+ kvs_.Get(kNewKey, std::span(buffer.data(), new_keyvalue_size)).status());
for (size_t i = 0; i < new_keyvalue_size; i++) {
EXPECT_EQ(buffer[i], kTestPattern);
}
@@ -1289,7 +1305,7 @@
}
TEST_F(EmptyInitializedKvs, ValueSize_Zero) {
- ASSERT_EQ(Status::OK, kvs_.Put("TheKey", as_bytes(span("123", 3))));
+ ASSERT_EQ(Status::OK, kvs_.Put("TheKey", std::as_bytes(std::span("123", 3))));
auto result = kvs_.ValueSize("TheKey");
EXPECT_EQ(Status::OK, result.status());
@@ -1305,7 +1321,7 @@
}
TEST_F(EmptyInitializedKvs, ValueSize_DeletedKey) {
- ASSERT_EQ(Status::OK, kvs_.Put("TheKey", as_bytes(span("123", 3))));
+ ASSERT_EQ(Status::OK, kvs_.Put("TheKey", std::as_bytes(std::span("123", 3))));
ASSERT_EQ(Status::OK, kvs_.Delete("TheKey"));
EXPECT_EQ(Status::NOT_FOUND, kvs_.ValueSize("TheKey").status());
diff --git a/pw_kvs/key_value_store_wear_test.cc b/pw_kvs/key_value_store_wear_test.cc
index e907576..eb5f930 100644
--- a/pw_kvs/key_value_store_wear_test.cc
+++ b/pw_kvs/key_value_store_wear_test.cc
@@ -63,7 +63,7 @@
// written.
test_data[0]++;
- EXPECT_TRUE(kvs_.Put("large_entry", span(test_data)).ok());
+ EXPECT_TRUE(kvs_.Put("large_entry", std::span(test_data)).ok());
}
// Ensure every sector has been erased at several times due to garbage
@@ -91,7 +91,8 @@
EXPECT_EQ(
Status::OK,
- kvs_.Put("key", as_bytes(span(test_data, sizeof(test_data) - 70))));
+ kvs_.Put("key",
+ std::as_bytes(std::span(test_data, sizeof(test_data) - 70))));
}
// Add many copies of a differently sized entry that is larger than the
diff --git a/pw_kvs/public/pw_kvs/alignment.h b/pw_kvs/public/pw_kvs/alignment.h
index f153756..e8cf191 100644
--- a/pw_kvs/public/pw_kvs/alignment.h
+++ b/pw_kvs/public/pw_kvs/alignment.h
@@ -17,10 +17,10 @@
#include <cstddef>
#include <cstring>
#include <initializer_list>
+#include <span>
#include <utility>
#include "pw_kvs/io.h"
-#include "pw_span/span.h"
#include "pw_status/status_with_size.h"
namespace pw {
@@ -46,7 +46,9 @@
// called or the AlignedWriter goes out of scope.
class AlignedWriter {
public:
- AlignedWriter(span<std::byte> buffer, size_t alignment_bytes, Output& writer)
+ AlignedWriter(std::span<std::byte> buffer,
+ size_t alignment_bytes,
+ Output& writer)
: buffer_(buffer.data()),
write_size_(AlignDown(buffer.size(), alignment_bytes)),
alignment_bytes_(alignment_bytes),
@@ -66,10 +68,10 @@
// successful and failed Write calls. On a failed write call, knowing the
// bytes attempted may be important when working with flash memory, since it
// can only be written once between erases.
- StatusWithSize Write(span<const std::byte> data);
+ StatusWithSize Write(std::span<const std::byte> data);
StatusWithSize Write(const void* data, size_t size) {
- return Write(span(static_cast<const std::byte*>(data), size));
+ return Write(std::span(static_cast<const std::byte*>(data), size));
}
// Reads size bytes from the input and writes them to the output.
@@ -110,7 +112,7 @@
template <size_t kBufferSize>
StatusWithSize AlignedWrite(Output& output,
size_t alignment_bytes,
- span<const span<const std::byte>> data) {
+ std::span<const std::span<const std::byte>> data) {
// TODO: This should convert to PW_CHECK once that is available for use in
// host tests.
if (alignment_bytes > kBufferSize) {
@@ -119,7 +121,7 @@
AlignedWriterBuffer<kBufferSize> buffer(alignment_bytes, output);
- for (const span<const std::byte>& chunk : data) {
+ for (const std::span<const std::byte>& chunk : data) {
if (StatusWithSize result = buffer.Write(chunk); !result.ok()) {
return result;
}
@@ -130,11 +132,12 @@
// Calls AlignedWrite with an initializer list.
template <size_t kBufferSize>
-StatusWithSize AlignedWrite(Output& output,
- size_t alignment_bytes,
- std::initializer_list<span<const std::byte>> data) {
+StatusWithSize AlignedWrite(
+ Output& output,
+ size_t alignment_bytes,
+ std::initializer_list<std::span<const std::byte>> data) {
return AlignedWrite<kBufferSize>(
- output, alignment_bytes, span(data.begin(), data.size()));
+ output, alignment_bytes, std::span(data.begin(), data.size()));
}
} // namespace pw
diff --git a/pw_kvs/public/pw_kvs/checksum.h b/pw_kvs/public/pw_kvs/checksum.h
index ff89d44..5899566 100644
--- a/pw_kvs/public/pw_kvs/checksum.h
+++ b/pw_kvs/public/pw_kvs/checksum.h
@@ -14,9 +14,9 @@
#pragma once
#include <cstddef>
+#include <span>
#include "pw_kvs/alignment.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::kvs {
@@ -27,18 +27,18 @@
virtual void Reset() = 0;
// Updates the checksum with the provided data.
- virtual void Update(span<const std::byte> data) = 0;
+ virtual void Update(std::span<const std::byte> data) = 0;
// Updates the checksum from a pointer and size.
void Update(const void* data, size_t size_bytes) {
- return Update(span(static_cast<const std::byte*>(data), size_bytes));
+ return Update(std::span(static_cast<const std::byte*>(data), size_bytes));
}
// Returns the final result of the checksum. Update() can no longer be called
- // after this. The returned span is valid until a call to Reset().
+ // after this. The returned std::span is valid until a call to Reset().
//
// Finish MUST be called before calling Verify.
- span<const std::byte> Finish() {
+ std::span<const std::byte> Finish() {
Finalize(); // Implemented by derived classes, if required.
return state();
}
@@ -51,24 +51,25 @@
// size_bytes() are ignored.
//
// Finish MUST be called before calling Verify.
- Status Verify(span<const std::byte> checksum) const;
+ Status Verify(std::span<const std::byte> checksum) const;
protected:
- // A derived class provides a span of its state buffer.
- constexpr ChecksumAlgorithm(span<const std::byte> state) : state_(state) {}
+ // A derived class provides a std::span of its state buffer.
+ constexpr ChecksumAlgorithm(std::span<const std::byte> state)
+ : state_(state) {}
// Protected destructor prevents deleting ChecksumAlgorithms from the base
// class, so that it is safe to have a non-virtual destructor.
~ChecksumAlgorithm() = default;
// Returns the current checksum state.
- constexpr span<const std::byte> state() const { return state_; }
+ constexpr std::span<const std::byte> state() const { return state_; }
private:
// Checksums that require finalizing operations may override this method.
virtual void Finalize() {}
- span<const std::byte> state_;
+ std::span<const std::byte> state_;
};
// A checksum algorithm for which Verify always passes. This can be used to
@@ -78,7 +79,7 @@
constexpr IgnoreChecksum() : ChecksumAlgorithm({}) {}
void Reset() override {}
- void Update(span<const std::byte>) override {}
+ void Update(std::span<const std::byte>) override {}
};
// Calculates a checksum in kAlignmentBytes chunks. Checksum classes can inherit
@@ -87,10 +88,10 @@
template <size_t kAlignmentBytes, size_t kBufferSize = kAlignmentBytes>
class AlignedChecksum : public ChecksumAlgorithm {
public:
- void Update(span<const std::byte> data) final { writer_.Write(data); }
+ void Update(std::span<const std::byte> data) final { writer_.Write(data); }
protected:
- constexpr AlignedChecksum(span<const std::byte> state)
+ constexpr AlignedChecksum(std::span<const std::byte> state)
: ChecksumAlgorithm(state),
output_(this),
writer_(kAlignmentBytes, output_) {}
@@ -105,7 +106,7 @@
FinalizeAligned();
}
- virtual void UpdateAligned(span<const std::byte> data) = 0;
+ virtual void UpdateAligned(std::span<const std::byte> data) = 0;
virtual void FinalizeAligned() = 0;
diff --git a/pw_kvs/public/pw_kvs/crc16_checksum.h b/pw_kvs/public/pw_kvs/crc16_checksum.h
index 51b096b..6cbef1f 100644
--- a/pw_kvs/public/pw_kvs/crc16_checksum.h
+++ b/pw_kvs/public/pw_kvs/crc16_checksum.h
@@ -13,19 +13,20 @@
// the License.
#pragma once
+#include <span>
+
#include "pw_checksum/ccitt_crc16.h"
#include "pw_kvs/checksum.h"
-#include "pw_span/span.h"
namespace pw::kvs {
class ChecksumCrc16 final : public ChecksumAlgorithm {
public:
- ChecksumCrc16() : ChecksumAlgorithm(as_bytes(span(&crc_, 1))) {}
+ ChecksumCrc16() : ChecksumAlgorithm(std::as_bytes(std::span(&crc_, 1))) {}
void Reset() override { crc_ = checksum::kCcittCrc16DefaultInitialValue; }
- void Update(span<const std::byte> data) override {
+ void Update(std::span<const std::byte> data) override {
crc_ = checksum::CcittCrc16(data, crc_);
}
diff --git a/pw_kvs/public/pw_kvs/fake_flash_memory.h b/pw_kvs/public/pw_kvs/fake_flash_memory.h
index a0916bf..5dc839c 100644
--- a/pw_kvs/public/pw_kvs/fake_flash_memory.h
+++ b/pw_kvs/public/pw_kvs/fake_flash_memory.h
@@ -17,10 +17,10 @@
#include <array>
#include <cstddef>
#include <cstring>
+#include <span>
#include "pw_containers/vector.h"
#include "pw_kvs/flash_memory.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::kvs {
@@ -50,7 +50,7 @@
Status Check(FlashMemory::Address start_address, size_t size);
// Determines if any of a series of FlashErrors applies to the operation.
- static Status Check(span<FlashError> errors,
+ static Status Check(std::span<FlashError> errors,
FlashMemory::Address address,
size_t size);
@@ -88,7 +88,7 @@
static constexpr std::byte kErasedValue = std::byte{0xff};
- FakeFlashMemory(span<std::byte> buffer,
+ FakeFlashMemory(std::span<std::byte> buffer,
size_t sector_size,
size_t sector_count,
size_t alignment_bytes = kDefaultAlignmentBytes,
@@ -110,16 +110,17 @@
Status Erase(Address address, size_t num_sectors) override;
// Reads bytes from flash into buffer.
- StatusWithSize Read(Address address, span<std::byte> output) override;
+ StatusWithSize Read(Address address, std::span<std::byte> output) override;
// Writes bytes to flash.
- StatusWithSize Write(Address address, span<const std::byte> data) override;
+ StatusWithSize Write(Address address,
+ std::span<const std::byte> data) override;
// Testing API
// Access the underlying buffer for testing purposes. Not part of the
// FlashMemory API.
- span<std::byte> buffer() const { return buffer_; }
+ std::span<std::byte> buffer() const { return buffer_; }
bool InjectReadError(const FlashError& error) {
if (read_errors_.full()) {
@@ -138,7 +139,7 @@
}
private:
- const span<std::byte> buffer_;
+ const std::span<std::byte> buffer_;
Vector<FlashError>& read_errors_;
Vector<FlashError>& write_errors_;
};
@@ -156,7 +157,7 @@
// Creates a flash memory initialized to the provided contents.
explicit FakeFlashMemoryBuffer(
- span<const std::byte> contents,
+ std::span<const std::byte> contents,
size_t alignment_bytes = kDefaultAlignmentBytes)
: FakeFlashMemory(buffer_,
kSectorSize,
diff --git a/pw_kvs/public/pw_kvs/flash_memory.h b/pw_kvs/public/pw_kvs/flash_memory.h
index b284415..ac8f429 100644
--- a/pw_kvs/public/pw_kvs/flash_memory.h
+++ b/pw_kvs/public/pw_kvs/flash_memory.h
@@ -16,9 +16,9 @@
#include <cstddef>
#include <cstdint>
#include <initializer_list>
+#include <span>
#include "pw_kvs/alignment.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
@@ -71,10 +71,10 @@
// OK: success
// DEADLINE_EXCEEDED: timeout
// OUT_OF_RANGE: write does not fit in the flash memory
- virtual StatusWithSize Read(Address address, span<std::byte> output) = 0;
+ virtual StatusWithSize Read(Address address, std::span<std::byte> output) = 0;
StatusWithSize Read(Address address, void* buffer, size_t len) {
- return Read(address, span(static_cast<std::byte*>(buffer), len));
+ return Read(address, std::span(static_cast<std::byte*>(buffer), len));
}
// Writes bytes to flash. Blocking call.
@@ -85,13 +85,13 @@
// OUT_OF_RANGE: write does not fit in the memory
//
virtual StatusWithSize Write(Address destination_flash_address,
- span<const std::byte> data) = 0;
+ std::span<const std::byte> data) = 0;
StatusWithSize Write(Address destination_flash_address,
const void* data,
size_t len) {
return Write(destination_flash_address,
- span(static_cast<const std::byte*>(data), len));
+ std::span(static_cast<const std::byte*>(data), len));
}
// Convert an Address to an MCU pointer, this can be used for memory
@@ -135,7 +135,7 @@
: flash_(flash), address_(address) {}
private:
- StatusWithSize DoWrite(span<const std::byte> data) override;
+ StatusWithSize DoWrite(std::span<const std::byte> data) override;
FlashPartition& flash_;
FlashPartition::Address address_;
@@ -148,7 +148,7 @@
: flash_(flash), address_(address) {}
private:
- StatusWithSize DoRead(span<std::byte> data) override;
+ StatusWithSize DoRead(std::span<std::byte> data) override;
FlashPartition& flash_;
FlashPartition::Address address_;
@@ -196,10 +196,10 @@
// TIMEOUT, on timeout.
// INVALID_ARGUMENT, if address or length is invalid.
// UNKNOWN, on HAL error
- virtual StatusWithSize Read(Address address, span<std::byte> output);
+ virtual StatusWithSize Read(Address address, std::span<std::byte> output);
StatusWithSize Read(Address address, size_t length, void* output) {
- return Read(address, span(static_cast<std::byte*>(output), length));
+ return Read(address, std::span(static_cast<std::byte*>(output), length));
}
// Writes bytes to flash. Blocking call.
@@ -208,7 +208,8 @@
// INVALID_ARGUMENT, if address or length is invalid.
// PERMISSION_DENIED, if partition is read only.
// UNKNOWN, on HAL error
- virtual StatusWithSize Write(Address address, span<const std::byte> data);
+ virtual StatusWithSize Write(Address address,
+ std::span<const std::byte> data);
// Check to see if chunk of flash memory is erased. Address and len need to
// be aligned with FlashMemory.
@@ -224,7 +225,7 @@
// Checks to see if the data appears to be erased. No reads or writes occur;
// the FlashPartition simply compares the data to
// flash_.erased_memory_content().
- bool AppearsErased(span<const std::byte> data) const;
+ bool AppearsErased(std::span<const std::byte> data) const;
// Overridden by derived classes. The reported sector size is space available
// to users of FlashPartition. It accounts for space reserved in the sector
diff --git a/pw_kvs/public/pw_kvs/flash_partition_with_stats.h b/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
index 9393fd9..569ab9f 100644
--- a/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
+++ b/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
@@ -38,8 +38,8 @@
Status Erase(Address address, size_t num_sectors) override;
- span<size_t> sector_erase_counters() {
- return span(sector_counters_.data(), sector_counters_.size());
+ std::span<size_t> sector_erase_counters() {
+ return std::span(sector_counters_.data(), sector_counters_.size());
}
size_t min_erase_count() const {
diff --git a/pw_kvs/public/pw_kvs/format.h b/pw_kvs/public/pw_kvs/format.h
index a2d843a..f6b33e7 100644
--- a/pw_kvs/public/pw_kvs/format.h
+++ b/pw_kvs/public/pw_kvs/format.h
@@ -14,9 +14,9 @@
#pragma once
#include <cstdint>
+#include <span>
#include "pw_kvs/checksum.h"
-#include "pw_span/span.h"
namespace pw::kvs {
@@ -56,7 +56,7 @@
// simultaneously supported formats.
class EntryFormats {
public:
- explicit constexpr EntryFormats(span<const EntryFormat> formats)
+ explicit constexpr EntryFormats(std::span<const EntryFormat> formats)
: formats_(formats) {}
explicit constexpr EntryFormats(const EntryFormat& format)
@@ -69,7 +69,7 @@
const EntryFormat* Find(uint32_t magic) const;
private:
- const span<const EntryFormat> formats_;
+ const std::span<const EntryFormat> formats_;
};
} // namespace internal
diff --git a/pw_kvs/public/pw_kvs/internal/entry.h b/pw_kvs/public/pw_kvs/internal/entry.h
index 3e75aeb..5305ab6 100644
--- a/pw_kvs/public/pw_kvs/internal/entry.h
+++ b/pw_kvs/public/pw_kvs/internal/entry.h
@@ -19,6 +19,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <span>
#include <string_view>
#include "pw_kvs/alignment.h"
@@ -27,7 +28,6 @@
#include "pw_kvs/format.h"
#include "pw_kvs/internal/hash.h"
#include "pw_kvs/internal/key_descriptor.h"
-#include "pw_span/span.h"
namespace pw::kvs::internal {
@@ -64,7 +64,7 @@
Address address,
const EntryFormat& format,
std::string_view key,
- span<const std::byte> value,
+ std::span<const std::byte> value,
uint32_t transaction_id) {
return Entry(
partition, address, format, key, value, value.size(), transaction_id);
@@ -97,7 +97,8 @@
deleted() ? EntryState::kDeleted : EntryState::kValid};
}
- StatusWithSize Write(std::string_view key, span<const std::byte> value) const;
+ StatusWithSize Write(std::string_view key,
+ std::span<const std::byte> value) const;
// Changes the format and transcation ID for this entry. In order to calculate
// the new checksum, the entire entry is read into a small stack-allocated
@@ -119,20 +120,20 @@
ReadKey(partition(), address_, key_length(), key.data()), key_length());
}
- StatusWithSize ReadValue(span<std::byte> buffer,
+ StatusWithSize ReadValue(std::span<std::byte> buffer,
size_t offset_bytes = 0) const;
- Status ValueMatches(span<const std::byte> value) const;
+ Status ValueMatches(std::span<const std::byte> value) const;
Status VerifyChecksum(std::string_view key,
- span<const std::byte> value) const;
+ std::span<const std::byte> value) const;
Status VerifyChecksumInFlash() const;
// Calculates the total size of an entry, including padding.
static size_t size(const FlashPartition& partition,
std::string_view key,
- span<const std::byte> value) {
+ std::span<const std::byte> value) {
return AlignUp(sizeof(EntryHeader) + key.size() + value.size(),
std::max(partition.alignment_bytes(), kMinAlignmentBytes));
}
@@ -174,7 +175,7 @@
Address address,
const EntryFormat& format,
std::string_view key,
- span<const std::byte> value,
+ std::span<const std::byte> value,
uint16_t value_size_bytes,
uint32_t transaction_id);
@@ -196,12 +197,12 @@
return sizeof(EntryHeader) + key_length() + value_size();
}
- span<const std::byte> checksum_bytes() const {
- return as_bytes(span(&header_.checksum, 1));
+ std::span<const std::byte> checksum_bytes() const {
+ return std::as_bytes(std::span(&header_.checksum, 1));
}
- span<const std::byte> CalculateChecksum(std::string_view key,
- span<const std::byte> value) const;
+ std::span<const std::byte> CalculateChecksum(
+ std::string_view key, std::span<const std::byte> value) const;
Status CalculateChecksumFromFlash();
diff --git a/pw_kvs/public/pw_kvs/internal/entry_cache.h b/pw_kvs/public/pw_kvs/internal/entry_cache.h
index 5ed2f15..f347738 100644
--- a/pw_kvs/public/pw_kvs/internal/entry_cache.h
+++ b/pw_kvs/public/pw_kvs/internal/entry_cache.h
@@ -15,6 +15,7 @@
#include <cstddef>
#include <cstdint>
+#include <span>
#include <string_view>
#include <type_traits>
@@ -23,7 +24,6 @@
#include "pw_kvs/format.h"
#include "pw_kvs/internal/key_descriptor.h"
#include "pw_kvs/internal/sectors.h"
-#include "pw_span/span.h"
namespace pw::kvs::internal {
@@ -45,7 +45,7 @@
uint32_t first_address() const { return addresses_[0]; }
// All addresses for this entry, including redundant entries, if any.
- const span<Address>& addresses() const { return addresses_; }
+ const std::span<Address>& addresses() const { return addresses_; }
// True if the KeyDesctiptor's transaction ID is newer than the specified ID.
bool IsNewerThan(uint32_t other_transaction_id) const {
@@ -57,7 +57,7 @@
// than allowed by the redundancy.
void AddNewAddress(Address address) {
addresses_[addresses_.size()] = address;
- addresses_ = span(addresses_.begin(), addresses_.size() + 1);
+ addresses_ = std::span(addresses_.begin(), addresses_.size() + 1);
}
// Remove an address from the entry metadata.
@@ -70,11 +70,12 @@
private:
friend class EntryCache;
- constexpr EntryMetadata(KeyDescriptor& descriptor, span<Address> addresses)
+ constexpr EntryMetadata(KeyDescriptor& descriptor,
+ std::span<Address> addresses)
: descriptor_(&descriptor), addresses_(addresses) {}
KeyDescriptor* descriptor_;
- span<Address> addresses_;
+ std::span<Address> addresses_;
};
// Tracks entry metadata. Combines KeyDescriptors and with their associated
@@ -215,8 +216,8 @@
// address slot available.
void AddAddressIfRoom(size_t descriptor_index, Address address) const;
- // Returns a span of the valid addresses for the descriptor.
- span<Address> addresses(size_t descriptor_index) const;
+ // Returns a std::span of the valid addresses for the descriptor.
+ std::span<Address> addresses(size_t descriptor_index) const;
Address* first_address(size_t descriptor_index) const {
return &addresses_[descriptor_index * redundancy_];
diff --git a/pw_kvs/public/pw_kvs/internal/sectors.h b/pw_kvs/public/pw_kvs/internal/sectors.h
index 7f89bb5..d2f4565 100644
--- a/pw_kvs/public/pw_kvs/internal/sectors.h
+++ b/pw_kvs/public/pw_kvs/internal/sectors.h
@@ -16,10 +16,10 @@
#include <climits>
#include <cstddef>
#include <cstdint>
+#include <span>
#include "pw_containers/vector.h"
#include "pw_kvs/flash_memory.h"
-#include "pw_span/span.h"
namespace pw::kvs::internal {
@@ -159,7 +159,7 @@
// least 1 empty sector. Addresses in reserved_addresses are avoided.
Status FindSpace(SectorDescriptor** found_sector,
size_t size,
- span<const Address> reserved_addresses) {
+ std::span<const Address> reserved_addresses) {
return Find(kAppendEntry, found_sector, size, {}, reserved_addresses);
}
@@ -168,8 +168,8 @@
Status FindSpaceDuringGarbageCollection(
SectorDescriptor** found_sector,
size_t size,
- span<const Address> addresses_to_skip,
- span<const Address> reserved_addresses) {
+ std::span<const Address> addresses_to_skip,
+ std::span<const Address> reserved_addresses) {
return Find(kGarbageCollect,
found_sector,
size,
@@ -180,7 +180,7 @@
// Finds a sector that is ready to be garbage collected. Returns nullptr if no
// sectors can / need to be garbage collected.
SectorDescriptor* FindSectorToGarbageCollect(
- span<const Address> addresses_to_avoid) const;
+ std::span<const Address> addresses_to_avoid) const;
// The number of sectors in use.
size_t size() const { return descriptors_.size(); }
@@ -210,8 +210,8 @@
Status Find(FindMode find_mode,
SectorDescriptor** found_sector,
size_t size,
- span<const Address> addresses_to_skip,
- span<const Address> reserved_addresses);
+ std::span<const Address> addresses_to_skip,
+ std::span<const Address> reserved_addresses);
SectorDescriptor& WearLeveledSectorFromIndex(size_t idx) const;
diff --git a/pw_kvs/public/pw_kvs/internal/span_traits.h b/pw_kvs/public/pw_kvs/internal/span_traits.h
index 18098ed..4c4ab56 100644
--- a/pw_kvs/public/pw_kvs/internal/span_traits.h
+++ b/pw_kvs/public/pw_kvs/internal/span_traits.h
@@ -18,12 +18,13 @@
namespace pw::kvs {
namespace internal {
-template <typename T, typename = decltype(span(std::declval<T>()))>
+template <typename T, typename = decltype(std::span(std::declval<T>()))>
constexpr bool ConvertsToSpan(int) {
return true;
}
-// If the expression span(T) fails, then the type can't be converted to a span.
+// If the expression std::span(T) fails, then the type can't be converted to a
+// std::span.
template <typename T>
constexpr bool ConvertsToSpan(...) {
return false;
@@ -31,7 +32,7 @@
} // namespace internal
-// Traits class to detect if the type converts to a span.
+// Traits class to detect if the type converts to a std::span.
template <typename T>
struct ConvertsToSpan
: public std::bool_constant<
diff --git a/pw_kvs/public/pw_kvs/io.h b/pw_kvs/public/pw_kvs/io.h
index 71d1eb2..167182f 100644
--- a/pw_kvs/public/pw_kvs/io.h
+++ b/pw_kvs/public/pw_kvs/io.h
@@ -14,9 +14,9 @@
#pragma once
#include <cstddef>
+#include <span>
#include <type_traits>
-#include "pw_span/span.h"
#include "pw_status/status_with_size.h"
namespace pw {
@@ -34,41 +34,43 @@
} // namespace internal
// Writes bytes to an unspecified output. Provides a Write function that takes a
-// span of bytes and returns a Status.
+// std::span of bytes and returns a Status.
class Output {
public:
- StatusWithSize Write(span<const std::byte> data) { return DoWrite(data); }
+ StatusWithSize Write(std::span<const std::byte> data) {
+ return DoWrite(data);
+ }
// Convenience wrapper for writing data from a pointer and length.
StatusWithSize Write(const void* data, size_t size_bytes) {
- return Write(span(static_cast<const std::byte*>(data), size_bytes));
+ return Write(std::span(static_cast<const std::byte*>(data), size_bytes));
}
protected:
~Output() = default;
private:
- virtual StatusWithSize DoWrite(span<const std::byte> data) = 0;
+ virtual StatusWithSize DoWrite(std::span<const std::byte> data) = 0;
};
class Input {
public:
- StatusWithSize Read(span<std::byte> data) { return DoRead(data); }
+ StatusWithSize Read(std::span<std::byte> data) { return DoRead(data); }
// Convenience wrapper for reading data from a pointer and length.
StatusWithSize Read(void* data, size_t size_bytes) {
- return Read(span(static_cast<std::byte*>(data), size_bytes));
+ return Read(std::span(static_cast<std::byte*>(data), size_bytes));
}
protected:
~Input() = default;
private:
- virtual StatusWithSize DoRead(span<std::byte> data) = 0;
+ virtual StatusWithSize DoRead(std::span<std::byte> data) = 0;
};
-// Output adapter that calls a method on a class with a span of bytes. If the
-// method returns void instead of the expected Status, Write always returns
+// Output adapter that calls a method on a class with a std::span of bytes. If
+// the method returns void instead of the expected Status, Write always returns
// Status::OK.
template <auto kMethod>
class OutputToMethod final : public Output {
@@ -78,7 +80,7 @@
constexpr OutputToMethod(Class* object) : object_(*object) {}
private:
- StatusWithSize DoWrite(span<const std::byte> data) override {
+ StatusWithSize DoWrite(std::span<const std::byte> data) override {
using Return = typename internal::FunctionTraits<decltype(kMethod)>::Return;
if constexpr (std::is_void_v<Return>) {
@@ -96,15 +98,15 @@
// Output adapter that calls a free function.
class OutputToFunction final : public Output {
public:
- OutputToFunction(StatusWithSize (*function)(span<const std::byte>))
+ OutputToFunction(StatusWithSize (*function)(std::span<const std::byte>))
: function_(function) {}
private:
- StatusWithSize DoWrite(span<const std::byte> data) override {
+ StatusWithSize DoWrite(std::span<const std::byte> data) override {
return function_(data);
}
- StatusWithSize (*function_)(span<const std::byte>);
+ StatusWithSize (*function_)(std::span<const std::byte>);
};
} // namespace pw
diff --git a/pw_kvs/public/pw_kvs/key_value_store.h b/pw_kvs/public/pw_kvs/key_value_store.h
index f382c60..01b055d 100644
--- a/pw_kvs/public/pw_kvs/key_value_store.h
+++ b/pw_kvs/public/pw_kvs/key_value_store.h
@@ -16,6 +16,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <span>
#include <string_view>
#include <type_traits>
@@ -28,7 +29,6 @@
#include "pw_kvs/internal/key_descriptor.h"
#include "pw_kvs/internal/sectors.h"
#include "pw_kvs/internal/span_traits.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
@@ -116,12 +116,13 @@
// INVALID_ARGUMENT: key is empty or too long or value is too large
//
StatusWithSize Get(std::string_view key,
- span<std::byte> value,
+ std::span<std::byte> value,
size_t offset_bytes = 0) const;
// This overload of Get accepts a pointer to a trivially copyable object.
- // If the value is an array, call Get with as_writable_bytes(span(array)),
- // or pass a pointer to the array instead of the array itself.
+ // If the value is an array, call Get with
+ // std::as_writable_bytes(std::span(array)), or pass a pointer to the array
+ // instead of the array itself.
template <typename Pointer,
typename = std::enable_if_t<std::is_pointer_v<Pointer>>>
Status Get(const std::string_view& key, const Pointer& pointer) const {
@@ -133,7 +134,7 @@
// Adds a key-value entry to the KVS. If the key was already present, its
// value is overwritten.
//
- // The value may be a span of bytes or a trivially copyable object.
+ // The value may be a std::span of bytes or a trivially copyable object.
//
// In the current implementation, all keys in the KVS must have a unique hash.
// If Put is called with a key whose hash matches an existing key, nothing
@@ -150,10 +151,10 @@
template <typename T>
Status Put(const std::string_view& key, const T& value) {
if constexpr (ConvertsToSpan<T>::value) {
- return PutBytes(key, as_bytes(span(value)));
+ return PutBytes(key, std::as_bytes(std::span(value)));
} else {
CheckThatObjectCanBePutOrGet<T>();
- return PutBytes(key, as_bytes(span(&value, 1)));
+ return PutBytes(key, std::as_bytes(std::span(&value, 1)));
}
}
@@ -202,7 +203,7 @@
// Gets the value referred to by this iterator. Equivalent to
// KeyValueStore::Get.
- StatusWithSize Get(span<std::byte> value_buffer,
+ StatusWithSize Get(std::span<std::byte> value_buffer,
size_t offset_bytes = 0) const {
return kvs_.Get(key(), *iterator_, value_buffer, offset_bytes);
}
@@ -315,7 +316,7 @@
// In the future, will be able to provide additional EntryFormats for
// backwards compatibility.
KeyValueStore(FlashPartition* partition,
- span<const EntryFormat> formats,
+ std::span<const EntryFormat> formats,
const Options& options,
size_t redundancy,
Vector<SectorDescriptor>& sector_descriptor_list,
@@ -332,8 +333,9 @@
static_assert(
std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>,
"Only trivially copyable, non-pointer objects may be Put and Get by "
- "value. Any value may be stored by converting it to a byte span with "
- "as_bytes(span(&value, 1)) or as_writable_bytes(span(&value, 1)).");
+ "value. Any value may be stored by converting it to a byte std::span "
+ "with std::as_bytes(std::span(&value, 1)) or "
+ "std::as_writable_bytes(std::span(&value, 1)).");
}
Status InitializeMetadata();
@@ -342,7 +344,7 @@
Address start_address,
Address* next_entry_address);
- Status PutBytes(std::string_view key, span<const std::byte> value);
+ Status PutBytes(std::string_view key, std::span<const std::byte> value);
StatusWithSize ValueSize(const EntryMetadata& metadata) const;
@@ -372,7 +374,7 @@
StatusWithSize Get(std::string_view key,
const EntryMetadata& metadata,
- span<std::byte> value_buffer,
+ std::span<std::byte> value_buffer,
size_t offset_bytes) const;
Status FixedSizeGet(std::string_view key,
@@ -390,12 +392,13 @@
Status WriteEntryForExistingKey(EntryMetadata& metadata,
EntryState new_state,
std::string_view key,
- span<const std::byte> value);
+ std::span<const std::byte> value);
- Status WriteEntryForNewKey(std::string_view key, span<const std::byte> value);
+ Status WriteEntryForNewKey(std::string_view key,
+ std::span<const std::byte> value);
Status WriteEntry(std::string_view key,
- span<const std::byte> value,
+ std::span<const std::byte> value,
EntryState new_state,
EntryMetadata* prior_metadata = nullptr,
const internal::Entry* prior_entry = nullptr);
@@ -414,13 +417,13 @@
Status GetSectorForWrite(SectorDescriptor** sector,
size_t entry_size,
- span<const Address> addresses_to_skip);
+ std::span<const Address> addresses_to_skip);
Status MarkSectorCorruptIfNotOk(Status status, SectorDescriptor* sector);
Status AppendEntry(const Entry& entry,
std::string_view key,
- span<const std::byte> value);
+ std::span<const std::byte> value);
StatusWithSize CopyEntryToSector(Entry& entry,
SectorDescriptor* new_sector,
@@ -428,18 +431,19 @@
Status RelocateEntry(const EntryMetadata& metadata,
KeyValueStore::Address& address,
- span<const Address> addresses_to_skip);
+ std::span<const Address> addresses_to_skip);
// Find and garbage collect a singe sector that does not include an address to
// skip.
- Status GarbageCollect(span<const Address> addresses_to_skip);
+ Status GarbageCollect(std::span<const Address> addresses_to_skip);
- Status RelocateKeyAddressesInSector(SectorDescriptor& sector_to_gc,
- const EntryMetadata& descriptor,
- span<const Address> addresses_to_skip);
+ Status RelocateKeyAddressesInSector(
+ SectorDescriptor& sector_to_gc,
+ const EntryMetadata& descriptor,
+ std::span<const Address> addresses_to_skip);
Status GarbageCollectSector(SectorDescriptor& sector_to_gc,
- span<const Address> addresses_to_skip);
+ std::span<const Address> addresses_to_skip);
// Ensure that all entries are on the primary (first) format. Entries that are
// not on the primary format are rewritten.
@@ -461,7 +465,7 @@
internal::Entry CreateEntry(Address address,
std::string_view key,
- span<const std::byte> value,
+ std::span<const std::byte> value,
EntryState state);
void LogSectors() const;
@@ -525,7 +529,7 @@
const Options& options = {})
: KeyValueStoreBuffer(
partition,
- span(reinterpret_cast<const EntryFormat (&)[1]>(format)),
+ std::span(reinterpret_cast<const EntryFormat (&)[1]>(format)),
options) {
static_assert(kEntryFormats == 1,
"kEntryFormats EntryFormats must be specified");
@@ -534,7 +538,7 @@
// Constructs a KeyValueStore on the partition. Supports multiple entry
// formats. The first EntryFormat is used for new entries.
KeyValueStoreBuffer(FlashPartition* partition,
- span<const EntryFormat, kEntryFormats> formats,
+ std::span<const EntryFormat, kEntryFormats> formats,
const Options& options = {})
: KeyValueStore(partition,
formats_,
diff --git a/pw_kvs/sectors.cc b/pw_kvs/sectors.cc
index d36e01c..01547ec 100644
--- a/pw_kvs/sectors.cc
+++ b/pw_kvs/sectors.cc
@@ -33,8 +33,8 @@
Status Sectors::Find(FindMode find_mode,
SectorDescriptor** found_sector,
size_t size,
- span<const Address> addresses_to_skip,
- span<const Address> reserved_addresses) {
+ std::span<const Address> addresses_to_skip,
+ std::span<const Address> reserved_addresses) {
SectorDescriptor* first_empty_sector = nullptr;
bool at_least_two_empty_sectors = (find_mode == kGarbageCollect);
@@ -99,7 +99,7 @@
}
// Skip sectors in the skip list.
- if (Contains(span(temp_sectors_to_skip_, sectors_to_skip), sector)) {
+ if (Contains(std::span(temp_sectors_to_skip_, sectors_to_skip), sector)) {
continue;
}
@@ -161,7 +161,7 @@
// TODO: Consider breaking this function into smaller sub-chunks.
SectorDescriptor* Sectors::FindSectorToGarbageCollect(
- span<const Address> reserved_addresses) const {
+ std::span<const Address> reserved_addresses) const {
const size_t sector_size_bytes = partition_.sector_size_bytes();
SectorDescriptor* sector_candidate = nullptr;
size_t candidate_bytes = 0;
@@ -171,7 +171,8 @@
temp_sectors_to_skip_[i] = &FromAddress(reserved_addresses[i]);
DBG(" Skip sector %u", Index(reserved_addresses[i]));
}
- const span sectors_to_skip(temp_sectors_to_skip_, reserved_addresses.size());
+ const std::span sectors_to_skip(temp_sectors_to_skip_,
+ reserved_addresses.size());
// Step 1: Try to find a sectors with stale keys and no valid keys (no
// relocation needed). Use the first such sector found, as that will help the