aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pw_allocator/block.cc2
-rw-r--r--pw_allocator/block_test.cc35
-rw-r--r--pw_allocator/freelist.cc14
-rw-r--r--pw_allocator/freelist_heap.cc2
-rw-r--r--pw_allocator/freelist_heap_test.cc3
-rw-r--r--pw_allocator/freelist_test.cc31
-rw-r--r--pw_allocator/public/pw_allocator/block.h5
-rw-r--r--pw_allocator/public/pw_allocator/freelist.h10
-rw-r--r--pw_allocator/public/pw_allocator/freelist_heap.h12
-rw-r--r--pw_assert/fake_backend.cc2
-rw-r--r--pw_base64/base64.cc5
-rw-r--r--pw_base64/base64_test.cc36
-rw-r--r--pw_base64/public/pw_base64/base64.h9
-rw-r--r--pw_checksum/ccitt_crc16_test.cc6
-rw-r--r--pw_checksum/public/pw_checksum/ccitt_crc16.h4
-rw-r--r--pw_cpu_exception/public/pw_cpu_exception/cpu_exception.h4
-rw-r--r--pw_cpu_exception_armv7m/cpu_state.cc7
-rw-r--r--pw_cpu_exception_armv7m/exception_entry_test.cc8
-rw-r--r--pw_kvs/alignment.cc2
-rw-r--r--pw_kvs/alignment_test.cc35
-rw-r--r--pw_kvs/checksum.cc2
-rw-r--r--pw_kvs/checksum_test.cc21
-rw-r--r--pw_kvs/entry.cc38
-rw-r--r--pw_kvs/entry_cache.cc9
-rw-r--r--pw_kvs/entry_test.cc27
-rw-r--r--pw_kvs/fake_flash_memory.cc7
-rw-r--r--pw_kvs/flash_memory.cc11
-rw-r--r--pw_kvs/key_value_store.cc45
-rw-r--r--pw_kvs/key_value_store_binary_format_test.cc93
-rw-r--r--pw_kvs/key_value_store_fuzz_test.cc2
-rw-r--r--pw_kvs/key_value_store_test.cc156
-rw-r--r--pw_kvs/key_value_store_wear_test.cc5
-rw-r--r--pw_kvs/public/pw_kvs/alignment.h23
-rw-r--r--pw_kvs/public/pw_kvs/checksum.h29
-rw-r--r--pw_kvs/public/pw_kvs/crc16_checksum.h7
-rw-r--r--pw_kvs/public/pw_kvs/fake_flash_memory.h17
-rw-r--r--pw_kvs/public/pw_kvs/flash_memory.h23
-rw-r--r--pw_kvs/public/pw_kvs/flash_partition_with_stats.h4
-rw-r--r--pw_kvs/public/pw_kvs/format.h6
-rw-r--r--pw_kvs/public/pw_kvs/internal/entry.h25
-rw-r--r--pw_kvs/public/pw_kvs/internal/entry_cache.h15
-rw-r--r--pw_kvs/public/pw_kvs/internal/sectors.h14
-rw-r--r--pw_kvs/public/pw_kvs/internal/span_traits.h7
-rw-r--r--pw_kvs/public/pw_kvs/io.h30
-rw-r--r--pw_kvs/public/pw_kvs/key_value_store.h58
-rw-r--r--pw_kvs/sectors.cc11
-rw-r--r--pw_protobuf/codegen_test.cc16
-rw-r--r--pw_protobuf/decoder.cc8
-rw-r--r--pw_protobuf/decoder_test.cc21
-rw-r--r--pw_protobuf/encoder.cc8
-rw-r--r--pw_protobuf/encoder_fuzzer.cc26
-rw-r--r--pw_protobuf/encoder_test.cc18
-rw-r--r--pw_protobuf/find.cc2
-rw-r--r--pw_protobuf/find_test.cc8
-rw-r--r--pw_protobuf/public/pw_protobuf/decoder.h28
-rw-r--r--pw_protobuf/public/pw_protobuf/encoder.h81
-rw-r--r--pw_protobuf/size_report/decoder_full.cc2
-rw-r--r--pw_protobuf/size_report/decoder_incremental.cc2
-rw-r--r--pw_ring_buffer/prefixed_entry_ring_buffer.cc28
-rw-r--r--pw_ring_buffer/prefixed_entry_ring_buffer_test.cc47
-rw-r--r--pw_ring_buffer/public/pw_ring_buffer/prefixed_entry_ring_buffer.h26
-rw-r--r--pw_rpc/base_server_writer.cc7
-rw-r--r--pw_rpc/base_server_writer_test.cc6
-rw-r--r--pw_rpc/channel.cc4
-rw-r--r--pw_rpc/channel_test.cc6
-rw-r--r--pw_rpc/nanopb/method.cc10
-rw-r--r--pw_rpc/nanopb/method_test.cc7
-rw-r--r--pw_rpc/nanopb/public_overrides/pw_rpc/internal/method.h31
-rw-r--r--pw_rpc/packet.cc8
-rw-r--r--pw_rpc/packet_test.cc2
-rw-r--r--pw_rpc/public/pw_rpc/channel.h4
-rw-r--r--pw_rpc/public/pw_rpc/internal/base_method.h4
-rw-r--r--pw_rpc/public/pw_rpc/internal/base_server_writer.h8
-rw-r--r--pw_rpc/public/pw_rpc/internal/channel.h10
-rw-r--r--pw_rpc/public/pw_rpc/internal/packet.h14
-rw-r--r--pw_rpc/public/pw_rpc/internal/service.h4
-rw-r--r--pw_rpc/public/pw_rpc/server.h10
-rw-r--r--pw_rpc/pw_rpc_private/test_utils.h16
-rw-r--r--pw_rpc/server.cc5
-rw-r--r--pw_rpc/server_test.cc13
-rw-r--r--pw_rpc/test_impl/public_overrides/pw_rpc/internal/method.h20
-rw-r--r--pw_stream/memory_stream.cc2
-rw-r--r--pw_stream/memory_stream_test.cc5
-rw-r--r--pw_stream/public/pw_stream/memory_stream.h10
-rw-r--r--pw_stream/public/pw_stream/stream.h8
-rw-r--r--pw_sys_io/public/pw_sys_io/sys_io.h10
-rw-r--r--pw_sys_io/sys_io.cc4
-rw-r--r--pw_sys_io_baremetal_lm3s6965evb/sys_io_baremetal.cc4
-rw-r--r--pw_sys_io_baremetal_stm32f429/sys_io_baremetal.cc4
-rw-r--r--pw_sys_io_stdio/sys_io.cc2
-rw-r--r--pw_tokenizer/base64.cc11
-rw-r--r--pw_tokenizer/base64_test.cc21
-rw-r--r--pw_tokenizer/decode.cc14
-rw-r--r--pw_tokenizer/detokenize.cc10
-rw-r--r--pw_tokenizer/detokenize_fuzzer.cc2
-rw-r--r--pw_tokenizer/encode_args.cc14
-rw-r--r--pw_tokenizer/generate_decoding_test_data.cc11
-rw-r--r--pw_tokenizer/java/dev/pigweed/tokenizer/detokenizer.cc4
-rw-r--r--pw_tokenizer/public/pw_tokenizer/base64.h11
-rw-r--r--pw_tokenizer/public/pw_tokenizer/detokenize.h11
-rw-r--r--pw_tokenizer/public/pw_tokenizer/internal/decode.h18
-rw-r--r--pw_tokenizer/pw_tokenizer_private/encode_args.h4
-rw-r--r--pw_tokenizer/token_database_fuzzer.cc8
-rw-r--r--pw_tokenizer/tokenize.cc10
-rw-r--r--pw_unit_test/simple_printing_main.cc4
-rw-r--r--pw_varint/public/pw_varint/varint.h10
106 files changed, 872 insertions, 767 deletions
diff --git a/pw_allocator/block.cc b/pw_allocator/block.cc
index 8f93ff47e..43fb209fe 100644
--- a/pw_allocator/block.cc
+++ b/pw_allocator/block.cc
@@ -16,7 +16,7 @@
namespace pw::allocator {
-Status Block::Init(const span<std::byte> region, Block** block) {
+Status Block::Init(const std::span<std::byte> region, Block** block) {
// Ensure the region we're given is aligned and sized accordingly
if (reinterpret_cast<uintptr_t>(region.data()) % alignof(Block) != 0) {
return Status::INVALID_ARGUMENT;
diff --git a/pw_allocator/block_test.cc b/pw_allocator/block_test.cc
index 7979bdc35..9fa56788f 100644
--- a/pw_allocator/block_test.cc
+++ b/pw_allocator/block_test.cc
@@ -14,8 +14,9 @@
#include "pw_allocator/block.h"
+#include <span>
+
#include "gtest/gtest.h"
-#include "pw_span/span.h"
using std::byte;
@@ -26,7 +27,7 @@ TEST(Block, CanCreateSingleBlock) {
alignas(Block*) byte bytes[kN];
Block* block = nullptr;
- auto status = Block::Init(span(bytes, kN), &block);
+ auto status = Block::Init(std::span(bytes, kN), &block);
ASSERT_EQ(status, Status::OK);
EXPECT_EQ(block->OuterSize(), kN);
@@ -45,7 +46,7 @@ TEST(Block, CannotCreateUnalignedSingleBlock) {
byte* byte_ptr = bytes;
Block* block = nullptr;
- auto status = Block::Init(span(byte_ptr + 1, kN - 1), &block);
+ auto status = Block::Init(std::span(byte_ptr + 1, kN - 1), &block);
EXPECT_EQ(status, Status::INVALID_ARGUMENT);
}
@@ -54,7 +55,7 @@ TEST(Block, CannotCreateTooSmallBlock) {
constexpr size_t kN = 2;
alignas(Block*) byte bytes[kN];
Block* block = nullptr;
- auto status = Block::Init(span(bytes, kN), &block);
+ auto status = Block::Init(std::span(bytes, kN), &block);
EXPECT_EQ(status, Status::INVALID_ARGUMENT);
}
@@ -65,7 +66,7 @@ TEST(Block, CanSplitBlock) {
alignas(Block*) byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(kSplitN, &next_block);
@@ -96,7 +97,7 @@ TEST(Block, CanSplitBlockUnaligned) {
uintptr_t split_len = split_addr - (uintptr_t)&bytes;
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(kSplitN, &next_block);
@@ -126,7 +127,7 @@ TEST(Block, CanSplitMidBlock) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* block2 = nullptr;
block->Split(kSplit1, &block2);
@@ -146,7 +147,7 @@ TEST(Block, CannotSplitBlockWithoutHeaderSpace) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(kSplitN, &next_block);
@@ -161,7 +162,7 @@ TEST(Block, MustProvideNextBlockPointer) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
auto status = block->Split(kSplitN, nullptr);
EXPECT_EQ(status, Status::INVALID_ARGUMENT);
@@ -173,7 +174,7 @@ TEST(Block, CannotMakeBlockLargerInSplit) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(block->InnerSize() + 1, &next_block);
@@ -187,7 +188,7 @@ TEST(Block, CanMakeZeroSizeFirstBlock) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(0, &next_block);
@@ -202,7 +203,7 @@ TEST(Block, CanMakeZeroSizeSecondBlock) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
auto status = block->Split(block->InnerSize() - sizeof(Block), &next_block);
@@ -216,7 +217,7 @@ TEST(Block, CanMarkBlockUsed) {
alignas(Block*) byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
block->MarkUsed();
EXPECT_EQ(block->Used(), true);
@@ -234,7 +235,7 @@ TEST(Block, CannotSplitUsedBlock) {
alignas(Block*) byte bytes[kN];
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
block->MarkUsed();
@@ -252,7 +253,7 @@ TEST(Block, CanMergeWithNextBlock) {
byte bytes[kN];
Block* block = nullptr;
- Block::Init(pw::span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* block2 = nullptr;
block->Split(kSplit1, &block2);
@@ -278,7 +279,7 @@ TEST(Block, CannotMergeWithFirstOrLastBlock) {
// Do a split, just to sanity check that the checks on Next/Prev are
// different...
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
block->Split(512, &next_block);
@@ -294,7 +295,7 @@ TEST(Block, CannotMergeUsedBlock) {
// Do a split, just to sanity check that the checks on Next/Prev are
// different...
Block* block = nullptr;
- Block::Init(span(bytes, kN), &block);
+ Block::Init(std::span(bytes, kN), &block);
Block* next_block = nullptr;
block->Split(512, &next_block);
diff --git a/pw_allocator/freelist.cc b/pw_allocator/freelist.cc
index 34bcbb7be..4629a4f15 100644
--- a/pw_allocator/freelist.cc
+++ b/pw_allocator/freelist.cc
@@ -16,7 +16,7 @@
namespace pw::allocator {
-Status FreeList::AddChunk(span<std::byte> chunk) {
+Status FreeList::AddChunk(std::span<std::byte> chunk) {
// Check that the size is enough to actually store what we need
if (chunk.size() < sizeof(FreeListNode)) {
return Status::OUT_OF_RANGE;
@@ -39,9 +39,9 @@ Status FreeList::AddChunk(span<std::byte> chunk) {
return Status::OK;
}
-span<std::byte> FreeList::FindChunk(size_t size) const {
+std::span<std::byte> FreeList::FindChunk(size_t size) const {
if (size == 0) {
- return span<std::byte>();
+ return std::span<std::byte>();
}
size_t chunk_ptr = FindChunkPtrForSize(size, true);
@@ -49,7 +49,7 @@ span<std::byte> FreeList::FindChunk(size_t size) const {
// Check that there's data. This catches the case where we run off the
// end of the array
if (chunks_[chunk_ptr] == nullptr) {
- return span<std::byte>();
+ return std::span<std::byte>();
}
// Now iterate up the buckets, walking each list to find a good candidate
@@ -62,7 +62,7 @@ span<std::byte> FreeList::FindChunk(size_t size) const {
while (aliased.node != nullptr) {
if (aliased.node->size >= size) {
- return span<std::byte>(aliased.data, aliased.node->size);
+ return std::span<std::byte>(aliased.data, aliased.node->size);
}
aliased.node = aliased.node->next;
@@ -71,10 +71,10 @@ span<std::byte> FreeList::FindChunk(size_t size) const {
// If we get here, we've checked every block in every bucket. There's
// nothing that can support this allocation.
- return span<std::byte>();
+ return std::span<std::byte>();
}
-Status FreeList::RemoveChunk(span<std::byte> chunk) {
+Status FreeList::RemoveChunk(std::span<std::byte> chunk) {
size_t chunk_ptr = FindChunkPtrForSize(chunk.size(), true);
// Walk that list, finding the chunk.
diff --git a/pw_allocator/freelist_heap.cc b/pw_allocator/freelist_heap.cc
index 7966bb89f..dfaba56bb 100644
--- a/pw_allocator/freelist_heap.cc
+++ b/pw_allocator/freelist_heap.cc
@@ -18,7 +18,7 @@
namespace pw::allocator {
-FreeListHeap::FreeListHeap(span<std::byte> region, FreeList& freelist)
+FreeListHeap::FreeListHeap(std::span<std::byte> region, FreeList& freelist)
: freelist_(freelist) {
Block* block;
Block::Init(region, &block);
diff --git a/pw_allocator/freelist_heap_test.cc b/pw_allocator/freelist_heap_test.cc
index 5356c4334..a28b31dc2 100644
--- a/pw_allocator/freelist_heap_test.cc
+++ b/pw_allocator/freelist_heap_test.cc
@@ -14,8 +14,9 @@
#include "pw_allocator/freelist_heap.h"
+#include <span>
+
#include "gtest/gtest.h"
-#include "pw_span/span.h"
namespace pw::allocator {
diff --git a/pw_allocator/freelist_test.cc b/pw_allocator/freelist_test.cc
index 9a1c5a332..0484a7a33 100644
--- a/pw_allocator/freelist_test.cc
+++ b/pw_allocator/freelist_test.cc
@@ -14,8 +14,9 @@
#include "pw_allocator/freelist.h"
+#include <span>
+
#include "gtest/gtest.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
using std::byte;
@@ -41,7 +42,7 @@ TEST(FreeList, CanRetrieveAddedMember) {
byte data[kN] = {std::byte(0)};
- auto status = list.AddChunk(pw::span(data, kN));
+ auto status = list.AddChunk(std::span(data, kN));
EXPECT_EQ(status, Status::OK);
auto item = list.FindChunk(kN);
@@ -55,7 +56,7 @@ TEST(FreeList, CanRetrieveAddedMemberForSmallerSize) {
byte data[kN] = {std::byte(0)};
- list.AddChunk(pw::span(data, kN));
+ list.AddChunk(std::span(data, kN));
auto item = list.FindChunk(kN / 2);
EXPECT_EQ(item.size(), kN);
EXPECT_EQ(item.data(), data);
@@ -67,8 +68,8 @@ TEST(FreeList, CanRemoveItem) {
byte data[kN] = {std::byte(0)};
- list.AddChunk(pw::span(data, kN));
- auto status = list.RemoveChunk(pw::span(data, kN));
+ list.AddChunk(std::span(data, kN));
+ auto status = list.RemoveChunk(std::span(data, kN));
EXPECT_EQ(status, Status::OK);
auto item = list.FindChunk(kN);
@@ -83,8 +84,8 @@ TEST(FreeList, FindReturnsSmallestChunk) {
byte data1[kN1] = {std::byte(0)};
byte data2[kN2] = {std::byte(0)};
- list.AddChunk(pw::span(data1, kN1));
- list.AddChunk(pw::span(data2, kN2));
+ list.AddChunk(std::span(data1, kN1));
+ list.AddChunk(std::span(data2, kN2));
auto chunk = list.FindChunk(kN1 / 2);
EXPECT_EQ(chunk.size(), kN1);
@@ -110,8 +111,8 @@ TEST(FreeList, FindReturnsCorrectChunkInSameBucket) {
byte data2[kN2] = {std::byte(0)};
// List should now be 257 -> 512 -> NULL
- list.AddChunk(pw::span(data1, kN1));
- list.AddChunk(pw::span(data2, kN2));
+ list.AddChunk(std::span(data1, kN1));
+ list.AddChunk(std::span(data2, kN2));
auto chunk = list.FindChunk(kN2 + 1);
EXPECT_EQ(chunk.size(), kN1);
@@ -130,8 +131,8 @@ TEST(FreeList, FindCanMoveUpThroughBuckets) {
// List should now be:
// bkt[3] (257 bytes up to 512 bytes) -> 257 -> NULL
// bkt[4] (513 bytes up to 1024 bytes) -> 513 -> NULL
- list.AddChunk(pw::span(data1, kN1));
- list.AddChunk(pw::span(data2, kN2));
+ list.AddChunk(std::span(data1, kN1));
+ list.AddChunk(std::span(data2, kN2));
// Request a 300 byte chunk. This should return the 513 byte one
auto chunk = list.FindChunk(kN1 + 1);
@@ -145,8 +146,8 @@ TEST(FreeList, RemoveUnknownChunkReturnsNotFound) {
byte data[kN] = {std::byte(0)};
byte data2[kN] = {std::byte(0)};
- list.AddChunk(pw::span(data, kN));
- auto status = list.RemoveChunk(pw::span(data2, kN));
+ list.AddChunk(std::span(data, kN));
+ auto status = list.RemoveChunk(std::span(data2, kN));
EXPECT_EQ(status, Status::NOT_FOUND);
}
@@ -157,8 +158,8 @@ TEST(FreeList, CanStoreMultipleChunksPerBucket) {
byte data1[kN] = {std::byte(0)};
byte data2[kN] = {std::byte(0)};
- list.AddChunk(pw::span(data1, kN));
- list.AddChunk(pw::span(data2, kN));
+ list.AddChunk(std::span(data1, kN));
+ list.AddChunk(std::span(data2, kN));
auto chunk1 = list.FindChunk(kN);
list.RemoveChunk(chunk1);
diff --git a/pw_allocator/public/pw_allocator/block.h b/pw_allocator/public/pw_allocator/block.h
index 2fa40523b..e12349aa7 100644
--- a/pw_allocator/public/pw_allocator/block.h
+++ b/pw_allocator/public/pw_allocator/block.h
@@ -16,7 +16,8 @@
// usable.
#pragma once
-#include "pw_span/span.h"
+#include <span>
+
#include "pw_status/status.h"
namespace pw::allocator {
@@ -80,7 +81,7 @@ class Block final {
// Returns:
// INVALID_ARGUMENT if the given region is unaligned to too small, or
// OK otherwise.
- static Status Init(const span<std::byte> region, Block** block);
+ static Status Init(const std::span<std::byte> region, Block** block);
// Returns a pointer to a Block, given a pointer to the start of the usable
// space inside the block (i.e. the opposite operation to UsableSpace()). In
diff --git a/pw_allocator/public/pw_allocator/freelist.h b/pw_allocator/public/pw_allocator/freelist.h
index ac4444a36..207edbac2 100644
--- a/pw_allocator/public/pw_allocator/freelist.h
+++ b/pw_allocator/public/pw_allocator/freelist.h
@@ -14,9 +14,9 @@
#pragma once
#include <array>
+#include <span>
#include "pw_containers/vector.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::allocator {
@@ -64,19 +64,19 @@ class FreeList {
// OK: The chunk was added successfully
// OUT_OF_RANGE: The chunk could not be added for size reasons (e.g. if
// the chunk is too small to store the FreeListNode).
- Status AddChunk(span<std::byte> chunk);
+ Status AddChunk(std::span<std::byte> chunk);
// Finds an eligible chunk for an allocation of size `size`. Note that this
// will return the first allocation possible within a given bucket, it does
- // not currently optimize for finding the smallest chunk. Returns a pw::span
+ // not currently optimize for finding the smallest chunk. Returns a std::span
// representing the chunk. This will be "valid" on success, and will have size
// = 0 on failure (if there were no chunks available for that allocation).
- span<std::byte> FindChunk(size_t size) const;
+ std::span<std::byte> FindChunk(size_t size) const;
// Remove a chunk from this freelist. Returns:
// OK: The chunk was removed successfully
// NOT_FOUND: The chunk could not be found in this freelist.
- Status RemoveChunk(span<std::byte> chunk);
+ Status RemoveChunk(std::span<std::byte> chunk);
private:
// For a given size, find which index into chunks_ the node should be written
diff --git a/pw_allocator/public/pw_allocator/freelist_heap.h b/pw_allocator/public/pw_allocator/freelist_heap.h
index c3c015edf..cf44ffd47 100644
--- a/pw_allocator/public/pw_allocator/freelist_heap.h
+++ b/pw_allocator/public/pw_allocator/freelist_heap.h
@@ -15,16 +15,16 @@
#pragma once
#include <cstddef>
+#include <span>
#include "pw_allocator/block.h"
#include "pw_allocator/freelist.h"
-#include "pw_span/span.h"
namespace pw::allocator {
class FreeListHeap {
public:
- FreeListHeap(span<std::byte> region, FreeList& freelist);
+ FreeListHeap(std::span<std::byte> region, FreeList& freelist);
void* Allocate(size_t size);
void Free(void* ptr);
@@ -32,11 +32,11 @@ class FreeListHeap {
void* Calloc(size_t num, size_t size);
private:
- span<std::byte> BlockToSpan(Block* block) {
- return span<std::byte>(block->UsableSpace(), block->InnerSize());
+ std::span<std::byte> BlockToSpan(Block* block) {
+ return std::span<std::byte>(block->UsableSpace(), block->InnerSize());
}
- span<std::byte> region_;
+ std::span<std::byte> region_;
FreeList& freelist_;
};
@@ -46,7 +46,7 @@ class FreeListHeapBuffer {
static constexpr std::array<size_t, N> defaultBuckets{
16, 32, 64, 128, 256, 512};
- FreeListHeapBuffer(span<std::byte> region)
+ FreeListHeapBuffer(std::span<std::byte> region)
: freelist_(defaultBuckets), heap_(region, freelist_) {}
void* Allocate(size_t size) { return heap_.Allocate(size); }
diff --git a/pw_assert/fake_backend.cc b/pw_assert/fake_backend.cc
index b81c106bc..8ab2279d2 100644
--- a/pw_assert/fake_backend.cc
+++ b/pw_assert/fake_backend.cc
@@ -15,8 +15,8 @@
#include "pw_assert_test/fake_backend.h"
#include <cstring>
+#include <span>
-#include "pw_span/span.h"
#include "pw_string/string_builder.h"
// Global that's publicly accessible to read captured assert contents.
diff --git a/pw_base64/base64.cc b/pw_base64/base64.cc
index c708bb599..7b2396c4e 100644
--- a/pw_base64/base64.cc
+++ b/pw_base64/base64.cc
@@ -154,7 +154,8 @@ extern "C" bool pw_Base64IsValid(const char* base64_data, size_t base64_size) {
return true;
}
-size_t Encode(span<const std::byte> binary, span<char> output_buffer) {
+size_t Encode(std::span<const std::byte> binary,
+ std::span<char> output_buffer) {
const size_t required_size = EncodedSize(binary.size_bytes());
if (output_buffer.size_bytes() < required_size) {
return 0;
@@ -163,7 +164,7 @@ size_t Encode(span<const std::byte> binary, span<char> output_buffer) {
return required_size;
}
-size_t Decode(std::string_view base64, span<std::byte> output_buffer) {
+size_t Decode(std::string_view base64, std::span<std::byte> output_buffer) {
if (output_buffer.size_bytes() < MaxDecodedSize(base64.size()) ||
!IsValid(base64)) {
return 0;
diff --git a/pw_base64/base64_test.cc b/pw_base64/base64_test.cc
index 0dfcfd77b..17e534854 100644
--- a/pw_base64/base64_test.cc
+++ b/pw_base64/base64_test.cc
@@ -285,7 +285,8 @@ TEST(Base64, Encode_SingleChar) {
for (const EncodedData& data : kSingleCharTestData) {
const size_t size = EncodedSize(data.binary_size);
ASSERT_EQ(std::strlen(data.encoded_data), size);
- Encode(as_bytes(span(data.binary_data, data.binary_size)), output);
+ Encode(std::as_bytes(std::span(data.binary_data, data.binary_size)),
+ output);
output[size] = '\0';
EXPECT_STREQ(data.encoded_data, output);
}
@@ -296,7 +297,8 @@ TEST(Base64, Encode_RandomData) {
for (const EncodedData& data : kRandomTestData) {
const size_t size = EncodedSize(data.binary_size);
ASSERT_EQ(std::strlen(data.encoded_data), size);
- Encode(as_bytes(span(data.binary_data, data.binary_size)), output);
+ Encode(std::as_bytes(std::span(data.binary_data, data.binary_size)),
+ output);
output[size] = '\0';
EXPECT_STREQ(data.encoded_data, output);
}
@@ -306,9 +308,9 @@ TEST(Base64, Encode_BoundaryCheck) {
constexpr std::byte data[] = {std::byte{'h'}, std::byte{'i'}};
char output[5] = {};
- EXPECT_EQ(0u, Encode(data, span(output, 3)));
+ EXPECT_EQ(0u, Encode(data, std::span(output, 3)));
EXPECT_STREQ("", output);
- EXPECT_EQ(4u, Encode(data, span(output, 4)));
+ EXPECT_EQ(4u, Encode(data, std::span(output, 4)));
EXPECT_STREQ("aGk=", output);
}
@@ -334,9 +336,9 @@ TEST(Base64, Decode_BoundaryCheck) {
constexpr const char encoded_data[] = "aGk=";
std::byte output[4] = {};
- EXPECT_EQ(0u, Decode(encoded_data, span(output, 2)));
+ EXPECT_EQ(0u, Decode(encoded_data, std::span(output, 2)));
EXPECT_STREQ("", reinterpret_cast<const char*>(output));
- EXPECT_EQ(2u, Decode(encoded_data, span(output, 3)));
+ EXPECT_EQ(2u, Decode(encoded_data, std::span(output, 3)));
EXPECT_STREQ("hi", reinterpret_cast<const char*>(output));
}
@@ -360,7 +362,7 @@ TEST(Base64, Decode_UrlSafeDecode) {
TEST(Base64, Empty) {
char buffer[] = "DO NOT TOUCH";
EXPECT_EQ(0u, EncodedSize(0));
- Encode(as_bytes(span("Something cool!!!", 0)), buffer);
+ Encode(std::as_bytes(std::span("Something cool!!!", 0)), buffer);
EXPECT_STREQ("DO NOT TOUCH", buffer);
EXPECT_EQ(0u, MaxDecodedSize(0));
@@ -372,11 +374,11 @@ TEST(Base64, ExampleFromRfc3548Section7) {
constexpr uint8_t input[] = {0x14, 0xfb, 0x9c, 0x03, 0xd9, 0x7e};
char output[EncodedSize(sizeof(input)) + 1] = {};
- Encode(as_bytes(span(input)), output);
+ Encode(std::as_bytes(std::span(input)), output);
EXPECT_STREQ("FPucA9l+", output);
- Encode(as_bytes(span(input, 5)), output);
+ Encode(std::as_bytes(std::span(input, 5)), output);
EXPECT_STREQ("FPucA9k=", output);
- Encode(as_bytes(span(input, 4)), output);
+ Encode(std::as_bytes(std::span(input, 4)), output);
EXPECT_STREQ("FPucAw==", output);
EXPECT_EQ(6u, Decode("FPucA9l+", output));
@@ -391,19 +393,19 @@ TEST(Base64, ExampleFromRfc4648Section9) {
char output[EncodedSize(sizeof("foobar")) + 1] = {};
const std::byte* foobar = reinterpret_cast<const std::byte*>("foobar");
- Encode(span(foobar, 0), output);
+ Encode(std::span(foobar, 0), output);
EXPECT_STREQ("", output);
- Encode(span(foobar, 1), output);
+ Encode(std::span(foobar, 1), output);
EXPECT_STREQ("Zg==", output);
- Encode(span(foobar, 2), output);
+ Encode(std::span(foobar, 2), output);
EXPECT_STREQ("Zm8=", output);
- Encode(span(foobar, 3), output);
+ Encode(std::span(foobar, 3), output);
EXPECT_STREQ("Zm9v", output);
- Encode(span(foobar, 4), output);
+ Encode(std::span(foobar, 4), output);
EXPECT_STREQ("Zm9vYg==", output);
- Encode(span(foobar, 5), output);
+ Encode(std::span(foobar, 5), output);
EXPECT_STREQ("Zm9vYmE=", output);
- Encode(span(foobar, 6), output);
+ Encode(std::span(foobar, 6), output);
EXPECT_STREQ("Zm9vYmFy", output);
std::memset(output, '\0', sizeof(output));
diff --git a/pw_base64/public/pw_base64/base64.h b/pw_base64/public/pw_base64/base64.h
index 24c425e27..e90510ce7 100644
--- a/pw_base64/public/pw_base64/base64.h
+++ b/pw_base64/public/pw_base64/base64.h
@@ -63,11 +63,10 @@ bool pw_Base64IsValid(const char* base64_data, size_t base64_size);
#ifdef __cplusplus
} // extern "C"
+#include <span>
#include <string_view>
#include <type_traits>
-#include "pw_span/span.h"
-
namespace pw::base64 {
// Returns the size of the given number of bytes when encoded as Base64. Base64
@@ -84,14 +83,14 @@ constexpr size_t EncodedSize(size_t binary_size_bytes) {
// output buffers MUST NOT be the same; encoding cannot occur in place.
//
// The resulting string in the output is NOT null-terminated!
-inline void Encode(span<const std::byte> binary, char* output) {
+inline void Encode(std::span<const std::byte> binary, char* output) {
pw_Base64Encode(binary.data(), binary.size_bytes(), output);
}
// Encodes the provided data in Base64 if the result fits in the provided
// buffer. Returns the number of bytes written, which will be 0 if the output
// buffer is too small.
-size_t Encode(span<const std::byte> binary, span<char> output_buffer);
+size_t Encode(std::span<const std::byte> binary, std::span<char> output_buffer);
// Returns the maximum size of decoded Base64 data in bytes. base64_size_bytes
// must be a multiple of 4, since Base64 encodes 3-byte groups into 4-character
@@ -117,7 +116,7 @@ inline size_t Decode(std::string_view base64, void* output) {
// Decodes the provided Base64 data, if the data is valid and fits in the output
// buffer. Returns the number of bytes written, which will be 0 if the data is
// invalid or doesn't fit.
-size_t Decode(std::string_view base64, span<std::byte> output_buffer);
+size_t Decode(std::string_view base64, std::span<std::byte> output_buffer);
// Returns true if the provided string is valid Base64 encoded data. Accepts
// either the standard (+/) or URL-safe (-_) alphabets.
diff --git a/pw_checksum/ccitt_crc16_test.cc b/pw_checksum/ccitt_crc16_test.cc
index 19b9c9c3d..e78f0e94c 100644
--- a/pw_checksum/ccitt_crc16_test.cc
+++ b/pw_checksum/ccitt_crc16_test.cc
@@ -35,7 +35,7 @@ constexpr std::string_view kString =
constexpr uint16_t kStringCrc = 0xC184;
TEST(Crc16, Empty) {
- EXPECT_EQ(CcittCrc16(span<std::byte>()), kCcittCrc16DefaultInitialValue);
+ EXPECT_EQ(CcittCrc16(std::span<std::byte>()), kCcittCrc16DefaultInitialValue);
}
TEST(Crc16, ByteByByte) {
@@ -47,11 +47,11 @@ TEST(Crc16, ByteByByte) {
}
TEST(Crc16, Buffer) {
- EXPECT_EQ(CcittCrc16(as_bytes(span(kBytes))), kBufferCrc);
+ EXPECT_EQ(CcittCrc16(std::as_bytes(std::span(kBytes))), kBufferCrc);
}
TEST(Crc16, String) {
- EXPECT_EQ(CcittCrc16(as_bytes(span(kString))), kStringCrc);
+ EXPECT_EQ(CcittCrc16(std::as_bytes(std::span(kString))), kStringCrc);
}
extern "C" uint16_t CallChecksumCcittCrc16(const void* data, size_t size_bytes);
diff --git a/pw_checksum/public/pw_checksum/ccitt_crc16.h b/pw_checksum/public/pw_checksum/ccitt_crc16.h
index c5679a883..4d43f93bd 100644
--- a/pw_checksum/public/pw_checksum/ccitt_crc16.h
+++ b/pw_checksum/public/pw_checksum/ccitt_crc16.h
@@ -34,7 +34,7 @@ uint16_t pw_ChecksumCcittCrc16(const void* data,
#ifdef __cplusplus
} // extern "C"
-#include "pw_span/span.h"
+#include <span>
namespace pw::checksum {
@@ -43,7 +43,7 @@ inline constexpr uint16_t kCcittCrc16DefaultInitialValue = 0xFFFF;
// Calculates the CCITT CRC16 for the provided data. To update an existing CRC,
// pass the previous value as the initial_value argument.
inline uint16_t CcittCrc16(
- span<const std::byte> data,
+ std::span<const std::byte> data,
uint16_t initial_value = kCcittCrc16DefaultInitialValue) {
return pw_ChecksumCcittCrc16(data.data(), data.size_bytes(), initial_value);
}
diff --git a/pw_cpu_exception/public/pw_cpu_exception/cpu_exception.h b/pw_cpu_exception/public/pw_cpu_exception/cpu_exception.h
index c01d25f55..b9b76f22c 100644
--- a/pw_cpu_exception/public/pw_cpu_exception/cpu_exception.h
+++ b/pw_cpu_exception/public/pw_cpu_exception/cpu_exception.h
@@ -28,9 +28,9 @@
// some part of your application.
#include <cstdint>
+#include <span>
#include "pw_preprocessor/compiler.h"
-#include "pw_span/span.h"
#include "pw_string/string_builder.h"
namespace pw::cpu_exception {
@@ -40,7 +40,7 @@ struct CpuState;
// Gets raw CPU state as a single contiguous block of data. The particular
// contents will depend on the specific backend and platform.
-span<const uint8_t> RawFaultingCpuState(const CpuState& cpu_state);
+std::span<const uint8_t> RawFaultingCpuState(const CpuState& cpu_state);
// Writes CPU state as a formatted string to a string builder.
// NEVER depend on the format of this output. This is exclusively FYI human
diff --git a/pw_cpu_exception_armv7m/cpu_state.cc b/pw_cpu_exception_armv7m/cpu_state.cc
index 9526c60f7..d3245a4bc 100644
--- a/pw_cpu_exception_armv7m/cpu_state.cc
+++ b/pw_cpu_exception_armv7m/cpu_state.cc
@@ -16,15 +16,16 @@
#include <cinttypes>
#include <cstdint>
+#include <span>
#include "pw_cpu_exception/cpu_exception.h"
-#include "pw_span/span.h"
#include "pw_string/string_builder.h"
namespace pw::cpu_exception {
-span<const uint8_t> RawFaultingCpuState(const CpuState& cpu_state) {
- return span(reinterpret_cast<const uint8_t*>(&cpu_state), sizeof(cpu_state));
+std::span<const uint8_t> RawFaultingCpuState(const CpuState& cpu_state) {
+ return std::span(reinterpret_cast<const uint8_t*>(&cpu_state),
+ sizeof(cpu_state));
}
// Using this function adds approximately 100 bytes to binary size.
diff --git a/pw_cpu_exception_armv7m/exception_entry_test.cc b/pw_cpu_exception_armv7m/exception_entry_test.cc
index 545c7a14a..fbd5fb36d 100644
--- a/pw_cpu_exception_armv7m/exception_entry_test.cc
+++ b/pw_cpu_exception_armv7m/exception_entry_test.cc
@@ -13,12 +13,12 @@
// the License.
#include <cstdint>
+#include <span>
#include <type_traits>
#include "gtest/gtest.h"
#include "pw_cpu_exception/cpu_exception.h"
#include "pw_cpu_exception_armv7m/cpu_state.h"
-#include "pw_span/span.h"
namespace pw::cpu_exception {
namespace {
@@ -137,7 +137,7 @@ size_t current_fault_depth = 0;
CpuState captured_states[kMaxFaultDepth] = {};
CpuState& captured_state = captured_states[0];
-// Flag used to check if the contents of span matches the captured state.
+// Flag used to check if the contents of std::span matches the captured state.
bool span_matches = false;
// Variable to be manipulated by function that uses floating
@@ -582,8 +582,8 @@ void HandleCpuException(CpuState* state) {
// Copy captured state to check later.
std::memcpy(&captured_states[exceptions_handled], state, sizeof(CpuState));
- // Ensure span compares to be the same.
- span<const uint8_t> state_span = RawFaultingCpuState(*state);
+ // Ensure std::span compares to be the same.
+ std::span<const uint8_t> state_span = RawFaultingCpuState(*state);
EXPECT_EQ(state_span.size(), sizeof(CpuState));
if (std::memcmp(state, state_span.data(), state_span.size()) == 0) {
span_matches = true;
diff --git a/pw_kvs/alignment.cc b/pw_kvs/alignment.cc
index 081d6c8e2..198ec14f0 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 2b25e9492..0f3dc89e9 100644
--- a/pw_kvs/alignment_test.cc
+++ b/pw_kvs/alignment_test.cc
@@ -125,11 +125,11 @@ 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));
// 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 @@ TEST(AlignedWriter, DestructorFlushes) {
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 @@ struct OutputWithErrorInjection final : public Output {
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 @@ TEST(AlignedWriter, Write_NoFurtherWritesOnFailure) {
{
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 @@ TEST(AlignedWriter, Write_ReturnsTotalBytesWritten) {
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_Ok_ReturnsTotalBytesWritten) {
}
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 @@ class InputWithErrorInjection final : public Input {
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 f5db06949..0a885f75f 100644
--- a/pw_kvs/checksum.cc
+++ b/pw_kvs/checksum.cc
@@ -20,7 +20,7 @@ namespace pw::kvs {
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 4f0d8c581..0db5ed214 100644
--- a/pw_kvs/checksum_test.cc
+++ b/pw_kvs/checksum_test.cc
@@ -32,19 +32,20 @@ TEST(Checksum, UpdateAndVerify) {
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 @@ TEST(Checksum, Verify_LargerState_ComparesToTruncatedData) {
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_VerifyWithoutData) {
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 size_t kAlignment = 10;
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 @@ class PickyChecksum final : public AlignedChecksum<kAlignment, 32> {
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 801a636ce..33435484a 100644
--- a/pw_kvs/entry.cc
+++ b/pw_kvs/entry.cc
@@ -34,7 +34,7 @@ Status Entry::Read(FlashPartition& partition,
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 @@ Entry::Entry(FlashPartition& partition,
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 @@ Entry::Entry(FlashPartition& partition,
.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 @@ StatusWithSize Entry::Copy(Address new_address) const {
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 @@ StatusWithSize Entry::ReadValue(span<byte> buffer, size_t offset_bytes) const {
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 @@ Status Entry::ValueMatches(span<const std::byte> value) const {
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 @@ Status Entry::ValueMatches(span<const std::byte> value) const {
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 @@ void Entry::DebugLog() const {
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 @@ span<const byte> Entry::CalculateChecksum(const string_view key,
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 @@ Status Entry::CalculateChecksumFromFlash() {
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 @@ Status Entry::CalculateChecksumFromFlash() {
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 599ae8010..116f27f06 100644
--- a/pw_kvs/entry_cache.cc
+++ b/pw_kvs/entry_cache.cc
@@ -44,7 +44,7 @@ void EntryMetadata::RemoveAddress(Address address_to_remove) {
// 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 @@ EntryMetadata EntryCache::AddNew(const KeyDescriptor& descriptor,
// 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 @@ void EntryCache::AddAddressIfRoom(size_t descriptor_index,
}
}
-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 @@ span<EntryCache::Address> EntryCache::addresses(size_t descriptor_index) const {
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 553ed52f4..d25003996 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 @@ TEST(Entry, Construct_ValidEntry) {
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, ReadKey) {
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) {
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_BufferTooSmall) {
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) {
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_BufferTooSmall) {
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_EmptyRead) {
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, ReadKey) {
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 @@ TEST_F(ValidEntryInFlash, Copy_ReadError) {
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 @@ constexpr uint32_t ByteSum(span<const byte> bytes, uint32_t value = 0) {
// 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 95987f389..39f5590ff 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 @@ Status FakeFlashMemory::Erase(Address address, size_t num_sectors) {
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::Read(Address address, span<std::byte> output) {
}
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 242f13e6d..30af38fe0 100644
--- a/pw_kvs/flash_memory.cc
+++ b/pw_kvs/flash_memory.cc
@@ -28,13 +28,13 @@ namespace pw::kvs {
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 @@ Status FlashPartition::Erase(Address address, size_t num_sectors) {
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 @@ Status FlashPartition::IsRegionErased(Address source_flash_address,
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 68a8412fd..a10659230 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -39,7 +39,7 @@ constexpr bool InvalidKey(std::string_view key) {
} // 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 @@ Status KeyValueStore::ScanForEntry(const SectorDescriptor& sector,
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 @@ Status KeyValueStore::ScanForEntry(const SectorDescriptor& sector,
}
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 @@ StatusWithSize KeyValueStore::Get(string_view key,
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 @@ Status KeyValueStore::FindExisting(string_view key,
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 @@ Status KeyValueStore::FixedSizeGet(std::string_view key,
}
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::CheckReadOperation(string_view key) const {
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::WriteEntryForExistingKey(EntryMetadata& metadata,
}
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::WriteEntryForNewKey(string_view key,
}
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 @@ Status KeyValueStore::GetAddressesForWrite(Address* write_addresses,
size_t write_size) {
for (size_t i = 0; i < redundancy(); i++) {
SectorDescriptor* sector;
- TRY(GetSectorForWrite(&sector, write_size, span(write_addresses, i)));
+ TRY(GetSectorForWrite(&sector, 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 @@ Status KeyValueStore::GetAddressesForWrite(Address* write_addresses,
// 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::MarkSectorCorruptIfNotOk(Status status,
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 @@ StatusWithSize KeyValueStore::CopyEntryToSector(Entry& entry,
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 @@ Status KeyValueStore::PartialMaintenance() {
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::GarbageCollect(span<const Address> reserved_addresses) {
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::RelocateKeyAddressesInSector(
};
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 @@ Status KeyValueStore::EnsureFreeSectorExists() {
}
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 @@ Status KeyValueStore::Repair() {
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 079396da0..5921e82b6 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 @@ using std::string_view;
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 @@ constexpr uint32_t SimpleChecksum(span<const byte> data, uint32_t state) {
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 @@ constexpr auto EntryPadding() {
}
// 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 @@ constexpr auto MakeValidEntry(uint32_t magic,
uint16_t(kValueSize),
id,
ByteStr(key),
- span(value),
+ std::span(value),
EntryPadding<kAlignmentBytes, kKeyLength, kValueSize>());
// Calculate the checksum
@@ -99,7 +101,8 @@ constexpr auto MakeValidEntry(uint32_t magic,
}
// 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 @@ class KvsErrorHandling : public ::testing::Test {
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 @@ TEST_F(KvsErrorHandling, Init_CorruptKey_RevertsToPreviousVersion) {
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 @@ TEST_F(KvsErrorHandling, Put_WriteFailure_EntryNotAddedButBytesMarkedWritten) {
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 @@ class KvsErrorRecovery : public ::testing::Test {
{.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 @@ TEST_F(KvsErrorRecovery, Init_CorruptKey_RevertsToPreviousVersion) {
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 @@ TEST_F(KvsErrorRecovery, Put_WriteFailure_EntryNotAddedButBytesMarkedWritten) {
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 @@ TEST_F(KvsErrorRecovery, Put_WriteFailure_EntryNotAddedButBytesMarkedWritten) {
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 @@ ChecksumFunction<uint32_t> alt_checksum(AltChecksum);
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 @@ class InitializedRedundantMultiMagicKvs : public ::testing::Test {
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 @@ TEST_F(InitializedRedundantMultiMagicKvs, SingleWriteError) {
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 @@ TEST_F(InitializedRedundantMultiMagicKvs, SingleWriteError) {
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 @@ TEST_F(InitializedRedundantMultiMagicKvs, DataLossAfterLosingBothCopies) {
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 @@ TEST_F(InitializedRedundantMultiMagicKvs, PutExistingEntry_UsesFirstFormat) {
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 @@ TEST_F(InitializedRedundantLazyRecoveryKvs, WriteAfterDataLoss) {
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 8ef1ebc9b..2a3475021 100644
--- a/pw_kvs/key_value_store_fuzz_test.cc
+++ b/pw_kvs/key_value_store_fuzz_test.cc
@@ -63,7 +63,7 @@ TEST_F(EmptyInitializedKvs, Put_VaryingKeysAndValues) {
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 13333640c..35840ef98 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[13] == std::byte{0xff});
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<bool[1]>());
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 @@ struct FlashWithPartitionFake {
}
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 @@ class EmptyInitializedKvs : public ::testing::Test {
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 @@ TEST_F(EmptyInitializedKvs, Put_SameKeySameValueRepeatedly_AlignedEntries) {
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 @@ TEST_F(EmptyInitializedKvs, Put_SameKeySameValueRepeatedly_UnalignedEntries) {
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 @@ TEST_F(EmptyInitializedKvs, Put_MaxValueSize) {
// 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_ConvertibleToSpan) {
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, PutAndGetByValue_NotConvertibleToSpan) {
}
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, GetValue_TooLarge) {
}
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_GetDeletedKey_ReturnsNotFound) {
}
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 @@ TEST_F(EmptyInitializedKvs, Delete_AddBackKey_PersistsAfterInitialization) {
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_Empty_ByValue) {
}
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_OneItem) {
}
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_GetValue_TooLarge) {
}
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 @@ TEST_F(EmptyInitializedKvs, FuzzTest) {
}
// 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 @@ TEST_F(EmptyInitializedKvs, FuzzTest) {
// 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, FuzzTest) {
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 @@ TEST_F(EmptyInitializedKvs, Basic) {
// 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 @@ TEST(InMemoryKvs, Basic) {
// 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 @@ TEST_F(EmptyInitializedKvs, RewriteValue) {
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 @@ TEST_F(EmptyInitializedKvs, RepeatingValueWithOtherData) {
// 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 @@ TEST_F(EmptyInitializedKvs, RepeatingValueWithOtherData) {
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 @@ TEST_F(EmptyInitializedKvs, RepeatingValueWithOtherData) {
// 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 @@ TEST_F(EmptyInitializedKvs, OffsetRead) {
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 @@ TEST_F(EmptyInitializedKvs, FillSector) {
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 @@ TEST_F(EmptyInitializedKvs, FillSector) {
// 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 @@ TEST_F(EmptyInitializedKvs, Interleaved) {
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 @@ TEST_F(EmptyInitializedKvs, FillSector2) {
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_Positive) {
}
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_MissingKey) {
}
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 e9075768b..eb5f93052 100644
--- a/pw_kvs/key_value_store_wear_test.cc
+++ b/pw_kvs/key_value_store_wear_test.cc
@@ -63,7 +63,7 @@ TEST_F(WearTest, RepeatedLargeEntry) {
// 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 @@ TEST_F(WearTest, TwoPassFillWithLargeAndLarger) {
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 f15375634..e8cf191ed 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 @@ constexpr size_t Padding(size_t length, size_t alignment) {
// 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 @@ class AlignedWriter {
// 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 @@ class AlignedWriterBuffer : public AlignedWriter {
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 @@ StatusWithSize AlignedWrite(Output& output,
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 @@ StatusWithSize AlignedWrite(Output& output,
// 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 ff89d4471..5899566d3 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 @@ class ChecksumAlgorithm {
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 @@ class ChecksumAlgorithm {
// 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 @@ class IgnoreChecksum final : public ChecksumAlgorithm {
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 @@ class IgnoreChecksum final : public ChecksumAlgorithm {
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 @@ class AlignedChecksum : public ChecksumAlgorithm {
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 51b096b24..6cbef1f93 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 a0916bffc..5dc839c1b 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 @@ class FlashError {
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 @@ class FakeFlashMemory : public FlashMemory {
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 @@ class FakeFlashMemory : public FlashMemory {
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 @@ class FakeFlashMemory : public FlashMemory {
}
private:
- const span<std::byte> buffer_;
+ const std::span<std::byte> buffer_;
Vector<FlashError>& read_errors_;
Vector<FlashError>& write_errors_;
};
@@ -156,7 +157,7 @@ class FakeFlashMemoryBuffer : public FakeFlashMemory {
// 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 b28441509..ac8f429f3 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 @@ class FlashMemory {
// 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 @@ class FlashMemory {
// 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 @@ class FlashPartition {
: 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 @@ class FlashPartition {
: 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 @@ class FlashPartition {
// 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 @@ class FlashPartition {
// 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 @@ class FlashPartition {
// 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 9393fd961..569ab9fd1 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 @@ class FlashPartitionWithStats : public FlashPartition {
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 a2d843a4a..f6b33e7cf 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 @@ static_assert(sizeof(EntryHeader) == 16, "EntryHeader must not have padding");
// 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 @@ class EntryFormats {
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 3e75aebd9..5305ab6b0 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 @@ class Entry {
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 @@ class Entry {
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 @@ class Entry {
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 @@ class Entry {
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 @@ class Entry {
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 5ed2f1571..f34773896 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 @@ class EntryMetadata {
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 @@ class EntryMetadata {
// 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 @@ class EntryMetadata {
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 @@ class EntryCache {
// 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 7f89bb566..d2f456505 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 @@ class Sectors {
// 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 @@ class Sectors {
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 @@ class Sectors {
// 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 @@ class Sectors {
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 18098ed77..4c4ab5628 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 @@ constexpr bool ConvertsToSpan(...) {
} // 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 71d1eb24b..167182f64 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 @@ struct FunctionTraits<ReturnType (T::*)(Args...)> {
} // 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 @@ class OutputToMethod final : public Output {
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 @@ class OutputToMethod final : public Output {
// 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 f382c60ae..01b055dbb 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 @@ class KeyValueStore {
// 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 @@ class KeyValueStore {
// 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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
// 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 @@ class KeyValueStore {
// 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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStore {
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 @@ class KeyValueStoreBuffer : public KeyValueStore {
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 @@ class KeyValueStoreBuffer : public KeyValueStore {
// 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 d36e01c05..01547ecf6 100644
--- a/pw_kvs/sectors.cc
+++ b/pw_kvs/sectors.cc
@@ -33,8 +33,8 @@ bool Contains(const Container& container, const T& value) {
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 @@ Status Sectors::Find(FindMode find_mode,
}
// 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 @@ SectorDescriptor& Sectors::WearLeveledSectorFromIndex(size_t idx) const {
// 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 @@ SectorDescriptor* Sectors::FindSectorToGarbageCollect(
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
diff --git a/pw_protobuf/codegen_test.cc b/pw_protobuf/codegen_test.cc
index 1001a8689..c9845c9f6 100644
--- a/pw_protobuf/codegen_test.cc
+++ b/pw_protobuf/codegen_test.cc
@@ -166,7 +166,7 @@ TEST(Codegen, Codegen) {
};
// clang-format on
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -185,7 +185,7 @@ TEST(CodegenRepeated, NonPackedScalar) {
constexpr uint8_t expected_proto[] = {
0x08, 0x00, 0x08, 0x10, 0x08, 0x20, 0x08, 0x30};
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -201,7 +201,7 @@ TEST(CodegenRepeated, PackedScalar) {
repeated_test.WriteUint32s(values);
constexpr uint8_t expected_proto[] = {0x0a, 0x04, 0x00, 0x10, 0x20, 0x30};
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -221,7 +221,7 @@ TEST(CodegenRepeated, NonScalar) {
constexpr uint8_t expected_proto[] = {
0x1a, 0x03, 't', 'h', 'e', 0x1a, 0x5, 'q', 'u', 'i', 'c', 'k',
0x1a, 0x5, 'b', 'r', 'o', 'w', 'n', 0x1a, 0x3, 'f', 'o', 'x'};
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -245,7 +245,7 @@ TEST(CodegenRepeated, Message) {
0x01, 0x10, 0x02, 0x2a, 0x04, 0x08, 0x02, 0x10, 0x04};
// clang-format on
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -269,7 +269,7 @@ TEST(Codegen, Proto2) {
constexpr uint8_t expected_proto[] = {
0x08, 0x03, 0x1a, 0x06, 0x0a, 0x04, 0xde, 0xad, 0xbe, 0xef};
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
EXPECT_EQ(proto.size(), sizeof(expected_proto));
EXPECT_EQ(std::memcmp(proto.data(), expected_proto, sizeof(expected_proto)),
@@ -293,7 +293,7 @@ TEST(Codegen, Import) {
end.WriteNanoseconds(490367432);
}
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
}
@@ -306,7 +306,7 @@ TEST(Codegen, NonPigweedPackage) {
packed.WriteRep(std::span<const int64_t>(repeated));
packed.WritePacked("packed");
- span<const std::byte> proto;
+ std::span<const std::byte> proto;
EXPECT_EQ(encoder.Encode(&proto), Status::OK);
}
diff --git a/pw_protobuf/decoder.cc b/pw_protobuf/decoder.cc
index 31835561b..72127bea5 100644
--- a/pw_protobuf/decoder.cc
+++ b/pw_protobuf/decoder.cc
@@ -100,7 +100,7 @@ Status Decoder::ReadBool(bool* out) {
}
Status Decoder::ReadString(std::string_view* out) {
- span<const std::byte> bytes;
+ std::span<const std::byte> bytes;
Status status = ReadDelimited(&bytes);
if (!status.ok()) {
return status;
@@ -117,7 +117,7 @@ size_t Decoder::FieldSize() const {
return 0;
}
- span<const std::byte> remainder = proto_.subspan(key_size);
+ std::span<const std::byte> remainder = proto_.subspan(key_size);
WireType wire_type = static_cast<WireType>(key & kWireTypeMask);
uint64_t value = 0;
size_t expected_size = 0;
@@ -207,7 +207,7 @@ Status Decoder::ReadFixed(std::byte* out, size_t size) {
return Status::OK;
}
-Status Decoder::ReadDelimited(span<const std::byte>* out) {
+Status Decoder::ReadDelimited(std::span<const std::byte>* out) {
Status status = ConsumeKey(WireType::kDelimited);
if (!status.ok()) {
return status;
@@ -231,7 +231,7 @@ Status Decoder::ReadDelimited(span<const std::byte>* out) {
return Status::OK;
}
-Status CallbackDecoder::Decode(span<const std::byte> proto) {
+Status CallbackDecoder::Decode(std::span<const std::byte> proto) {
if (handler_ == nullptr || state_ != kReady) {
return Status::FAILED_PRECONDITION;
}
diff --git a/pw_protobuf/decoder_test.cc b/pw_protobuf/decoder_test.cc
index abc9d540e..7dad4b2d0 100644
--- a/pw_protobuf/decoder_test.cc
+++ b/pw_protobuf/decoder_test.cc
@@ -80,7 +80,7 @@ TEST(Decoder, Decode) {
};
// clang-format on
- Decoder decoder(as_bytes(span(encoded_proto)));
+ Decoder decoder(std::as_bytes(std::span(encoded_proto)));
int32_t v1 = 0;
EXPECT_EQ(decoder.Next(), Status::OK);
@@ -142,7 +142,7 @@ TEST(Decoder, Decode_SkipsUnusedFields) {
};
// clang-format on
- Decoder decoder(as_bytes(span(encoded_proto)));
+ Decoder decoder(std::as_bytes(std::span(encoded_proto)));
// Don't process any fields except for the fourth. Next should still iterate
// correctly despite field values not being consumed.
@@ -178,7 +178,8 @@ TEST(CallbackDecoder, Decode) {
// clang-format on
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(as_bytes(span(encoded_proto))), Status::OK);
+ EXPECT_EQ(decoder.Decode(std::as_bytes(std::span(encoded_proto))),
+ Status::OK);
EXPECT_TRUE(handler.called);
EXPECT_EQ(handler.test_int32, 42);
EXPECT_EQ(handler.test_sint32, -13);
@@ -204,7 +205,8 @@ TEST(CallbackDecoder, Decode_OverridesDuplicateFields) {
// clang-format on
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(as_bytes(span(encoded_proto))), Status::OK);
+ EXPECT_EQ(decoder.Decode(std::as_bytes(std::span(encoded_proto))),
+ Status::OK);
EXPECT_TRUE(handler.called);
EXPECT_EQ(handler.test_int32, 44);
}
@@ -214,7 +216,7 @@ TEST(CallbackDecoder, Decode_Empty) {
TestDecodeHandler handler;
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(span<std::byte>()), Status::OK);
+ EXPECT_EQ(decoder.Decode(std::span<std::byte>()), Status::OK);
EXPECT_FALSE(handler.called);
EXPECT_EQ(handler.test_int32, 0);
EXPECT_EQ(handler.test_sint32, 0);
@@ -228,7 +230,8 @@ TEST(CallbackDecoder, Decode_BadData) {
uint8_t encoded_proto[] = {0x08};
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(as_bytes(span(encoded_proto))), Status::DATA_LOSS);
+ EXPECT_EQ(decoder.Decode(std::as_bytes(std::span(encoded_proto))),
+ Status::DATA_LOSS);
}
// Only processes fields numbered 1 or 3.
@@ -282,7 +285,8 @@ TEST(CallbackDecoder, Decode_SkipsUnprocessedFields) {
// clang-format on
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(as_bytes(span(encoded_proto))), Status::OK);
+ EXPECT_EQ(decoder.Decode(std::as_bytes(std::span(encoded_proto))),
+ Status::OK);
EXPECT_TRUE(handler.called);
EXPECT_EQ(handler.field_one, 42);
EXPECT_EQ(handler.field_three, 99);
@@ -331,7 +335,8 @@ TEST(CallbackDecoder, Decode_StopsOnNonOkStatus) {
// clang-format on
decoder.set_handler(&handler);
- EXPECT_EQ(decoder.Decode(as_bytes(span(encoded_proto))), Status::CANCELLED);
+ EXPECT_EQ(decoder.Decode(std::as_bytes(std::span(encoded_proto))),
+ Status::CANCELLED);
EXPECT_EQ(handler.field_one, 42);
EXPECT_EQ(handler.field_three, 1111);
}
diff --git a/pw_protobuf/encoder.cc b/pw_protobuf/encoder.cc
index c20b093eb..96b9b7ddc 100644
--- a/pw_protobuf/encoder.cc
+++ b/pw_protobuf/encoder.cc
@@ -30,7 +30,7 @@ Status Encoder::WriteVarint(uint64_t value) {
return encode_status_;
}
- span varint_buf = buffer_.last(RemainingSize());
+ std::span varint_buf = buffer_.last(RemainingSize());
if (varint_buf.empty()) {
encode_status_ = Status::RESOURCE_EXHAUSTED;
return encode_status_;
@@ -126,9 +126,9 @@ Status Encoder::Pop() {
return Status::OK;
}
-Status Encoder::Encode(span<const std::byte>* out) {
+Status Encoder::Encode(std::span<const std::byte>* out) {
if (!encode_status_.ok()) {
- *out = span<const std::byte>();
+ *out = std::span<const std::byte>();
return encode_status_;
}
@@ -152,7 +152,7 @@ Status Encoder::Encode(span<const std::byte>* out) {
while (read_cursor < cursor_) {
SizeType nested_size = *size_cursor;
- span<std::byte> varint_buf(write_cursor, sizeof(*size_cursor));
+ std::span<std::byte> varint_buf(write_cursor, sizeof(*size_cursor));
size_t varint_size =
pw::varint::EncodeLittleEndianBase128(nested_size, varint_buf);
diff --git a/pw_protobuf/encoder_fuzzer.cc b/pw_protobuf/encoder_fuzzer.cc
index a59e3b3a5..e0991d00b 100644
--- a/pw_protobuf/encoder_fuzzer.cc
+++ b/pw_protobuf/encoder_fuzzer.cc
@@ -18,10 +18,10 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
+#include <span>
#include <vector>
#include "pw_protobuf/encoder.h"
-#include "pw_span/span.h"
namespace {
@@ -72,11 +72,11 @@ size_t ConsumeSize(FuzzedDataProvider* provider) {
}
// Uses the given |provider| to generate several instances of T, store them in
-// |data|, and then return a span to them. It is the caller's responsbility to
-// ensure |data| remains in scope as long as the returned span.
+// |data|, and then return a std::span to them. It is the caller's responsbility
+// to ensure |data| remains in scope as long as the returned std::span.
template <typename T>
-pw::span<const T> ConsumeSpan(FuzzedDataProvider* provider,
- std::vector<T>* data) {
+std::span<const T> ConsumeSpan(FuzzedDataProvider* provider,
+ std::vector<T>* data) {
size_t num = ConsumeSize<T>(provider);
size_t off = data->size();
data->reserve(off + num);
@@ -87,7 +87,7 @@ pw::span<const T> ConsumeSpan(FuzzedDataProvider* provider,
data->push_back(provider->ConsumeIntegral<T>());
}
}
- return pw::span(&((*data)[off]), num);
+ return std::span(&((*data)[off]), num);
}
// Uses the given |provider| to generate a string, store it in |data|, and
@@ -104,16 +104,16 @@ const char* ConsumeString(FuzzedDataProvider* provider,
}
// Uses the given |provider| to generate non-arithmetic bytes, store them in
-// |data|, and return a span to them. It is the caller's responsbility to
-// ensure |data| remains in scope as long as the returned span.
-pw::span<const std::byte> ConsumeBytes(FuzzedDataProvider* provider,
- std::vector<std::byte>* data) {
+// |data|, and return a std::span to them. It is the caller's responsbility to
+// ensure |data| remains in scope as long as the returned std::span.
+std::span<const std::byte> ConsumeBytes(FuzzedDataProvider* provider,
+ std::vector<std::byte>* data) {
size_t num = ConsumeSize<std::byte>(provider);
auto added = provider->ConsumeBytes<std::byte>(num);
size_t off = data->size();
num = added.size();
data->insert(data->end(), added.begin(), added.end());
- return pw::span(&((*data)[off]), num);
+ return std::span(&((*data)[off]), num);
}
} // namespace
@@ -127,13 +127,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// the rest.
size_t unpoisoned_length =
provider.ConsumeIntegralInRange<size_t>(0, sizeof(buffer));
- pw::span<std::byte> unpoisoned(buffer, unpoisoned_length);
+ std::span<std::byte> unpoisoned(buffer, unpoisoned_length);
void* poisoned = &buffer[unpoisoned_length];
size_t poisoned_length = sizeof(buffer) - unpoisoned_length;
ASAN_POISON_MEMORY_REGION(poisoned, poisoned_length);
pw::protobuf::NestedEncoder encoder(unpoisoned);
- pw::span<const std::byte> out;
+ std::span<const std::byte> out;
// Storage for generated spans
std::vector<uint32_t> u32s;
diff --git a/pw_protobuf/encoder_test.cc b/pw_protobuf/encoder_test.cc
index e812dca34..8a86057ae 100644
--- a/pw_protobuf/encoder_test.cc
+++ b/pw_protobuf/encoder_test.cc
@@ -93,7 +93,7 @@ TEST(Encoder, EncodePrimitives) {
EXPECT_EQ(encoder.WriteString(kTestProtoErrorMessageField, "broken 💩"),
Status::OK);
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
@@ -115,7 +115,7 @@ TEST(Encoder, EncodeInsufficientSpace) {
EXPECT_EQ(encoder.WriteFloat(kTestProtoRatioField, 1.618034),
Status::RESOURCE_EXHAUSTED);
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::RESOURCE_EXHAUSTED);
EXPECT_EQ(encoded.size(), 0u);
}
@@ -133,7 +133,7 @@ TEST(Encoder, EncodeInvalidArguments) {
encoder.Clear();
EXPECT_EQ(encoder.WriteBool(19091, false), Status::INVALID_ARGUMENT);
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::INVALID_ARGUMENT);
EXPECT_EQ(encoded.size(), 0u);
}
@@ -213,7 +213,7 @@ TEST(Encoder, Nested) {
};
// clang-format on
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
@@ -273,7 +273,7 @@ TEST(Encoder, RepeatedField) {
constexpr uint8_t encoded_proto[] = {
0x08, 0x00, 0x08, 0x32, 0x08, 0x64, 0x08, 0x96, 0x01, 0x08, 0xc8, 0x01};
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
@@ -291,7 +291,7 @@ TEST(Encoder, PackedVarint) {
0x0a, 0x07, 0x00, 0x32, 0x64, 0x96, 0x01, 0xc8, 0x01};
// key size v[0] v[1] v[2] v[3] v[4]
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
@@ -304,7 +304,7 @@ TEST(Encoder, PackedVarintInsufficientSpace) {
constexpr uint32_t values[] = {0, 50, 100, 150, 200};
encoder.WritePackedUint32(1, values);
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::RESOURCE_EXHAUSTED);
EXPECT_EQ(encoded.size(), 0u);
}
@@ -326,7 +326,7 @@ TEST(Encoder, PackedFixed) {
0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00,
0x12, 0x08, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
@@ -343,7 +343,7 @@ TEST(Encoder, PackedZigzag) {
constexpr uint8_t encoded_proto[] = {
0x0a, 0x09, 0xc7, 0x01, 0x31, 0x01, 0x00, 0x02, 0x32, 0xc8, 0x01};
- span<const std::byte> encoded;
+ std::span<const std::byte> encoded;
EXPECT_EQ(encoder.Encode(&encoded), Status::OK);
EXPECT_EQ(encoded.size(), sizeof(encoded_proto));
EXPECT_EQ(std::memcmp(encoded.data(), encoded_proto, encoded.size()), 0);
diff --git a/pw_protobuf/find.cc b/pw_protobuf/find.cc
index 70daabbbd..923097a82 100644
--- a/pw_protobuf/find.cc
+++ b/pw_protobuf/find.cc
@@ -28,7 +28,7 @@ Status FindDecodeHandler::ProcessField(CallbackDecoder& decoder,
return Status::CANCELLED;
}
- span<const std::byte> submessage;
+ std::span<const std::byte> submessage;
if (Status status = decoder.ReadBytes(&submessage); !status.ok()) {
return status;
}
diff --git a/pw_protobuf/find_test.cc b/pw_protobuf/find_test.cc
index 2a7edd6d9..1dd478973 100644
--- a/pw_protobuf/find_test.cc
+++ b/pw_protobuf/find_test.cc
@@ -45,7 +45,7 @@ TEST(FindDecodeHandler, SingleLevel_FindsExistingField) {
FindDecodeHandler finder(3);
decoder.set_handler(&finder);
- decoder.Decode(as_bytes(span(encoded_proto)));
+ decoder.Decode(std::as_bytes(std::span(encoded_proto)));
EXPECT_TRUE(finder.found());
EXPECT_TRUE(decoder.cancelled());
@@ -56,7 +56,7 @@ TEST(FindDecodeHandler, SingleLevel_DoesntFindNonExistingField) {
FindDecodeHandler finder(8);
decoder.set_handler(&finder);
- decoder.Decode(as_bytes(span(encoded_proto)));
+ decoder.Decode(std::as_bytes(std::span(encoded_proto)));
EXPECT_FALSE(finder.found());
EXPECT_FALSE(decoder.cancelled());
@@ -68,7 +68,7 @@ TEST(FindDecodeHandler, MultiLevel_FindsExistingNestedField) {
FindDecodeHandler finder(7, &nested_finder);
decoder.set_handler(&finder);
- decoder.Decode(as_bytes(span(encoded_proto)));
+ decoder.Decode(std::as_bytes(std::span(encoded_proto)));
EXPECT_TRUE(finder.found());
EXPECT_TRUE(nested_finder.found());
@@ -81,7 +81,7 @@ TEST(FindDecodeHandler, MultiLevel_DoesntFindNonExistingNestedField) {
FindDecodeHandler finder(7, &nested_finder);
decoder.set_handler(&finder);
- decoder.Decode(as_bytes(span(encoded_proto)));
+ decoder.Decode(std::as_bytes(std::span(encoded_proto)));
EXPECT_TRUE(finder.found());
EXPECT_FALSE(nested_finder.found());
diff --git a/pw_protobuf/public/pw_protobuf/decoder.h b/pw_protobuf/public/pw_protobuf/decoder.h
index 184c38f35..595bc9aec 100644
--- a/pw_protobuf/public/pw_protobuf/decoder.h
+++ b/pw_protobuf/public/pw_protobuf/decoder.h
@@ -13,10 +13,10 @@
// the License.
#pragma once
+#include <span>
#include <string_view>
#include "pw_protobuf/wire_format.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_varint/varint.h"
@@ -44,7 +44,7 @@ namespace pw::protobuf {
class Decoder {
public:
- constexpr Decoder(span<const std::byte> proto)
+ constexpr Decoder(std::span<const std::byte> proto)
: proto_(proto), previous_field_consumed_(true) {}
Decoder(const Decoder& other) = delete;
@@ -127,12 +127,14 @@ class Decoder {
Status ReadString(std::string_view* out);
// Reads a proto bytes value from the current cursor and returns a view of it
- // in `out`. The raw protobuf data must outlive the `out` span. If the bytes
- // field is invalid, `out` is not modified.
- Status ReadBytes(span<const std::byte>* out) { return ReadDelimited(out); }
+ // in `out`. The raw protobuf data must outlive the `out` std::span. If the
+ // bytes field is invalid, `out` is not modified.
+ Status ReadBytes(std::span<const std::byte>* out) {
+ return ReadDelimited(out);
+ }
// Resets the decoder to start reading a new proto message.
- void Reset(span<const std::byte> proto) {
+ void Reset(std::span<const std::byte> proto) {
proto_ = proto;
previous_field_consumed_ = true;
}
@@ -160,9 +162,9 @@ class Decoder {
return ReadFixed(reinterpret_cast<std::byte*>(out), sizeof(T));
}
- Status ReadDelimited(span<const std::byte>* out);
+ Status ReadDelimited(std::span<const std::byte>* out);
- span<const std::byte> proto_;
+ std::span<const std::byte> proto_;
bool previous_field_consumed_;
};
@@ -197,7 +199,7 @@ class DecodeHandler;
// unsigned int baz;
// };
//
-// void DecodeFooProto(span<std::byte> raw_proto) {
+// void DecodeFooProto(std::span<std::byte> raw_proto) {
// Decoder decoder;
// FooProtoHandler handler;
//
@@ -222,7 +224,7 @@ class CallbackDecoder {
// Decodes the specified protobuf data. The registered handler's ProcessField
// function is called on each field found in the data.
- Status Decode(span<const std::byte> proto);
+ Status Decode(std::span<const std::byte> proto);
// Reads a proto int32 value from the current cursor.
Status ReadInt32(int32_t* out) { return decoder_.ReadInt32(out); }
@@ -269,9 +271,9 @@ class CallbackDecoder {
Status ReadString(std::string_view* out) { return decoder_.ReadString(out); }
// Reads a proto bytes value from the current cursor and returns a view of it
- // in `out`. The raw protobuf data must outlive the `out` span. If the bytes
- // field is invalid, `out` is not modified.
- Status ReadBytes(span<const std::byte>* out) {
+ // in `out`. The raw protobuf data must outlive the `out` std::span. If the
+ // bytes field is invalid, `out` is not modified.
+ Status ReadBytes(std::span<const std::byte>* out) {
return decoder_.ReadBytes(out);
}
diff --git a/pw_protobuf/public/pw_protobuf/encoder.h b/pw_protobuf/public/pw_protobuf/encoder.h
index 84e8ee18b..3e86368c6 100644
--- a/pw_protobuf/public/pw_protobuf/encoder.h
+++ b/pw_protobuf/public/pw_protobuf/encoder.h
@@ -15,9 +15,9 @@
#include <cstddef>
#include <cstring>
+#include <span>
#include "pw_protobuf/wire_format.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_varint/varint.h"
@@ -31,9 +31,9 @@ class Encoder {
// message. This can be templated to minimize the overhead.
using SizeType = size_t;
- constexpr Encoder(span<std::byte> buffer,
- span<SizeType*> locations,
- span<SizeType*> stack)
+ constexpr Encoder(std::span<std::byte> buffer,
+ std::span<SizeType*> locations,
+ std::span<SizeType*> stack)
: buffer_(buffer),
cursor_(buffer.data()),
blob_locations_(locations),
@@ -59,7 +59,8 @@ class Encoder {
}
// Writes a repeated uint32 using packed encoding.
- Status WritePackedUint32(uint32_t field_number, span<const uint32_t> values) {
+ Status WritePackedUint32(uint32_t field_number,
+ std::span<const uint32_t> values) {
return WritePackedVarints(field_number, values, /*zigzag=*/false);
}
@@ -67,7 +68,8 @@ class Encoder {
Status WriteUint64(uint32_t field_number, uint64_t value);
// Writes a repeated uint64 using packed encoding.
- Status WritePackedUint64(uint64_t field_number, span<const uint64_t> values) {
+ Status WritePackedUint64(uint64_t field_number,
+ std::span<const uint64_t> values) {
return WritePackedVarints(field_number, values, /*zigzag=*/false);
}
@@ -77,10 +79,12 @@ class Encoder {
}
// Writes a repeated int32 using packed encoding.
- Status WritePackedInt32(uint32_t field_number, span<const int32_t> values) {
+ Status WritePackedInt32(uint32_t field_number,
+ std::span<const int32_t> values) {
return WritePackedVarints(
field_number,
- span(reinterpret_cast<const uint32_t*>(values.data()), values.size()),
+ std::span(reinterpret_cast<const uint32_t*>(values.data()),
+ values.size()),
/*zigzag=*/false);
}
@@ -90,10 +94,12 @@ class Encoder {
}
// Writes a repeated int64 using packed encoding.
- Status WritePackedInt64(uint32_t field_number, span<const int64_t> values) {
+ Status WritePackedInt64(uint32_t field_number,
+ std::span<const int64_t> values) {
return WritePackedVarints(
field_number,
- span(reinterpret_cast<const uint64_t*>(values.data()), values.size()),
+ std::span(reinterpret_cast<const uint64_t*>(values.data()),
+ values.size()),
/*zigzag=*/false);
}
@@ -103,10 +109,12 @@ class Encoder {
}
// Writes a repeated sint32 using packed encoding.
- Status WritePackedSint32(uint32_t field_number, span<const int32_t> values) {
+ Status WritePackedSint32(uint32_t field_number,
+ std::span<const int32_t> values) {
return WritePackedVarints(
field_number,
- span(reinterpret_cast<const uint32_t*>(values.data()), values.size()),
+ std::span(reinterpret_cast<const uint32_t*>(values.data()),
+ values.size()),
/*zigzag=*/true);
}
@@ -116,10 +124,12 @@ class Encoder {
}
// Writes a repeated sint64 using packed encoding.
- Status WritePackedSint64(uint32_t field_number, span<const int64_t> values) {
+ Status WritePackedSint64(uint32_t field_number,
+ std::span<const int64_t> values) {
return WritePackedVarints(
field_number,
- span(reinterpret_cast<const uint64_t*>(values.data()), values.size()),
+ std::span(reinterpret_cast<const uint64_t*>(values.data()),
+ values.size()),
/*zigzag=*/true);
}
@@ -139,8 +149,8 @@ class Encoder {
// Writes a repeated fixed32 field using packed encoding.
Status WritePackedFixed32(uint32_t field_number,
- span<const uint32_t> values) {
- return WriteBytes(field_number, as_bytes(values));
+ std::span<const uint32_t> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto fixed64 key-value pair.
@@ -154,8 +164,8 @@ class Encoder {
// Writes a repeated fixed64 field using packed encoding.
Status WritePackedFixed64(uint32_t field_number,
- span<const uint64_t> values) {
- return WriteBytes(field_number, as_bytes(values));
+ std::span<const uint64_t> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto sfixed32 key-value pair.
@@ -165,8 +175,8 @@ class Encoder {
// Writes a repeated sfixed32 field using packed encoding.
Status WritePackedSfixed32(uint32_t field_number,
- span<const int32_t> values) {
- return WriteBytes(field_number, as_bytes(values));
+ std::span<const int32_t> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto sfixed64 key-value pair.
@@ -176,8 +186,8 @@ class Encoder {
// Writes a repeated sfixed64 field using packed encoding.
Status WritePackedSfixed64(uint32_t field_number,
- span<const int64_t> values) {
- return WriteBytes(field_number, as_bytes(values));
+ std::span<const int64_t> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto float key-value pair.
@@ -192,8 +202,9 @@ class Encoder {
}
// Writes a repeated float field using packed encoding.
- Status WritePackedFloat(uint32_t field_number, span<const float> values) {
- return WriteBytes(field_number, as_bytes(values));
+ Status WritePackedFloat(uint32_t field_number,
+ std::span<const float> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto double key-value pair.
@@ -208,12 +219,13 @@ class Encoder {
}
// Writes a repeated double field using packed encoding.
- Status WritePackedDouble(uint32_t field_number, span<const double> values) {
- return WriteBytes(field_number, as_bytes(values));
+ Status WritePackedDouble(uint32_t field_number,
+ std::span<const double> values) {
+ return WriteBytes(field_number, std::as_bytes(values));
}
// Writes a proto bytes key-value pair.
- Status WriteBytes(uint32_t field_number, span<const std::byte> value) {
+ Status WriteBytes(uint32_t field_number, std::span<const std::byte> value) {
std::byte* original_cursor = cursor_;
WriteFieldKey(field_number, WireType::kDelimited);
WriteVarint(value.size_bytes());
@@ -224,7 +236,7 @@ class Encoder {
// Writes a proto string key-value pair.
Status WriteString(uint32_t field_number, const char* value, size_t size) {
- return WriteBytes(field_number, as_bytes(span(value, size)));
+ return WriteBytes(field_number, std::as_bytes(std::span(value, size)));
}
Status WriteString(uint32_t field_number, const char* value) {
@@ -254,7 +266,7 @@ class Encoder {
// Runs a final encoding pass over the intermediary data and returns the
// encoded protobuf message.
- Status Encode(span<const std::byte>* out);
+ Status Encode(std::span<const std::byte>* out);
private:
constexpr bool ValidFieldNumber(uint32_t field_number) const {
@@ -291,7 +303,7 @@ class Encoder {
// If zigzag is true, zig-zag encodes each of the varints.
template <typename T>
Status WritePackedVarints(uint32_t field_number,
- span<T> values,
+ std::span<T> values,
bool zigzag) {
if (Status status = Push(field_number); !status.ok()) {
return status;
@@ -328,16 +340,16 @@ class Encoder {
}
// The buffer into which the proto is encoded.
- span<std::byte> buffer_;
+ std::span<std::byte> buffer_;
std::byte* cursor_;
// List of pointers to sub-messages' delimiting size fields.
- span<SizeType*> blob_locations_;
+ std::span<SizeType*> blob_locations_;
size_t blob_count_;
// Stack of current nested message size locations. Push() operations add a new
// entry to this stack and Pop() operations remove one.
- span<SizeType*> blob_stack_;
+ std::span<SizeType*> blob_stack_;
size_t depth_;
Status encode_status_;
@@ -347,7 +359,8 @@ class Encoder {
template <size_t kMaxNestedDepth = 1, size_t kMaxBlobs = 1>
class NestedEncoder : public Encoder {
public:
- NestedEncoder(span<std::byte> buffer) : Encoder(buffer, blobs_, stack_) {}
+ NestedEncoder(std::span<std::byte> buffer)
+ : Encoder(buffer, blobs_, stack_) {}
// Disallow copy/assign to avoid confusion about who owns the buffer.
NestedEncoder(const NestedEncoder& other) = delete;
diff --git a/pw_protobuf/size_report/decoder_full.cc b/pw_protobuf/size_report/decoder_full.cc
index 561335e26..075981e81 100644
--- a/pw_protobuf/size_report/decoder_full.cc
+++ b/pw_protobuf/size_report/decoder_full.cc
@@ -38,7 +38,7 @@ int main() {
float f;
double d;
- pw::protobuf::Decoder decoder(pw::as_bytes(pw::span(encoded_proto)));
+ pw::protobuf::Decoder decoder(std::as_bytes(std::span(encoded_proto)));
while (decoder.Next().ok()) {
switch (decoder.FieldNumber()) {
case 1:
diff --git a/pw_protobuf/size_report/decoder_incremental.cc b/pw_protobuf/size_report/decoder_incremental.cc
index 064f57931..9f4029ffd 100644
--- a/pw_protobuf/size_report/decoder_incremental.cc
+++ b/pw_protobuf/size_report/decoder_incremental.cc
@@ -39,7 +39,7 @@ int main() {
double d;
uint32_t uint;
- pw::protobuf::Decoder decoder(pw::as_bytes(pw::span(encoded_proto)));
+ pw::protobuf::Decoder decoder(std::as_bytes(std::span(encoded_proto)));
while (decoder.Next().ok()) {
switch (decoder.FieldNumber()) {
case 1:
diff --git a/pw_ring_buffer/prefixed_entry_ring_buffer.cc b/pw_ring_buffer/prefixed_entry_ring_buffer.cc
index fac8e6edf..31eb222bc 100644
--- a/pw_ring_buffer/prefixed_entry_ring_buffer.cc
+++ b/pw_ring_buffer/prefixed_entry_ring_buffer.cc
@@ -29,7 +29,7 @@ void PrefixedEntryRingBuffer::Clear() {
entry_count_ = 0;
}
-Status PrefixedEntryRingBuffer::SetBuffer(span<byte> buffer) {
+Status PrefixedEntryRingBuffer::SetBuffer(std::span<byte> buffer) {
if ((buffer.data() == nullptr) || //
(buffer.size_bytes() == 0) || //
(buffer.size_bytes() > kMaxBufferBytes)) {
@@ -43,7 +43,7 @@ Status PrefixedEntryRingBuffer::SetBuffer(span<byte> buffer) {
return Status::OK;
}
-Status PrefixedEntryRingBuffer::InternalPushBack(span<const byte> data,
+Status PrefixedEntryRingBuffer::InternalPushBack(std::span<const byte> data,
byte user_preamble_data,
bool drop_elements_if_needed) {
if (buffer_ == nullptr) {
@@ -75,16 +75,16 @@ Status PrefixedEntryRingBuffer::InternalPushBack(span<const byte> data,
// Write the new entry into the ring buffer.
if (user_preamble_) {
- RawWrite(span(&user_preamble_data, sizeof(user_preamble_data)));
+ RawWrite(std::span(&user_preamble_data, sizeof(user_preamble_data)));
}
- RawWrite(span(varint_buf, varint_bytes));
+ RawWrite(std::span(varint_buf, varint_bytes));
RawWrite(data);
entry_count_++;
return Status::OK;
}
-auto GetOutput(span<byte> data_out, size_t* write_index) {
- return [data_out, write_index](span<const byte> src) -> Status {
+auto GetOutput(std::span<byte> data_out, size_t* write_index) {
+ return [data_out, write_index](std::span<const byte> src) -> Status {
size_t copy_size = std::min(data_out.size_bytes(), src.size_bytes());
memcpy(data_out.data() + *write_index, src.data(), copy_size);
@@ -95,7 +95,8 @@ auto GetOutput(span<byte> data_out, size_t* write_index) {
};
}
-Status PrefixedEntryRingBuffer::PeekFront(span<byte> data, size_t* bytes_read) {
+Status PrefixedEntryRingBuffer::PeekFront(std::span<byte> data,
+ size_t* bytes_read) {
*bytes_read = 0;
return InternalRead(GetOutput(data, bytes_read), false);
}
@@ -104,7 +105,7 @@ Status PrefixedEntryRingBuffer::PeekFront(ReadOutput output) {
return InternalRead(output, false);
}
-Status PrefixedEntryRingBuffer::PeekFrontWithPreamble(span<byte> data,
+Status PrefixedEntryRingBuffer::PeekFrontWithPreamble(std::span<byte> data,
size_t* bytes_read) {
*bytes_read = 0;
return InternalRead(GetOutput(data, bytes_read), true);
@@ -114,7 +115,7 @@ Status PrefixedEntryRingBuffer::PeekFrontWithPreamble(ReadOutput output) {
return InternalRead(output, true);
}
-// T should be similar to Status (*read_output)(span<const byte>)
+// T should be similar to Status (*read_output)(std::span<const byte>)
template <typename T>
Status PrefixedEntryRingBuffer::InternalRead(T read_output, bool get_preamble) {
if (buffer_ == nullptr) {
@@ -137,11 +138,12 @@ Status PrefixedEntryRingBuffer::InternalRead(T read_output, bool get_preamble) {
// Read bytes, stopping at the end of the buffer if this entry wraps.
size_t bytes_until_wrap = buffer_bytes_ - data_read_idx;
size_t bytes_to_copy = std::min(read_bytes, bytes_until_wrap);
- Status status = read_output(span(buffer_ + data_read_idx, bytes_to_copy));
+ Status status =
+ read_output(std::span(buffer_ + data_read_idx, bytes_to_copy));
// If the entry wrapped, read the remaining bytes.
if (status.ok() && (bytes_to_copy < read_bytes)) {
- status = read_output(span(buffer_, read_bytes - bytes_to_copy));
+ status = read_output(std::span(buffer_, read_bytes - bytes_to_copy));
}
return status;
}
@@ -171,7 +173,7 @@ Status PrefixedEntryRingBuffer::Dering() {
return Status::OK;
}
- auto buffer_span = span(buffer_, buffer_bytes_);
+ auto buffer_span = std::span(buffer_, buffer_bytes_);
std::rotate(
buffer_span.begin(), buffer_span.begin() + read_idx_, buffer_span.end());
@@ -232,7 +234,7 @@ size_t PrefixedEntryRingBuffer::RawAvailableBytes() {
return entry_count_ ? 0 : buffer_bytes_;
}
-void PrefixedEntryRingBuffer::RawWrite(span<const std::byte> source) {
+void PrefixedEntryRingBuffer::RawWrite(std::span<const std::byte> source) {
// Write until the end of the source or the backing buffer.
size_t bytes_until_wrap = buffer_bytes_ - write_idx_;
size_t bytes_to_copy = std::min(source.size(), bytes_until_wrap);
diff --git a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
index 225eb136b..271ce74ed 100644
--- a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
+++ b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
@@ -34,8 +34,9 @@ TEST(PrefixedEntryRingBuffer, NoBuffer) {
size_t count;
EXPECT_EQ(ring.EntryCount(), 0u);
- EXPECT_EQ(ring.SetBuffer(span<byte>(nullptr, 10u)), Status::INVALID_ARGUMENT);
- EXPECT_EQ(ring.SetBuffer(span(buf, 0u)), Status::INVALID_ARGUMENT);
+ EXPECT_EQ(ring.SetBuffer(std::span<byte>(nullptr, 10u)),
+ Status::INVALID_ARGUMENT);
+ EXPECT_EQ(ring.SetBuffer(std::span(buf, 0u)), Status::INVALID_ARGUMENT);
EXPECT_EQ(ring.FrontEntryDataSizeBytes(), 0u);
EXPECT_EQ(ring.PushBack(buf), Status::FAILED_PRECONDITION);
@@ -87,11 +88,12 @@ void SingleEntryWriteReadTest(bool user_data) {
EXPECT_EQ(ring.EntryCount(), 0u);
EXPECT_EQ(ring.PopFront(), Status::OUT_OF_RANGE);
EXPECT_EQ(ring.EntryCount(), 0u);
- EXPECT_EQ(ring.PushBack(span(single_entry_data, 0u)),
+ EXPECT_EQ(ring.PushBack(std::span(single_entry_data, 0u)),
Status::INVALID_ARGUMENT);
EXPECT_EQ(ring.EntryCount(), 0u);
- EXPECT_EQ(ring.PushBack(span(single_entry_data, sizeof(test_buffer) + 5)),
- Status::OUT_OF_RANGE);
+ EXPECT_EQ(
+ ring.PushBack(std::span(single_entry_data, sizeof(test_buffer) + 5)),
+ Status::OUT_OF_RANGE);
EXPECT_EQ(ring.EntryCount(), 0u);
EXPECT_EQ(ring.PeekFront(read_buffer, &read_size), Status::OUT_OF_RANGE);
EXPECT_EQ(read_size, 0u);
@@ -112,7 +114,7 @@ void SingleEntryWriteReadTest(bool user_data) {
ASSERT_EQ(ring.FrontEntryDataSizeBytes(), 0u);
ASSERT_EQ(ring.FrontEntryTotalSizeBytes(), 0u);
- ASSERT_EQ(ring.PushBack(span(single_entry_data, data_size), byte(i)),
+ ASSERT_EQ(ring.PushBack(std::span(single_entry_data, data_size), byte(i)),
Status::OK);
ASSERT_EQ(ring.FrontEntryDataSizeBytes(), data_size);
ASSERT_EQ(ring.FrontEntryTotalSizeBytes(), single_entry_total_size);
@@ -121,12 +123,12 @@ void SingleEntryWriteReadTest(bool user_data) {
ASSERT_EQ(ring.PeekFront(read_buffer, &read_size), Status::OK);
ASSERT_EQ(read_size, data_size);
- // ASSERT_THAT(span(expect_buffer).last(data_size),
- // testing::ElementsAreArray(span(read_buffer, data_size)));
- ASSERT_EQ(
- memcmp(
- span(expect_buffer).last(data_size).data(), read_buffer, data_size),
- 0);
+ // ASSERT_THAT(std::span(expect_buffer).last(data_size),
+ // testing::ElementsAreArray(std::span(read_buffer, data_size)));
+ ASSERT_EQ(memcmp(std::span(expect_buffer).last(data_size).data(),
+ read_buffer,
+ data_size),
+ 0);
read_size = 500U;
ASSERT_EQ(ring.PeekFrontWithPreamble(read_buffer, &read_size), Status::OK);
@@ -137,8 +139,8 @@ void SingleEntryWriteReadTest(bool user_data) {
expect_buffer[0] = byte(i);
}
- // ASSERT_THAT(span(expect_buffer),
- // testing::ElementsAreArray(span(read_buffer)));
+ // ASSERT_THAT(std::span(expect_buffer),
+ // testing::ElementsAreArray(std::span(read_buffer)));
ASSERT_EQ(memcmp(expect_buffer, read_buffer, single_entry_total_size), 0);
}
}
@@ -221,7 +223,7 @@ void SingleEntryWriteReadWithSectionWriterTest(bool user_data) {
EXPECT_EQ(ring.SetBuffer(test_buffer), Status::OK);
- auto output = [](span<const byte> src) -> Status {
+ auto output = [](std::span<const byte> src) -> Status {
for (byte b : src) {
read_buffer.push_back(b);
}
@@ -240,7 +242,7 @@ void SingleEntryWriteReadWithSectionWriterTest(bool user_data) {
ASSERT_EQ(ring.FrontEntryDataSizeBytes(), 0u);
ASSERT_EQ(ring.FrontEntryTotalSizeBytes(), 0u);
- ASSERT_EQ(ring.PushBack(span(single_entry_data, data_size), byte(i)),
+ ASSERT_EQ(ring.PushBack(std::span(single_entry_data, data_size), byte(i)),
Status::OK);
ASSERT_EQ(ring.FrontEntryDataSizeBytes(), data_size);
ASSERT_EQ(ring.FrontEntryTotalSizeBytes(), single_entry_total_size);
@@ -249,7 +251,7 @@ void SingleEntryWriteReadWithSectionWriterTest(bool user_data) {
ASSERT_EQ(ring.PeekFront(output), Status::OK);
ASSERT_EQ(read_buffer.size(), data_size);
- ASSERT_EQ(memcmp(span(expect_buffer).last(data_size).data(),
+ ASSERT_EQ(memcmp(std::span(expect_buffer).last(data_size).data(),
read_buffer.data(),
data_size),
0);
@@ -294,7 +296,7 @@ void DeringTest(bool preload) {
// Entry data is entry size - preamble (single byte in this case).
byte single_entry_buffer[kEntrySizeBytes - 1u];
- auto entry_data = span(single_entry_buffer);
+ auto entry_data = std::span(single_entry_buffer);
size_t i;
// TODO(pwbug/196): Increase this to 500 once we have a way to detect targets
@@ -341,7 +343,7 @@ void DeringTest(bool preload) {
// Read out the entries of the ring buffer.
actual_result.clear();
- auto output = [](span<const byte> src) -> Status {
+ auto output = [](std::span<const byte> src) -> Status {
for (byte b : src) {
actual_result.push_back(b);
}
@@ -374,7 +376,7 @@ Status PushBack(PrefixedEntryRingBuffer& ring, T element) {
T item;
} aliased;
aliased.item = element;
- return ring.PushBack(span(aliased.buffer));
+ return ring.PushBack(aliased.buffer);
}
template <typename T>
@@ -384,7 +386,7 @@ Status TryPushBack(PrefixedEntryRingBuffer& ring, T element) {
T item;
} aliased;
aliased.item = element;
- return ring.TryPushBack(span(aliased.buffer));
+ return ring.TryPushBack(aliased.buffer);
}
template <typename T>
@@ -394,8 +396,7 @@ T PeekFront(PrefixedEntryRingBuffer& ring) {
T item;
} aliased;
size_t bytes_read = 0;
- PW_CHECK_INT_EQ(ring.PeekFront(span(aliased.buffer), &bytes_read),
- Status::OK);
+ PW_CHECK_INT_EQ(ring.PeekFront(aliased.buffer, &bytes_read), Status::OK);
PW_CHECK_INT_EQ(bytes_read, sizeof(T));
return aliased.item;
}
diff --git a/pw_ring_buffer/public/pw_ring_buffer/prefixed_entry_ring_buffer.h b/pw_ring_buffer/public/pw_ring_buffer/prefixed_entry_ring_buffer.h
index f87c44fc2..e164834af 100644
--- a/pw_ring_buffer/public/pw_ring_buffer/prefixed_entry_ring_buffer.h
+++ b/pw_ring_buffer/public/pw_ring_buffer/prefixed_entry_ring_buffer.h
@@ -14,8 +14,8 @@
#pragma once
#include <cstddef>
+#include <span>
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw {
@@ -32,7 +32,7 @@ namespace ring_buffer {
// room. Entries are internally wrapped around as needed.
class PrefixedEntryRingBuffer {
public:
- typedef Status (*ReadOutput)(span<const std::byte>);
+ typedef Status (*ReadOutput)(std::span<const std::byte>);
PrefixedEntryRingBuffer(bool user_preamble = false)
: buffer_(nullptr),
@@ -47,7 +47,7 @@ class PrefixedEntryRingBuffer {
// Return values:
// OK - successfully set the raw buffer.
// INVALID_ARGUMENT - Argument was nullptr, size zero, or too large.
- Status SetBuffer(span<std::byte> buffer);
+ Status SetBuffer(std::span<std::byte> buffer);
// Removes all data from the ring buffer.
void Clear();
@@ -65,7 +65,7 @@ class PrefixedEntryRingBuffer {
// INVALID_ARGUMENT - Size of data to write is zero bytes
// FAILED_PRECONDITION - Buffer not initialized.
// OUT_OF_RANGE - Size of data is greater than buffer size.
- Status PushBack(span<const std::byte> data,
+ Status PushBack(std::span<const std::byte> data,
std::byte user_preamble_data = std::byte(0)) {
return InternalPushBack(data, user_preamble_data, true);
}
@@ -83,29 +83,29 @@ class PrefixedEntryRingBuffer {
// OUT_OF_RANGE - Size of data is greater than buffer size.
// RESOURCE_EXHAUSTED - The ring buffer doesn't have space for the data
// without popping off existing elements.
- Status TryPushBack(span<const std::byte> data,
+ Status TryPushBack(std::span<const std::byte> data,
std::byte user_preamble_data = std::byte(0)) {
return InternalPushBack(data, user_preamble_data, false);
}
// Read the oldest stored data chunk of data from the ring buffer to
- // the provided destination span. The number of bytes read is written to
+ // the provided destination std::span. The number of bytes read is written to
// bytes_read
//
// Return values:
// OK - Data successfully read from the ring buffer.
// FAILED_PRECONDITION - Buffer not initialized.
// OUT_OF_RANGE - No entries in ring buffer to read.
- // RESOURCE_EXHAUSTED - Destination data span was smaller number of bytes than
- // the data size of the data chunk being read. Available destination bytes
- // were filled, remaining bytes of the data chunk were ignored.
- Status PeekFront(span<std::byte> data, size_t* bytes_read);
+ // RESOURCE_EXHAUSTED - Destination data std::span was smaller number of bytes
+ // than the data size of the data chunk being read. Available destination
+ // bytes were filled, remaining bytes of the data chunk were ignored.
+ Status PeekFront(std::span<std::byte> data, size_t* bytes_read);
Status PeekFront(ReadOutput output);
// Same as Read but includes the entry's preamble of optional user value and
// the varint of the data size
- Status PeekFrontWithPreamble(span<std::byte> data, size_t* bytes_read);
+ Status PeekFrontWithPreamble(std::span<std::byte> data, size_t* bytes_read);
Status PeekFrontWithPreamble(ReadOutput output);
@@ -157,7 +157,7 @@ class PrefixedEntryRingBuffer {
// Push back implementation, which optionally discards front elements to fit
// the incoming element.
- Status InternalPushBack(span<const std::byte> data,
+ Status InternalPushBack(std::span<const std::byte> data,
std::byte user_preamble_data,
bool pop_front_if_needed);
@@ -173,7 +173,7 @@ class PrefixedEntryRingBuffer {
// Do the basic write of the specified number of bytes starting at the last
// write index of the ring buffer to the destination, handing any wrap-around
// of the ring buffer. This is basic, raw operation with no safety checks.
- void RawWrite(span<const std::byte> source);
+ void RawWrite(std::span<const std::byte> source);
// Do the basic read of the specified number of bytes starting at the given
// index of the ring buffer to the destination, handing any wrap-around of
diff --git a/pw_rpc/base_server_writer.cc b/pw_rpc/base_server_writer.cc
index 4fa1f1f74..1e23fc846 100644
--- a/pw_rpc/base_server_writer.cc
+++ b/pw_rpc/base_server_writer.cc
@@ -47,7 +47,7 @@ void BaseServerWriter::Finish() {
state_ = kClosed;
}
-span<std::byte> BaseServerWriter::AcquirePayloadBuffer() {
+std::span<std::byte> BaseServerWriter::AcquirePayloadBuffer() {
if (!open()) {
return {};
}
@@ -56,14 +56,15 @@ span<std::byte> BaseServerWriter::AcquirePayloadBuffer() {
return response_.payload(packet());
}
-Status BaseServerWriter::ReleasePayloadBuffer(span<const std::byte> payload) {
+Status BaseServerWriter::ReleasePayloadBuffer(
+ std::span<const std::byte> payload) {
if (!open()) {
return Status::FAILED_PRECONDITION;
}
return call_.channel().Send(response_, packet(payload));
}
-Packet BaseServerWriter::packet(span<const std::byte> payload) const {
+Packet BaseServerWriter::packet(std::span<const std::byte> payload) const {
return Packet(PacketType::RPC,
call_.channel().id(),
call_.service().id(),
diff --git a/pw_rpc/base_server_writer_test.cc b/pw_rpc/base_server_writer_test.cc
index 8c1b9146d..b10620eba 100644
--- a/pw_rpc/base_server_writer_test.cc
+++ b/pw_rpc/base_server_writer_test.cc
@@ -28,7 +28,7 @@ namespace pw::rpc {
class TestService : public internal::Service {
public:
constexpr TestService(uint32_t id)
- : Service(id, span(&method, 1)), method(8) {}
+ : Service(id, std::span(&method, 1)), method(8) {}
internal::Method method;
};
@@ -62,8 +62,8 @@ class FakeServerWriter : public BaseServerWriter {
constexpr FakeServerWriter() = default;
- Status Write(span<const byte> response) {
- span buffer = AcquirePayloadBuffer();
+ Status Write(std::span<const byte> response) {
+ std::span buffer = AcquirePayloadBuffer();
std::memcpy(buffer.data(),
response.data(),
std::min(buffer.size(), response.size()));
diff --git a/pw_rpc/channel.cc b/pw_rpc/channel.cc
index 5747577fc..b34ebf2cc 100644
--- a/pw_rpc/channel.cc
+++ b/pw_rpc/channel.cc
@@ -21,10 +21,10 @@ namespace pw::rpc::internal {
using std::byte;
-span<byte> Channel::OutputBuffer::payload(const Packet& packet) const {
+std::span<byte> Channel::OutputBuffer::payload(const Packet& packet) const {
const size_t reserved_size = packet.MinEncodedSizeBytes();
return reserved_size <= buffer_.size() ? buffer_.subspan(reserved_size)
- : span<byte>();
+ : std::span<byte>();
}
Status Channel::Send(OutputBuffer& buffer, const internal::Packet& packet) {
diff --git a/pw_rpc/channel_test.cc b/pw_rpc/channel_test.cc
index 5f195aff0..b63535b5e 100644
--- a/pw_rpc/channel_test.cc
+++ b/pw_rpc/channel_test.cc
@@ -27,7 +27,7 @@ TEST(ChannelOutput, Name) {
class NameTester : public ChannelOutput {
public:
NameTester(const char* name) : ChannelOutput(name) {}
- span<std::byte> AcquireBuffer() override { return {}; }
+ std::span<std::byte> AcquireBuffer() override { return {}; }
void SendAndReleaseBuffer(size_t) override {}
};
@@ -67,7 +67,7 @@ TEST(Channel, OutputBuffer_ExactFit) {
internal::Channel channel(100, &output);
Channel::OutputBuffer output_buffer(channel.AcquireBuffer());
- const span payload = output_buffer.payload(kTestPacket);
+ const std::span payload = output_buffer.payload(kTestPacket);
EXPECT_EQ(payload.size(), output.buffer().size() - kReservedSize);
EXPECT_EQ(output.buffer().data() + kReservedSize, payload.data());
@@ -93,7 +93,7 @@ TEST(Channel, OutputBuffer_ExtraRoom) {
internal::Channel channel(100, &output);
Channel::OutputBuffer output_buffer = channel.AcquireBuffer();
- const span payload = output_buffer.payload(kTestPacket);
+ const std::span payload = output_buffer.payload(kTestPacket);
EXPECT_EQ(payload.size(), output.buffer().size() - kReservedSize);
EXPECT_EQ(output.buffer().data() + kReservedSize, payload.data());
diff --git a/pw_rpc/nanopb/method.cc b/pw_rpc/nanopb/method.cc
index 7ed052253..3d91070bf 100644
--- a/pw_rpc/nanopb/method.cc
+++ b/pw_rpc/nanopb/method.cc
@@ -37,7 +37,7 @@ using Fields = typename NanopbTraits<decltype(pb_decode)>::Fields;
using std::byte;
-Status Method::DecodeRequest(span<const byte> buffer,
+Status Method::DecodeRequest(std::span<const byte> buffer,
void* proto_struct) const {
auto input = pb_istream_from_buffer(
reinterpret_cast<const pb_byte_t*>(buffer.data()), buffer.size());
@@ -47,7 +47,7 @@ Status Method::DecodeRequest(span<const byte> buffer,
}
StatusWithSize Method::EncodeResponse(const void* proto_struct,
- span<byte> buffer) const {
+ std::span<byte> buffer) const {
auto output = pb_ostream_from_buffer(
reinterpret_cast<pb_byte_t*>(buffer.data()), buffer.size());
if (pb_encode(&output, static_cast<Fields>(response_fields_), proto_struct)) {
@@ -57,8 +57,8 @@ StatusWithSize Method::EncodeResponse(const void* proto_struct,
}
StatusWithSize Method::CallUnary(ServerCall& call,
- span<const byte> request_buffer,
- span<byte> response_buffer,
+ std::span<const byte> request_buffer,
+ std::span<byte> response_buffer,
void* request_struct,
void* response_struct) const {
Status status = DecodeRequest(request_buffer, request_struct);
@@ -76,7 +76,7 @@ StatusWithSize Method::CallUnary(ServerCall& call,
}
StatusWithSize Method::CallServerStreaming(ServerCall& call,
- span<const byte> request_buffer,
+ std::span<const byte> request_buffer,
void* request_struct) const {
Status status = DecodeRequest(request_buffer, request_struct);
if (!status.ok()) {
diff --git a/pw_rpc/nanopb/method_test.cc b/pw_rpc/nanopb/method_test.cc
index 6d82f2af8..80fd216fb 100644
--- a/pw_rpc/nanopb/method_test.cc
+++ b/pw_rpc/nanopb/method_test.cc
@@ -36,14 +36,15 @@ using std::byte;
#define _ENCODE_PB_IMPL(proto, init, result, unique) \
std::array<pb_byte_t, 2 * sizeof(proto)> _pb_buffer_##unique{}; \
- const span result = \
+ const std::span result = \
EncodeProtobuf<proto, proto##_fields>(proto init, _pb_buffer_##unique)
template <typename T, auto fields>
-span<const byte> EncodeProtobuf(const T& protobuf, span<pb_byte_t> buffer) {
+std::span<const byte> EncodeProtobuf(const T& protobuf,
+ std::span<pb_byte_t> buffer) {
auto output = pb_ostream_from_buffer(buffer.data(), buffer.size());
EXPECT_TRUE(pb_encode(&output, fields, &protobuf));
- return as_bytes(buffer.first(output.bytes_written));
+ return std::as_bytes(buffer.first(output.bytes_written));
}
class FakeGeneratedService : public Service {
diff --git a/pw_rpc/nanopb/public_overrides/pw_rpc/internal/method.h b/pw_rpc/nanopb/public_overrides/pw_rpc/internal/method.h
index f50a997db..19f1497c8 100644
--- a/pw_rpc/nanopb/public_overrides/pw_rpc/internal/method.h
+++ b/pw_rpc/nanopb/public_overrides/pw_rpc/internal/method.h
@@ -16,11 +16,11 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
+#include <span>
#include "pw_rpc/internal/base_method.h"
#include "pw_rpc/internal/base_server_writer.h"
#include "pw_rpc/server_context.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
@@ -137,17 +137,18 @@ class Method : public BaseMethod {
// calls the invoker function, which encodes and decodes the request and
// response (if any) and calls the user-defined RPC function.
StatusWithSize Invoke(ServerCall& call,
- span<const std::byte> request,
- span<std::byte> payload_buffer) const {
+ std::span<const std::byte> request,
+ std::span<std::byte> payload_buffer) const {
return invoker_(*this, call, request, payload_buffer);
}
// Decodes a request protobuf with Nanopb to the provided buffer.
- Status DecodeRequest(span<const std::byte> buffer, void* proto_struct) const;
+ Status DecodeRequest(std::span<const std::byte> buffer,
+ void* proto_struct) const;
// Encodes a response protobuf with Nanopb to the provided buffer.
StatusWithSize EncodeResponse(const void* proto_struct,
- span<std::byte> buffer) const;
+ std::span<std::byte> buffer) const;
private:
// Generic version of the unary RPC function signature:
@@ -187,8 +188,8 @@ class Method : public BaseMethod {
// returns the number of bytes written to the response buffer, if any.
using Invoker = StatusWithSize (&)(const Method&,
ServerCall&,
- span<const std::byte>,
- span<std::byte>);
+ std::span<const std::byte>,
+ std::span<std::byte>);
constexpr Method(Function function,
Invoker invoker,
@@ -202,13 +203,13 @@ class Method : public BaseMethod {
response_fields_(response) {}
StatusWithSize CallUnary(ServerCall& call,
- span<const std::byte> request_buffer,
- span<std::byte> response_buffer,
+ std::span<const std::byte> request_buffer,
+ std::span<std::byte> response_buffer,
void* request_struct,
void* response_struct) const;
StatusWithSize CallServerStreaming(ServerCall& call,
- span<const std::byte> request_buffer,
+ std::span<const std::byte> request_buffer,
void* request_struct) const;
// TODO(hepler): Add CallClientStreaming and CallBidiStreaming
@@ -219,8 +220,8 @@ class Method : public BaseMethod {
template <size_t request_size, size_t response_size>
static StatusWithSize UnaryInvoker(const Method& method,
ServerCall& call,
- span<const std::byte> request_buffer,
- span<std::byte> response_buffer) {
+ std::span<const std::byte> request_buffer,
+ std::span<std::byte> response_buffer) {
std::aligned_storage_t<request_size, alignof(std::max_align_t)>
request_struct{};
std::aligned_storage_t<response_size, alignof(std::max_align_t)>
@@ -240,8 +241,8 @@ class Method : public BaseMethod {
static StatusWithSize ServerStreamingInvoker(
const Method& method,
ServerCall& call,
- span<const std::byte> request_buffer,
- span<std::byte> /* payload not used */) {
+ std::span<const std::byte> request_buffer,
+ std::span<std::byte> /* payload not used */) {
std::aligned_storage_t<request_size, alignof(std::max_align_t)>
request_struct{};
@@ -264,7 +265,7 @@ class Method : public BaseMethod {
template <typename T>
Status ServerWriter<T>::Write(const T& response) {
- span<std::byte> buffer = AcquirePayloadBuffer();
+ std::span<std::byte> buffer = AcquirePayloadBuffer();
if (auto result = method().EncodeResponse(&response, buffer); result.ok()) {
return ReleasePayloadBuffer(buffer.first(result.size()));
diff --git a/pw_rpc/packet.cc b/pw_rpc/packet.cc
index b6e670140..9a7e34fd6 100644
--- a/pw_rpc/packet.cc
+++ b/pw_rpc/packet.cc
@@ -20,12 +20,12 @@ namespace pw::rpc::internal {
using std::byte;
-Packet Packet::FromBuffer(span<const byte> data) {
+Packet Packet::FromBuffer(std::span<const byte> data) {
PacketType type = PacketType::RPC;
uint32_t channel_id = 0;
uint32_t service_id = 0;
uint32_t method_id = 0;
- span<const byte> payload;
+ std::span<const byte> payload;
Status status;
uint32_t value;
@@ -68,7 +68,7 @@ Packet Packet::FromBuffer(span<const byte> data) {
return Packet(type, channel_id, service_id, method_id, payload, status);
}
-StatusWithSize Packet::Encode(span<byte> buffer) const {
+StatusWithSize Packet::Encode(std::span<byte> buffer) const {
pw::protobuf::NestedEncoder encoder(buffer);
RpcPacket::Encoder rpc_packet(&encoder);
@@ -81,7 +81,7 @@ StatusWithSize Packet::Encode(span<byte> buffer) const {
rpc_packet.WriteMethodId(method_id_);
rpc_packet.WriteStatus(status_);
- span<const byte> proto;
+ std::span<const byte> proto;
if (Status status = encoder.Encode(&proto); !status.ok()) {
return StatusWithSize(status, 0);
}
diff --git a/pw_rpc/packet_test.cc b/pw_rpc/packet_test.cc
index a8d96a70d..87d5c8369 100644
--- a/pw_rpc/packet_test.cc
+++ b/pw_rpc/packet_test.cc
@@ -91,7 +91,7 @@ TEST(Packet, EncodeDecode) {
StatusWithSize sws = packet.Encode(buffer);
ASSERT_EQ(sws.status(), Status::OK);
- span<byte> packet_data(buffer, sws.size());
+ std::span<byte> packet_data(buffer, sws.size());
Packet decoded = Packet::FromBuffer(packet_data);
EXPECT_EQ(decoded.type(), packet.type());
diff --git a/pw_rpc/public/pw_rpc/channel.h b/pw_rpc/public/pw_rpc/channel.h
index 2602bbe4a..ecae93922 100644
--- a/pw_rpc/public/pw_rpc/channel.h
+++ b/pw_rpc/public/pw_rpc/channel.h
@@ -14,9 +14,9 @@
#pragma once
#include <cstdint>
+#include <span>
#include "pw_assert/assert.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::rpc {
@@ -37,7 +37,7 @@ class ChannelOutput {
constexpr const char* name() const { return name_; }
// Acquire a buffer into which to write an outgoing RPC packet.
- virtual span<std::byte> AcquireBuffer() = 0;
+ virtual std::span<std::byte> AcquireBuffer() = 0;
// Sends the contents of the buffer from AcquireBuffer().
virtual void SendAndReleaseBuffer(size_t size) = 0;
diff --git a/pw_rpc/public/pw_rpc/internal/base_method.h b/pw_rpc/public/pw_rpc/internal/base_method.h
index 07db6161a..4b3fdae5a 100644
--- a/pw_rpc/public/pw_rpc/internal/base_method.h
+++ b/pw_rpc/public/pw_rpc/internal/base_method.h
@@ -27,8 +27,8 @@ class BaseMethod {
// Implementations must provide the Invoke method, which the Server calls:
//
// StatusWithSize Invoke(ServerCall& call,
- // span<const std::byte> request,
- // span<std::byte> payload_buffer) const;
+ // std::span<const std::byte> request,
+ // std::span<std::byte> payload_buffer) const;
protected:
constexpr BaseMethod(uint32_t id) : id_(id) {}
diff --git a/pw_rpc/public/pw_rpc/internal/base_server_writer.h b/pw_rpc/public/pw_rpc/internal/base_server_writer.h
index 413293ce6..47c685855 100644
--- a/pw_rpc/public/pw_rpc/internal/base_server_writer.h
+++ b/pw_rpc/public/pw_rpc/internal/base_server_writer.h
@@ -14,12 +14,12 @@
#pragma once
#include <cstddef>
+#include <span>
#include <utility>
#include "pw_containers/intrusive_list.h"
#include "pw_rpc/internal/call.h"
#include "pw_rpc/internal/channel.h"
-#include "pw_span/span.h"
namespace pw::rpc::internal {
@@ -54,12 +54,12 @@ class BaseServerWriter : public IntrusiveList<BaseServerWriter>::Item {
const Method& method() const { return call_.method(); }
- span<std::byte> AcquirePayloadBuffer();
+ std::span<std::byte> AcquirePayloadBuffer();
- Status ReleasePayloadBuffer(span<const std::byte> payload);
+ Status ReleasePayloadBuffer(std::span<const std::byte> payload);
private:
- Packet packet(span<const std::byte> payload = {}) const;
+ Packet packet(std::span<const std::byte> payload = {}) const;
ServerCall call_;
Channel::OutputBuffer response_;
diff --git a/pw_rpc/public/pw_rpc/internal/channel.h b/pw_rpc/public/pw_rpc/internal/channel.h
index b3f01f723..b42c8a052 100644
--- a/pw_rpc/public/pw_rpc/internal/channel.h
+++ b/pw_rpc/public/pw_rpc/internal/channel.h
@@ -13,8 +13,9 @@
// the License.
#pragma once
+#include <span>
+
#include "pw_rpc/channel.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::rpc::internal {
@@ -48,14 +49,15 @@ class Channel : public rpc::Channel {
}
// Returns a portion of this OutputBuffer to use as the packet payload.
- span<std::byte> payload(const Packet& packet) const;
+ std::span<std::byte> payload(const Packet& packet) const;
private:
friend class Channel;
- explicit constexpr OutputBuffer(span<std::byte> buffer) : buffer_(buffer) {}
+ explicit constexpr OutputBuffer(std::span<std::byte> buffer)
+ : buffer_(buffer) {}
- span<std::byte> buffer_;
+ std::span<std::byte> buffer_;
};
// Acquires a buffer for the packet.
diff --git a/pw_rpc/public/pw_rpc/internal/packet.h b/pw_rpc/public/pw_rpc/internal/packet.h
index 3f5e87d59..79b18f687 100644
--- a/pw_rpc/public/pw_rpc/internal/packet.h
+++ b/pw_rpc/public/pw_rpc/internal/packet.h
@@ -15,9 +15,9 @@
#include <cstddef>
#include <cstdint>
+#include <span>
#include "pw_rpc_protos/packet.pwpb.h"
-#include "pw_span/span.h"
#include "pw_status/status_with_size.h"
namespace pw::rpc::internal {
@@ -28,13 +28,13 @@ class Packet {
// Parses a packet from a protobuf message. Missing or malformed fields take
// their default values.
- static Packet FromBuffer(span<const std::byte> data);
+ static Packet FromBuffer(std::span<const std::byte> data);
constexpr Packet(PacketType type,
uint32_t channel_id = kUnassignedId,
uint32_t service_id = kUnassignedId,
uint32_t method_id = kUnassignedId,
- span<const std::byte> payload = {},
+ std::span<const std::byte> payload = {},
Status status = Status::OK)
: type_(type),
channel_id_(channel_id),
@@ -44,7 +44,7 @@ class Packet {
status_(status) {}
// Encodes the packet into its wire format. Returns the encoded size.
- StatusWithSize Encode(span<std::byte> buffer) const;
+ StatusWithSize Encode(std::span<std::byte> buffer) const;
// Determines the space required to encode the packet proto fields for a
// response. This may be used to split the buffer into reserved space and
@@ -58,14 +58,14 @@ class Packet {
uint32_t channel_id() const { return channel_id_; }
uint32_t service_id() const { return service_id_; }
uint32_t method_id() const { return method_id_; }
- const span<const std::byte>& payload() const { return payload_; }
+ const std::span<const std::byte>& payload() const { return payload_; }
Status status() const { return status_; }
void set_type(PacketType type) { type_ = type; }
void set_channel_id(uint32_t channel_id) { channel_id_ = channel_id; }
void set_service_id(uint32_t service_id) { service_id_ = service_id; }
void set_method_id(uint32_t method_id) { method_id_ = method_id; }
- void set_payload(span<const std::byte> payload) { payload_ = payload; }
+ void set_payload(std::span<const std::byte> payload) { payload_ = payload; }
void set_status(Status status) { status_ = status; }
private:
@@ -73,7 +73,7 @@ class Packet {
uint32_t channel_id_;
uint32_t service_id_;
uint32_t method_id_;
- span<const std::byte> payload_;
+ std::span<const std::byte> payload_;
Status status_;
};
diff --git a/pw_rpc/public/pw_rpc/internal/service.h b/pw_rpc/public/pw_rpc/internal/service.h
index 7e5a96f7c..9a82b57fc 100644
--- a/pw_rpc/public/pw_rpc/internal/service.h
+++ b/pw_rpc/public/pw_rpc/internal/service.h
@@ -14,11 +14,11 @@
#pragma once
#include <cstdint>
+#include <span>
#include <utility>
#include "pw_containers/intrusive_list.h"
#include "pw_rpc/internal/method.h"
-#include "pw_span/span.h"
namespace pw::rpc::internal {
@@ -40,7 +40,7 @@ class Service : public IntrusiveList<Service>::Item {
friend class ServiceRegistry;
uint32_t id_;
- span<const Method> methods_;
+ std::span<const Method> methods_;
};
} // namespace pw::rpc::internal
diff --git a/pw_rpc/public/pw_rpc/server.h b/pw_rpc/public/pw_rpc/server.h
index 1232a7562..c8b047675 100644
--- a/pw_rpc/public/pw_rpc/server.h
+++ b/pw_rpc/public/pw_rpc/server.h
@@ -14,6 +14,7 @@
#pragma once
#include <cstddef>
+#include <span>
#include "pw_containers/intrusive_list.h"
#include "pw_rpc/channel.h"
@@ -25,7 +26,7 @@ namespace pw::rpc {
class Server {
public:
- constexpr Server(span<Channel> channels)
+ constexpr Server(std::span<Channel> channels)
: channels_(static_cast<internal::Channel*>(channels.data()),
channels.size()) {}
@@ -36,7 +37,8 @@ class Server {
services_.push_front(service);
}
- void ProcessPacket(span<const std::byte> packet, ChannelOutput& interface);
+ void ProcessPacket(std::span<const std::byte> packet,
+ ChannelOutput& interface);
constexpr size_t channel_count() const { return channels_.size(); }
@@ -47,12 +49,12 @@ class Server {
void InvokeMethod(const internal::Packet& request,
Channel& channel,
internal::Packet& response,
- span<std::byte> buffer);
+ std::span<std::byte> buffer);
internal::Channel* FindChannel(uint32_t id) const;
internal::Channel* AssignChannel(uint32_t id, ChannelOutput& interface);
- span<internal::Channel> channels_;
+ std::span<internal::Channel> channels_;
IntrusiveList<internal::Service> services_;
IntrusiveList<internal::BaseServerWriter> writers_;
};
diff --git a/pw_rpc/pw_rpc_private/test_utils.h b/pw_rpc/pw_rpc_private/test_utils.h
index 6dcd8a6b5..8ad045b6d 100644
--- a/pw_rpc/pw_rpc_private/test_utils.h
+++ b/pw_rpc/pw_rpc_private/test_utils.h
@@ -16,12 +16,12 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <span>
#include "pw_rpc/internal/channel.h"
#include "pw_rpc/internal/method.h"
#include "pw_rpc/internal/packet.h"
#include "pw_rpc/internal/server.h"
-#include "pw_span/span.h"
namespace pw::rpc {
@@ -31,19 +31,19 @@ class TestOutput : public ChannelOutput {
constexpr TestOutput(const char* name = "TestOutput")
: ChannelOutput(name), sent_packet_{} {}
- span<std::byte> AcquireBuffer() override { return buffer_; }
+ std::span<std::byte> AcquireBuffer() override { return buffer_; }
void SendAndReleaseBuffer(size_t size) override {
- sent_packet_ = span(buffer_.data(), size);
+ sent_packet_ = std::span(buffer_.data(), size);
}
- span<const std::byte> buffer() const { return buffer_; }
+ std::span<const std::byte> buffer() const { return buffer_; }
- const span<const std::byte>& sent_packet() const { return sent_packet_; }
+ const std::span<const std::byte>& sent_packet() const { return sent_packet_; }
private:
std::array<std::byte, buffer_size> buffer_;
- span<const std::byte> sent_packet_;
+ std::span<const std::byte> sent_packet_;
};
// Version of the internal::Server with extra methods exposed for testing.
@@ -63,7 +63,7 @@ class ServerContextForTest {
ServerContextForTest(const internal::Method& method)
: channel_(Channel::Create<kChannelId>(&output_)),
- server_(span(&channel_, 1)),
+ server_(std::span(&channel_, 1)),
service_(kServiceId),
context_(static_cast<internal::Server&>(server_),
static_cast<internal::Channel&>(channel_),
@@ -75,7 +75,7 @@ class ServerContextForTest {
ServerContextForTest() : ServerContextForTest(service_.method) {}
// Creates a packet for this context's channel, service, and method.
- internal::Packet packet(span<const std::byte> payload) const {
+ internal::Packet packet(std::span<const std::byte> payload) const {
return internal::Packet(internal::PacketType::RPC,
kChannelId,
kServiceId,
diff --git a/pw_rpc/server.cc b/pw_rpc/server.cc
index 11857c12f..7f20a36a1 100644
--- a/pw_rpc/server.cc
+++ b/pw_rpc/server.cc
@@ -29,7 +29,8 @@ using std::byte;
using internal::Packet;
using internal::PacketType;
-void Server::ProcessPacket(span<const byte> data, ChannelOutput& interface) {
+void Server::ProcessPacket(std::span<const byte> data,
+ ChannelOutput& interface) {
Packet packet = Packet::FromBuffer(data);
if (packet.is_control()) {
// TODO(frolv): Handle control packets.
@@ -73,7 +74,7 @@ void Server::ProcessPacket(span<const byte> data, ChannelOutput& interface) {
void Server::InvokeMethod(const Packet& request,
Channel& channel,
internal::Packet& response,
- span<std::byte> payload_buffer) {
+ std::span<std::byte> payload_buffer) {
auto service = std::find_if(services_.begin(), services_.end(), [&](auto& s) {
return s.id() == request.service_id();
});
diff --git a/pw_rpc/server_test.cc b/pw_rpc/server_test.cc
index 6b5905d1f..7082772cb 100644
--- a/pw_rpc/server_test.cc
+++ b/pw_rpc/server_test.cc
@@ -76,15 +76,16 @@ class BasicServer : public ::testing::Test {
Server server_;
TestService service_;
- span<const byte> EncodeRequest(PacketType type,
- uint32_t channel_id,
- uint32_t service_id,
- uint32_t method_id,
- span<const byte> payload = kDefaultPayload) {
+ std::span<const byte> EncodeRequest(
+ PacketType type,
+ uint32_t channel_id,
+ uint32_t service_id,
+ uint32_t method_id,
+ std::span<const byte> payload = kDefaultPayload) {
auto sws = Packet(type, channel_id, service_id, method_id, payload)
.Encode(request_buffer_);
EXPECT_EQ(Status::OK, sws.status());
- return span(request_buffer_, sws.size());
+ return std::span(request_buffer_, sws.size());
}
private:
diff --git a/pw_rpc/test_impl/public_overrides/pw_rpc/internal/method.h b/pw_rpc/test_impl/public_overrides/pw_rpc/internal/method.h
index 6c3beeb79..297f14e63 100644
--- a/pw_rpc/test_impl/public_overrides/pw_rpc/internal/method.h
+++ b/pw_rpc/test_impl/public_overrides/pw_rpc/internal/method.h
@@ -15,10 +15,10 @@
#include <cstdint>
#include <cstring>
+#include <span>
#include "pw_rpc/internal/base_method.h"
#include "pw_rpc/server_context.h"
-#include "pw_span/span.h"
#include "pw_status/status_with_size.h"
namespace pw::rpc::internal {
@@ -30,8 +30,8 @@ class Method : public BaseMethod {
constexpr Method(uint32_t id) : BaseMethod(id), last_channel_id_(0) {}
StatusWithSize Invoke(ServerCall& call,
- span<const std::byte> request,
- span<std::byte> payload_buffer) const {
+ std::span<const std::byte> request,
+ std::span<std::byte> payload_buffer) const {
last_channel_id_ = call.channel().id();
last_request_ = request;
last_payload_buffer_ = payload_buffer;
@@ -43,10 +43,12 @@ class Method : public BaseMethod {
}
uint32_t last_channel_id() const { return last_channel_id_; }
- span<const std::byte> last_request() const { return last_request_; }
- span<std::byte> last_payload_buffer() const { return last_payload_buffer_; }
+ std::span<const std::byte> last_request() const { return last_request_; }
+ std::span<std::byte> last_payload_buffer() const {
+ return last_payload_buffer_;
+ }
- void set_response(span<const std::byte> payload) { response_ = payload; }
+ void set_response(std::span<const std::byte> payload) { response_ = payload; }
void set_status(Status status) { response_status_ = status; }
private:
@@ -54,10 +56,10 @@ class Method : public BaseMethod {
// The Method class is used exclusively in tests. Having these members mutable
// allows tests to verify that the Method is invoked correctly.
mutable uint32_t last_channel_id_;
- mutable span<const std::byte> last_request_;
- mutable span<std::byte> last_payload_buffer_;
+ mutable std::span<const std::byte> last_request_;
+ mutable std::span<std::byte> last_payload_buffer_;
- span<const std::byte> response_;
+ std::span<const std::byte> response_;
Status response_status_;
};
diff --git a/pw_stream/memory_stream.cc b/pw_stream/memory_stream.cc
index efe2c9701..ca7e27663 100644
--- a/pw_stream/memory_stream.cc
+++ b/pw_stream/memory_stream.cc
@@ -21,7 +21,7 @@
namespace pw::stream {
-Status MemoryWriter::DoWrite(span<const std::byte> data) {
+Status MemoryWriter::DoWrite(std::span<const std::byte> data) {
size_t bytes_to_write =
std::min(data.size_bytes(), dest_.size_bytes() - bytes_written_);
std::memcpy(dest_.data() + bytes_written_, data.data(), bytes_to_write);
diff --git a/pw_stream/memory_stream_test.cc b/pw_stream/memory_stream_test.cc
index ada85ab75..9e37bf32d 100644
--- a/pw_stream/memory_stream_test.cc
+++ b/pw_stream/memory_stream_test.cc
@@ -47,7 +47,7 @@ TEST(MemoryWriter, ValidateContents) {
EXPECT_TRUE(
memory_writer.Write(&kExpectedStruct, sizeof(kExpectedStruct)).ok());
- span<const std::byte> written_data = memory_writer.WrittenData();
+ std::span<const std::byte> written_data = memory_writer.WrittenData();
EXPECT_EQ(written_data.size_bytes(), sizeof(kExpectedStruct));
TestStruct temp;
std::memcpy(&temp, written_data.data(), written_data.size_bytes());
@@ -65,7 +65,8 @@ TEST(MemoryWriter, MultipleWrites) {
for (size_t i = 0; i < sizeof(buffer); ++i) {
buffer[i] = std::byte(counter++);
}
- } while (memory_writer.Write(span(buffer)) != Status::RESOURCE_EXHAUSTED);
+ } while (memory_writer.Write(std::span(buffer)) !=
+ Status::RESOURCE_EXHAUSTED);
// Ensure that we counted up to at least the sink buffer size. This can be
// more since we write to the sink via in intermediate buffer.
diff --git a/pw_stream/public/pw_stream/memory_stream.h b/pw_stream/public/pw_stream/memory_stream.h
index ad9d30d66..2dec4a204 100644
--- a/pw_stream/public/pw_stream/memory_stream.h
+++ b/pw_stream/public/pw_stream/memory_stream.h
@@ -15,19 +15,19 @@
#include <array>
#include <cstddef>
+#include <span>
-#include "pw_span/span.h"
#include "pw_stream/stream.h"
namespace pw::stream {
class MemoryWriter : public Writer {
public:
- MemoryWriter(span<std::byte> dest) : dest_(dest) {}
+ MemoryWriter(std::span<std::byte> dest) : dest_(dest) {}
size_t bytes_written() const { return bytes_written_; }
- span<const std::byte> WrittenData() const {
+ std::span<const std::byte> WrittenData() const {
return dest_.first(bytes_written_);
}
@@ -38,9 +38,9 @@ class MemoryWriter : public Writer {
//
// If the in-memory buffer is exhausted in the middle of a write, this will
// perform a partial write and Status::RESOURCE_EXHAUSTED will be returned.
- Status DoWrite(span<const std::byte> data) override;
+ Status DoWrite(std::span<const std::byte> data) override;
- span<std::byte> dest_;
+ std::span<std::byte> dest_;
size_t bytes_written_ = 0;
};
diff --git a/pw_stream/public/pw_stream/stream.h b/pw_stream/public/pw_stream/stream.h
index 6d5119157..13e30e968 100644
--- a/pw_stream/public/pw_stream/stream.h
+++ b/pw_stream/public/pw_stream/stream.h
@@ -15,9 +15,9 @@
#include <array>
#include <cstddef>
+#include <span>
#include "pw_assert/assert.h"
-#include "pw_span/span.h"
#include "pw_status/status.h"
namespace pw::stream {
@@ -36,12 +36,12 @@ class Writer {
//
// Derived classes should NOT try to override these public write methods.
// Instead, provide an implementation by overriding DoWrite().
- Status Write(span<const std::byte> data) {
+ Status Write(std::span<const std::byte> data) {
PW_DCHECK(data.empty() || data.data() != nullptr);
return DoWrite(data);
}
Status 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));
}
// Flush any buffered data, finalizing all writes.
@@ -52,7 +52,7 @@ class Writer {
virtual Status Flush() { return Status::OK; }
private:
- virtual Status DoWrite(span<const std::byte> data) = 0;
+ virtual Status DoWrite(std::span<const std::byte> data) = 0;
};
} // namespace pw::stream
diff --git a/pw_sys_io/public/pw_sys_io/sys_io.h b/pw_sys_io/public/pw_sys_io/sys_io.h
index 3010de1ff..5f545b316 100644
--- a/pw_sys_io/public/pw_sys_io/sys_io.h
+++ b/pw_sys_io/public/pw_sys_io/sys_io.h
@@ -37,9 +37,9 @@
#include <cstddef>
#include <cstring>
+#include <span>
#include <string_view>
-#include "pw_span/span.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
@@ -75,7 +75,7 @@ Status WriteByte(std::byte b);
// are returned as part of the StatusWithSize.
StatusWithSize WriteLine(const std::string_view& s);
-// Fill a byte span from the sys io backend using ReadByte().
+// Fill a byte std::span from the sys io backend using ReadByte().
// Implemented by: Facade
//
// This function is implemented by this facade and simply uses ReadByte() to
@@ -87,9 +87,9 @@ StatusWithSize WriteLine(const std::string_view& s);
// Return status is Status::OK if the destination span was successfully filled.
// In all cases, the number of bytes successuflly read to the destination span
// are returned as part of the StatusWithSize.
-StatusWithSize ReadBytes(span<std::byte> dest);
+StatusWithSize ReadBytes(std::span<std::byte> dest);
-// Write span of bytes out the sys io backend using WriteByte().
+// Write std::span of bytes out the sys io backend using WriteByte().
// Implemented by: Facade
//
// This function is implemented by this facade and simply writes the source
@@ -101,6 +101,6 @@ StatusWithSize ReadBytes(span<std::byte> dest);
// Return status is Status::OK if all the bytes from the source span were
// successfully written. In all cases, the number of bytes successfully written
// are returned as part of the StatusWithSize.
-StatusWithSize WriteBytes(span<const std::byte> src);
+StatusWithSize WriteBytes(std::span<const std::byte> src);
} // namespace pw::sys_io
diff --git a/pw_sys_io/sys_io.cc b/pw_sys_io/sys_io.cc
index ed0ab5c5a..8e013c3b2 100644
--- a/pw_sys_io/sys_io.cc
+++ b/pw_sys_io/sys_io.cc
@@ -16,7 +16,7 @@
namespace pw::sys_io {
-StatusWithSize ReadBytes(span<std::byte> dest) {
+StatusWithSize ReadBytes(std::span<std::byte> dest) {
for (size_t i = 0; i < dest.size_bytes(); ++i) {
Status result = ReadByte(&dest[i]);
if (!result.ok()) {
@@ -26,7 +26,7 @@ StatusWithSize ReadBytes(span<std::byte> dest) {
return StatusWithSize(dest.size_bytes());
}
-StatusWithSize WriteBytes(span<const std::byte> src) {
+StatusWithSize WriteBytes(std::span<const std::byte> src) {
for (size_t i = 0; i < src.size_bytes(); ++i) {
Status result = WriteByte(src[i]);
if (!result.ok()) {
diff --git a/pw_sys_io_baremetal_lm3s6965evb/sys_io_baremetal.cc b/pw_sys_io_baremetal_lm3s6965evb/sys_io_baremetal.cc
index 7930439b4..29fed33b3 100644
--- a/pw_sys_io_baremetal_lm3s6965evb/sys_io_baremetal.cc
+++ b/pw_sys_io_baremetal_lm3s6965evb/sys_io_baremetal.cc
@@ -169,14 +169,14 @@ Status WriteByte(std::byte b) {
// Writes a string using pw::sys_io, and add newline characters at the end.
StatusWithSize WriteLine(const std::string_view& s) {
size_t chars_written = 0;
- StatusWithSize result = WriteBytes(as_bytes(span(s)));
+ StatusWithSize result = WriteBytes(std::as_bytes(std::span(s)));
if (!result.ok()) {
return result;
}
chars_written += result.size();
// Write trailing newline ("\n\r").
- result = WriteBytes(as_bytes(span("\n\r", 2)));
+ result = WriteBytes(std::as_bytes(std::span("\n\r", 2)));
chars_written += result.size();
return StatusWithSize(result.status(), chars_written);
diff --git a/pw_sys_io_baremetal_stm32f429/sys_io_baremetal.cc b/pw_sys_io_baremetal_stm32f429/sys_io_baremetal.cc
index c5f5526c3..914593160 100644
--- a/pw_sys_io_baremetal_stm32f429/sys_io_baremetal.cc
+++ b/pw_sys_io_baremetal_stm32f429/sys_io_baremetal.cc
@@ -234,14 +234,14 @@ Status WriteByte(std::byte b) {
// Writes a string using pw::sys_io, and add newline characters at the end.
StatusWithSize WriteLine(const std::string_view& s) {
size_t chars_written = 0;
- StatusWithSize result = WriteBytes(as_bytes(span(s)));
+ StatusWithSize result = WriteBytes(std::as_bytes(std::span(s)));
if (!result.ok()) {
return result;
}
chars_written += result.size();
// Write trailing newline ("\n\r").
- result = WriteBytes(as_bytes(span("\n\r", 2)));
+ result = WriteBytes(std::as_bytes(std::span("\n\r", 2)));
chars_written += result.size();
return StatusWithSize(result.status(), chars_written);
diff --git a/pw_sys_io_stdio/sys_io.cc b/pw_sys_io_stdio/sys_io.cc
index 72e4df624..65d1a8914 100644
--- a/pw_sys_io_stdio/sys_io.cc
+++ b/pw_sys_io_stdio/sys_io.cc
@@ -40,7 +40,7 @@ Status WriteByte(std::byte b) {
StatusWithSize WriteLine(const std::string_view& s) {
size_t chars_written = 0;
- StatusWithSize size_result = WriteBytes(as_bytes(span(s)));
+ StatusWithSize size_result = WriteBytes(std::as_bytes(std::span(s)));
if (!size_result.ok()) {
return size_result;
}
diff --git a/pw_tokenizer/base64.cc b/pw_tokenizer/base64.cc
index e05390ec0..6ce4a4c05 100644
--- a/pw_tokenizer/base64.cc
+++ b/pw_tokenizer/base64.cc
@@ -14,8 +14,9 @@
#include "pw_tokenizer/base64.h"
+#include <span>
+
#include "pw_base64/base64.h"
-#include "pw_span/span.h"
namespace pw::tokenizer {
@@ -33,9 +34,9 @@ extern "C" size_t pw_TokenizerPrefixedBase64Encode(
char* output = static_cast<char*>(output_buffer);
output[0] = kBase64Prefix;
- base64::Encode(
- span(static_cast<const std::byte*>(binary_message), binary_size_bytes),
- &output[1]);
+ base64::Encode(std::span(static_cast<const std::byte*>(binary_message),
+ binary_size_bytes),
+ &output[1]);
return encoded_size;
}
@@ -52,7 +53,7 @@ extern "C" size_t pw_TokenizerPrefixedBase64Decode(const void* base64_message,
return base64::Decode(
std::string_view(&base64[1], base64_size_bytes - 1),
- span(static_cast<std::byte*>(output_buffer), output_buffer_size));
+ std::span(static_cast<std::byte*>(output_buffer), output_buffer_size));
}
} // namespace pw::tokenizer
diff --git a/pw_tokenizer/base64_test.cc b/pw_tokenizer/base64_test.cc
index 8a6f8b6fe..59f3a05dd 100644
--- a/pw_tokenizer/base64_test.cc
+++ b/pw_tokenizer/base64_test.cc
@@ -15,10 +15,10 @@
#include "pw_tokenizer/base64.h"
#include <cstring>
+#include <span>
#include <string_view>
#include "gtest/gtest.h"
-#include "pw_span/span.h"
namespace pw::tokenizer {
namespace {
@@ -34,9 +34,10 @@ class PrefixedBase64 : public ::testing::Test {
const struct TestData {
template <size_t kSize>
TestData(const char (&binary_data)[kSize], const char* base64_data)
- : binary{as_bytes(span(binary_data, kSize - 1))}, base64(base64_data) {}
+ : binary{std::as_bytes(std::span(binary_data, kSize - 1))},
+ base64(base64_data) {}
- span<const std::byte> binary;
+ std::span<const std::byte> binary;
std::string_view base64;
} kTestData[] = {
{"", "$"},
@@ -68,7 +69,8 @@ TEST_F(PrefixedBase64, Encode_EmptyInput_WritesPrefix) {
}
TEST_F(PrefixedBase64, Encode_EmptyOutput_WritesNothing) {
- EXPECT_EQ(0u, PrefixedBase64Encode(kTestData[5].binary, span(base64_, 0)));
+ EXPECT_EQ(0u,
+ PrefixedBase64Encode(kTestData[5].binary, std::span(base64_, 0)));
EXPECT_EQ('\0', base64_[0]);
}
@@ -90,15 +92,16 @@ TEST_F(PrefixedBase64, Decode_OnlyPrefix_WritesNothing) {
}
TEST_F(PrefixedBase64, Decode_EmptyOutput_WritesNothing) {
- EXPECT_EQ(0u, PrefixedBase64Decode(kTestData[5].base64, span(binary_, 0)));
+ EXPECT_EQ(0u,
+ PrefixedBase64Decode(kTestData[5].base64, std::span(binary_, 0)));
EXPECT_EQ(std::byte{0}, binary_[0]);
}
TEST_F(PrefixedBase64, Decode_OutputTooSmall_WritesNothing) {
auto& item = kTestData[5];
- EXPECT_EQ(
- 0u,
- PrefixedBase64Decode(item.base64, span(binary_, item.binary.size() - 1)));
+ EXPECT_EQ(0u,
+ PrefixedBase64Decode(item.base64,
+ std::span(binary_, item.binary.size() - 1)));
EXPECT_EQ(std::byte{0}, binary_[0]);
}
@@ -109,7 +112,7 @@ TEST(PrefixedBase64, DecodeInPlace) {
std::memcpy(buffer, base64.data(), base64.size());
EXPECT_EQ(binary.size(),
- PrefixedBase64DecodeInPlace(span(buffer, base64.size())));
+ PrefixedBase64DecodeInPlace(std::span(buffer, base64.size())));
ASSERT_EQ(0, std::memcmp(binary.data(), buffer, binary.size()));
}
}
diff --git a/pw_tokenizer/decode.cc b/pw_tokenizer/decode.cc
index 22ce61a5b..cccaa08d4 100644
--- a/pw_tokenizer/decode.cc
+++ b/pw_tokenizer/decode.cc
@@ -172,7 +172,7 @@ StringSegment::ArgSize StringSegment::VarargSize(std::array<char, 2> length,
}
DecodedArg StringSegment::DecodeString(
- const span<const uint8_t>& arguments) const {
+ const std::span<const uint8_t>& arguments) const {
if (arguments.empty()) {
return DecodedArg(ArgStatus::kMissing, text_);
}
@@ -201,13 +201,13 @@ DecodedArg StringSegment::DecodeString(
}
DecodedArg StringSegment::DecodeInteger(
- const span<const uint8_t>& arguments) const {
+ const std::span<const uint8_t>& arguments) const {
if (arguments.empty()) {
return DecodedArg(ArgStatus::kMissing, text_);
}
int64_t value;
- const size_t bytes = varint::Decode(pw::as_bytes(arguments), &value);
+ const size_t bytes = varint::Decode(std::as_bytes(arguments), &value);
if (bytes == 0u) {
return DecodedArg(ArgStatus::kDecodeError,
@@ -228,7 +228,7 @@ DecodedArg StringSegment::DecodeInteger(
}
DecodedArg StringSegment::DecodeFloatingPoint(
- const span<const uint8_t>& arguments) const {
+ const std::span<const uint8_t>& arguments) const {
static_assert(sizeof(float) == 4u);
if (arguments.size() < sizeof(float)) {
return DecodedArg(ArgStatus::kMissing, text_);
@@ -239,7 +239,8 @@ DecodedArg StringSegment::DecodeFloatingPoint(
return DecodedArg::FromValue(text_.c_str(), value, sizeof(value));
}
-DecodedArg StringSegment::Decode(const span<const uint8_t>& arguments) const {
+DecodedArg StringSegment::Decode(
+ const std::span<const uint8_t>& arguments) const {
switch (type_) {
case kLiteral:
return DecodedArg(text_);
@@ -329,7 +330,8 @@ FormatString::FormatString(const char* format) {
}
}
-DecodedFormatString FormatString::Format(span<const uint8_t> arguments) const {
+DecodedFormatString FormatString::Format(
+ std::span<const uint8_t> arguments) const {
std::vector<DecodedArg> results;
bool skip = false;
diff --git a/pw_tokenizer/detokenize.cc b/pw_tokenizer/detokenize.cc
index ef462694e..ad7bb78dd 100644
--- a/pw_tokenizer/detokenize.cc
+++ b/pw_tokenizer/detokenize.cc
@@ -69,8 +69,8 @@ bool IsBetterResult(const DecodingResult& lhs, const DecodingResult& rhs) {
DetokenizedString::DetokenizedString(
uint32_t token,
- const span<const TokenizedStringEntry>& entries,
- const span<const uint8_t>& arguments)
+ const std::span<const TokenizedStringEntry>& entries,
+ const std::span<const uint8_t>& arguments)
: token_(token), has_token_(true) {
std::vector<DecodingResult> results;
@@ -104,7 +104,7 @@ Detokenizer::Detokenizer(const TokenDatabase& database) {
}
DetokenizedString Detokenizer::Detokenize(
- const span<const uint8_t>& encoded) const {
+ const std::span<const uint8_t>& encoded) const {
// The token is missing from the encoded data; there is nothing to do.
if (encoded.size() < sizeof(uint32_t)) {
return DetokenizedString();
@@ -117,8 +117,8 @@ DetokenizedString Detokenizer::Detokenize(
return DetokenizedString(token,
result == database_.end()
- ? span<TokenizedStringEntry>()
- : span(result->second),
+ ? std::span<TokenizedStringEntry>()
+ : std::span(result->second),
encoded.subspan(sizeof(token)));
}
diff --git a/pw_tokenizer/detokenize_fuzzer.cc b/pw_tokenizer/detokenize_fuzzer.cc
index 76e3a7f54..cf5571715 100644
--- a/pw_tokenizer/detokenize_fuzzer.cc
+++ b/pw_tokenizer/detokenize_fuzzer.cc
@@ -76,7 +76,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::vector<uint8_t> buffer =
provider.ConsumeBytes<uint8_t>(consumed_size);
auto detokenized_string =
- detokenizer.Detokenize(pw::span(&buffer[0], buffer.size()));
+ detokenizer.Detokenize(std::span(&buffer[0], buffer.size()));
PW_UNUSED(detokenized_string);
break;
}
diff --git a/pw_tokenizer/encode_args.cc b/pw_tokenizer/encode_args.cc
index 27fa7f2bd..b53cc22d0 100644
--- a/pw_tokenizer/encode_args.cc
+++ b/pw_tokenizer/encode_args.cc
@@ -73,15 +73,15 @@ static_assert(0b01u == static_cast<uint8_t>(ArgType::kInt64));
static_assert(0b10u == static_cast<uint8_t>(ArgType::kDouble));
static_assert(0b11u == static_cast<uint8_t>(ArgType::kString));
-size_t EncodeInt(int value, const span<uint8_t>& output) {
- return varint::Encode(value, pw::as_writable_bytes(output));
+size_t EncodeInt(int value, const std::span<uint8_t>& output) {
+ return varint::Encode(value, std::as_writable_bytes(output));
}
-size_t EncodeInt64(int64_t value, const span<uint8_t>& output) {
- return varint::Encode(value, pw::as_writable_bytes(output));
+size_t EncodeInt64(int64_t value, const std::span<uint8_t>& output) {
+ return varint::Encode(value, std::as_writable_bytes(output));
}
-size_t EncodeFloat(float value, const span<uint8_t>& output) {
+size_t EncodeFloat(float value, const std::span<uint8_t>& output) {
if (output.size() < sizeof(value)) {
return 0;
}
@@ -89,7 +89,7 @@ size_t EncodeFloat(float value, const span<uint8_t>& output) {
return sizeof(value);
}
-size_t EncodeString(const char* string, const span<uint8_t>& output) {
+size_t EncodeString(const char* string, const std::span<uint8_t>& output) {
// The top bit of the status byte indicates if the string was truncated.
static constexpr size_t kMaxStringLength = 0x7Fu;
@@ -126,7 +126,7 @@ size_t EncodeString(const char* string, const span<uint8_t>& output) {
size_t EncodeArgs(pw_TokenizerArgTypes types,
va_list args,
- span<uint8_t> output) {
+ std::span<uint8_t> output) {
size_t arg_count = types & PW_TOKENIZER_TYPE_COUNT_MASK;
types >>= PW_TOKENIZER_TYPE_COUNT_SIZE_BITS;
diff --git a/pw_tokenizer/generate_decoding_test_data.cc b/pw_tokenizer/generate_decoding_test_data.cc
index b43cb9ceb..9adfdfed9 100644
--- a/pw_tokenizer/generate_decoding_test_data.cc
+++ b/pw_tokenizer/generate_decoding_test_data.cc
@@ -25,8 +25,8 @@
#include <cstdint>
#include <cstdio>
#include <random>
+#include <span>
-#include "pw_span/span.h"
#include "pw_tokenizer/internal/decode.h"
#include "pw_tokenizer/tokenize.h"
#include "pw_varint/varint.h"
@@ -168,7 +168,7 @@ class TestDataFile {
// Writes a decoding test case to the file.
void TestCase(TestDataFile* file,
- pw::span<const uint8_t> buffer,
+ std::span<const uint8_t> buffer,
const char* format,
const char* formatted) {
file->printf(R"(TestCase("%s", "%s", %s)",
@@ -189,7 +189,7 @@ void TestCase(TestDataFile* file,
const char (&buffer)[kSize],
const char* formatted) {
TestCase(file,
- pw::span(reinterpret_cast<const uint8_t*>(buffer), kSize - 1),
+ std::span(reinterpret_cast<const uint8_t*>(buffer), kSize - 1),
format,
formatted);
}
@@ -204,7 +204,7 @@ void TestCase(TestDataFile* file,
std::array<char, 128> formatted = {}; \
std::snprintf(formatted.data(), formatted.size(), format, ##__VA_ARGS__); \
TestCase(file, \
- pw::span(buffer).first(size).subspan(4), /* skip the token */ \
+ std::span(buffer).first(size).subspan(4), /* skip the token */ \
format, \
formatted.data()); \
} while (0)
@@ -382,7 +382,8 @@ void OutputVarintTest(TestDataFile* file, T i) {
std::array<uint8_t, 10> buffer;
// All integers are encoded as signed for tokenization.
- size_t size = pw::varint::Encode(i, pw::as_writable_bytes(pw::span(buffer)));
+ size_t size =
+ pw::varint::Encode(i, std::as_writable_bytes(std::span(buffer)));
for (size_t i = 0; i < size; ++i) {
file->printf("\\x%02x", buffer[i]);
diff --git a/pw_tokenizer/java/dev/pigweed/tokenizer/detokenizer.cc b/pw_tokenizer/java/dev/pigweed/tokenizer/detokenizer.cc
index b2c8f3329..06a5003c1 100644
--- a/pw_tokenizer/java/dev/pigweed/tokenizer/detokenizer.cc
+++ b/pw_tokenizer/java/dev/pigweed/tokenizer/detokenizer.cc
@@ -19,9 +19,9 @@
#include <jni.h>
#include <cstring>
+#include <span>
#include "pw_preprocessor/concat.h"
-#include "pw_span/span.h"
#include "pw_tokenizer/detokenize.h"
#include "pw_tokenizer/token_database.h"
@@ -57,7 +57,7 @@ JNIEXPORT jlong DETOKENIZER_METHOD(newNativeDetokenizer)(JNIEnv* env,
jbyte* const data = env->GetByteArrayElements(array, nullptr);
const jsize size = env->GetArrayLength(array);
- TokenDatabase tokens = TokenDatabase::Create(pw::span(data, size));
+ TokenDatabase tokens = TokenDatabase::Create(std::span(data, size));
const jlong handle =
PointerToHandle(new Detokenizer(tokens.ok() ? tokens : TokenDatabase()));
diff --git a/pw_tokenizer/public/pw_tokenizer/base64.h b/pw_tokenizer/public/pw_tokenizer/base64.h
index 45bc029f5..679b805db 100644
--- a/pw_tokenizer/public/pw_tokenizer/base64.h
+++ b/pw_tokenizer/public/pw_tokenizer/base64.h
@@ -63,10 +63,9 @@ PW_EXTERN_C_END
#ifdef __cplusplus
+#include <span>
#include <string_view>
-#include "pw_span/span.h"
-
namespace pw::tokenizer {
inline constexpr char kBase64Prefix = PW_TOKENIZER_BASE64_PREFIX;
@@ -74,8 +73,8 @@ inline constexpr char kBase64Prefix = PW_TOKENIZER_BASE64_PREFIX;
// Encodes a binary tokenized message as prefixed Base64. Returns the size of
// the number of characters written to output_buffer. Returns 0 if the buffer is
// too small.
-inline size_t PrefixedBase64Encode(span<const std::byte> binary_message,
- span<char> output_buffer) {
+inline size_t PrefixedBase64Encode(std::span<const std::byte> binary_message,
+ std::span<char> output_buffer) {
return pw_TokenizerPrefixedBase64Encode(binary_message.data(),
binary_message.size(),
output_buffer.data(),
@@ -86,7 +85,7 @@ inline size_t PrefixedBase64Encode(span<const std::byte> binary_message,
// the decoded binary data. The resulting data is ready to be passed to
// pw::tokenizer::Detokenizer::Detokenize.
inline size_t PrefixedBase64Decode(std::string_view base64_message,
- span<std::byte> output_buffer) {
+ std::span<std::byte> output_buffer) {
return pw_TokenizerPrefixedBase64Decode(base64_message.data(),
base64_message.size(),
output_buffer.data(),
@@ -95,7 +94,7 @@ inline size_t PrefixedBase64Decode(std::string_view base64_message,
// Decodes a prefixed Base64 tokenized message to binary in place. Returns the
// size of the decoded binary data.
-inline size_t PrefixedBase64DecodeInPlace(span<std::byte> buffer) {
+inline size_t PrefixedBase64DecodeInPlace(std::span<std::byte> buffer) {
return pw_TokenizerPrefixedBase64Decode(
buffer.data(), buffer.size(), buffer.data(), buffer.size());
}
diff --git a/pw_tokenizer/public/pw_tokenizer/detokenize.h b/pw_tokenizer/public/pw_tokenizer/detokenize.h
index 745024987..7c658cfda 100644
--- a/pw_tokenizer/public/pw_tokenizer/detokenize.h
+++ b/pw_tokenizer/public/pw_tokenizer/detokenize.h
@@ -26,12 +26,12 @@
#include <cstddef>
#include <cstdint>
+#include <span>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
-#include "pw_span/span.h"
#include "pw_tokenizer/internal/decode.h"
#include "pw_tokenizer/token_database.h"
@@ -44,8 +44,8 @@ using TokenizedStringEntry = std::pair<FormatString, uint32_t /*date removed*/>;
class DetokenizedString {
public:
DetokenizedString(uint32_t token,
- const span<const TokenizedStringEntry>& entries,
- const span<const uint8_t>& arguments);
+ const std::span<const TokenizedStringEntry>& entries,
+ const std::span<const uint8_t>& arguments);
DetokenizedString() : has_token_(false) {}
@@ -80,14 +80,15 @@ class Detokenizer {
// Decodes and detokenizes the encoded message. Returns a DetokenizedString
// that stores all possible detokenized string results.
- DetokenizedString Detokenize(const span<const uint8_t>& encoded) const;
+ DetokenizedString Detokenize(const std::span<const uint8_t>& encoded) const;
DetokenizedString Detokenize(const std::string_view& encoded) const {
return Detokenize(encoded.data(), encoded.size());
}
DetokenizedString Detokenize(const void* encoded, size_t size_bytes) const {
- return Detokenize(span(static_cast<const uint8_t*>(encoded), size_bytes));
+ return Detokenize(
+ std::span(static_cast<const uint8_t*>(encoded), size_bytes));
}
private:
diff --git a/pw_tokenizer/public/pw_tokenizer/internal/decode.h b/pw_tokenizer/public/pw_tokenizer/internal/decode.h
index 8cdf69081..913838f00 100644
--- a/pw_tokenizer/public/pw_tokenizer/internal/decode.h
+++ b/pw_tokenizer/public/pw_tokenizer/internal/decode.h
@@ -20,13 +20,12 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
+#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
-#include "pw_span/span.h"
-
// Decoding errors are marked with prefix and suffix so that they stand out from
// the rest of the decoded strings. These macros are used to build decoding
// error strings.
@@ -132,7 +131,7 @@ class StringSegment {
// Returns the DecodedArg with this StringSegment decoded according to the
// provided arguments.
- DecodedArg Decode(const span<const uint8_t>& arguments) const;
+ DecodedArg Decode(const std::span<const uint8_t>& arguments) const;
// Skips decoding this StringSegment. Literals and %% are expanded as normal.
DecodedArg Skip() const;
@@ -170,11 +169,12 @@ class StringSegment {
StringSegment(const std::string_view& text, Type type, ArgSize local_size)
: text_(text), type_(type), local_size_(local_size) {}
- DecodedArg DecodeString(const span<const uint8_t>& arguments) const;
+ DecodedArg DecodeString(const std::span<const uint8_t>& arguments) const;
- DecodedArg DecodeInteger(const span<const uint8_t>& arguments) const;
+ DecodedArg DecodeInteger(const std::span<const uint8_t>& arguments) const;
- DecodedArg DecodeFloatingPoint(const span<const uint8_t>& arguments) const;
+ DecodedArg DecodeFloatingPoint(
+ const std::span<const uint8_t>& arguments) const;
std::string text_;
Type type_;
@@ -229,11 +229,11 @@ class FormatString {
// Formats this format string according to the provided encoded arguments and
// returns a string.
- DecodedFormatString Format(span<const uint8_t> arguments) const;
+ DecodedFormatString Format(std::span<const uint8_t> arguments) const;
DecodedFormatString Format(const std::string_view& arguments) const {
- return Format(span(reinterpret_cast<const uint8_t*>(arguments.data()),
- arguments.size()));
+ return Format(std::span(reinterpret_cast<const uint8_t*>(arguments.data()),
+ arguments.size()));
}
private:
diff --git a/pw_tokenizer/pw_tokenizer_private/encode_args.h b/pw_tokenizer/pw_tokenizer_private/encode_args.h
index b1360a8bf..2f399496c 100644
--- a/pw_tokenizer/pw_tokenizer_private/encode_args.h
+++ b/pw_tokenizer/pw_tokenizer_private/encode_args.h
@@ -16,8 +16,8 @@
#include <array>
#include <cstdarg>
#include <cstddef>
+#include <span>
-#include "pw_span/span.h"
#include "pw_tokenizer/config.h"
#include "pw_tokenizer/internal/argument_types.h"
#include "pw_tokenizer/internal/tokenize_string.h"
@@ -38,7 +38,7 @@ static_assert(offsetof(EncodedMessage, args) == sizeof(EncodedMessage::token),
// parameter specifies the argument types, in place of a format string.
size_t EncodeArgs(pw_TokenizerArgTypes types,
va_list args,
- span<uint8_t> output);
+ std::span<uint8_t> output);
} // namespace tokenizer
} // namespace pw
diff --git a/pw_tokenizer/token_database_fuzzer.cc b/pw_tokenizer/token_database_fuzzer.cc
index 0fb5d5729..3e243c895 100644
--- a/pw_tokenizer/token_database_fuzzer.cc
+++ b/pw_tokenizer/token_database_fuzzer.cc
@@ -18,11 +18,11 @@
// operations on this database.
#include <cstring>
+#include <span>
#include "pw_fuzzer/asan_interface.h"
#include "pw_fuzzer/fuzzed_data_provider.h"
#include "pw_preprocessor/util.h"
-#include "pw_span/span.h"
#include "pw_tokenizer/token_database.h"
namespace pw::tokenizer {
@@ -115,12 +115,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
ASAN_POISON_MEMORY_REGION(poisoned, poisoned_length);
- // We create a database from a span of the buffer since the string
+ // We create a database from a std::span of the buffer since the string
// entries might not be null terminated, and the creation of a database
// from a raw buffer has an explicit null terminated string requirement
// specified in the API.
- span<uint8_t> data_span(buffer, data_size);
- auto token_database = TokenDatabase::Create<span<uint8_t>>(data_span);
+ std::span<uint8_t> data_span(buffer, data_size);
+ auto token_database = TokenDatabase::Create<std::span<uint8_t>>(data_span);
volatile auto match = token_database.Find(random_token);
PW_UNUSED(match);
diff --git a/pw_tokenizer/tokenize.cc b/pw_tokenizer/tokenize.cc
index 4f29876b1..c7e369960 100644
--- a/pw_tokenizer/tokenize.cc
+++ b/pw_tokenizer/tokenize.cc
@@ -40,11 +40,11 @@ extern "C" void _pw_TokenizeToBuffer(void* buffer,
va_list args;
va_start(args, types);
- const size_t encoded_bytes =
- EncodeArgs(types,
- args,
- span<uint8_t>(static_cast<uint8_t*>(buffer) + sizeof(token),
- *buffer_size_bytes - sizeof(token)));
+ const size_t encoded_bytes = EncodeArgs(
+ types,
+ args,
+ std::span<uint8_t>(static_cast<uint8_t*>(buffer) + sizeof(token),
+ *buffer_size_bytes - sizeof(token)));
va_end(args);
*buffer_size_bytes = sizeof(token) + encoded_bytes;
diff --git a/pw_unit_test/simple_printing_main.cc b/pw_unit_test/simple_printing_main.cc
index 859f5f878..5aeab4578 100644
--- a/pw_unit_test/simple_printing_main.cc
+++ b/pw_unit_test/simple_printing_main.cc
@@ -12,9 +12,9 @@
// License for the specific language governing permissions and limitations under
// the License.
+#include <span>
#include <string_view>
-#include "pw_span/span.h"
#include "pw_sys_io/sys_io.h"
#include "pw_unit_test/framework.h"
#include "pw_unit_test/simple_printing_event_handler.h"
@@ -25,7 +25,7 @@ int main() {
if (append_newline) {
pw::sys_io::WriteLine(s);
} else {
- pw::sys_io::WriteBytes(pw::as_bytes(pw::span(s)));
+ pw::sys_io::WriteBytes(std::as_bytes(std::span(s)));
}
});
diff --git a/pw_varint/public/pw_varint/varint.h b/pw_varint/public/pw_varint/varint.h
index b128bc0e9..b9f6e59d6 100644
--- a/pw_varint/public/pw_varint/varint.h
+++ b/pw_varint/public/pw_varint/varint.h
@@ -40,10 +40,10 @@ size_t pw_VarintZigZagEncodedSize(int64_t integer);
} // extern "C"
+#include <span>
#include <type_traits>
#include "pw_polyfill/language_features.h"
-#include "pw_span/span.h"
namespace pw {
namespace varint {
@@ -82,7 +82,7 @@ constexpr std::make_signed_t<T> ZigZagDecode(T n)
// Encodes a uint64_t with Little-Endian Base 128 (LEB128) encoding.
inline size_t EncodeLittleEndianBase128(uint64_t integer,
- const span<std::byte>& output) {
+ const std::span<std::byte>& output) {
return pw_VarintEncode(integer, output.data(), output.size());
}
@@ -97,7 +97,7 @@ inline size_t EncodeLittleEndianBase128(uint64_t integer,
// Returns the number of bytes written or 0 if the result didn't fit in the
// encoding buffer.
template <typename T>
-size_t Encode(T integer, const span<std::byte>& output) {
+size_t Encode(T integer, const std::span<std::byte>& output) {
if (std::is_signed<T>()) {
return pw_VarintZigZagEncode(integer, output.data(), output.size());
} else {
@@ -125,11 +125,11 @@ size_t Encode(T integer, const span<std::byte>& output) {
// data = data.subspan(bytes)
// }
//
-inline size_t Decode(const span<const std::byte>& input, int64_t* value) {
+inline size_t Decode(const std::span<const std::byte>& input, int64_t* value) {
return pw_VarintZigZagDecode(input.data(), input.size(), value);
}
-inline size_t Decode(const span<const std::byte>& input, uint64_t* value) {
+inline size_t Decode(const std::span<const std::byte>& input, uint64_t* value) {
return pw_VarintDecode(input.data(), input.size(), value);
}