pw_kvs: Remove unnecessary alignment_bytes arg
Change-Id: Ie8288f870a182ac0d5d9a3764bcce96a713247db
diff --git a/pw_kvs/entry.cc b/pw_kvs/entry.cc
index 086c014..fa224d4 100644
--- a/pw_kvs/entry.cc
+++ b/pw_kvs/entry.cc
@@ -58,13 +58,13 @@
string_view key,
span<const byte> value,
uint16_t value_size_bytes,
- size_t alignment_bytes,
uint32_t transaction_id)
: Entry(&partition,
address,
{.magic = format.magic,
.checksum = 0,
- .alignment_units = alignment_bytes_to_units(alignment_bytes),
+ .alignment_units =
+ alignment_bytes_to_units(partition.alignment_bytes()),
.key_length_bytes = static_cast<uint8_t>(key.size()),
.value_size_bytes = value_size_bytes,
.transaction_id = transaction_id}) {
@@ -74,9 +74,6 @@
checksum.data(),
std::min(checksum.size(), sizeof(header_.checksum)));
}
-
- // TODO: 0 is an invalid alignment value. There should be an assert for this.
- // DCHECK_NE(alignment_bytes, 0);
}
StatusWithSize Entry::Write(const string_view key,
diff --git a/pw_kvs/entry_test.cc b/pw_kvs/entry_test.cc
index 65c7f64..64b1718 100644
--- a/pw_kvs/entry_test.cc
+++ b/pw_kvs/entry_test.cc
@@ -35,20 +35,19 @@
TEST(Entry, Size_RoundsUpToAlignment) {
FakeFlashBuffer<64, 2> flash(16);
- FlashPartition partition(&flash, 0, flash.sector_count());
for (size_t alignment_bytes = 1; alignment_bytes <= 4096; ++alignment_bytes) {
+ FlashPartition partition(&flash, 0, flash.sector_count(), alignment_bytes);
const size_t align = AlignUp(alignment_bytes, Entry::kMinAlignmentBytes);
for (size_t value : {size_t(0), align - 1, align, align + 1, 2 * align}) {
- Entry entry = Entry::Valid(
- partition, 0, kFormat, "k", {nullptr, value}, alignment_bytes, 0);
+ Entry entry =
+ Entry::Valid(partition, 0, kFormat, "k", {nullptr, value}, 0);
ASSERT_EQ(AlignUp(sizeof(EntryHeader) + 1 /* key */ + value, align),
entry.size());
}
- Entry entry =
- Entry::Tombstone(partition, 0, kFormat, "k", alignment_bytes, 0);
+ Entry entry = Entry::Tombstone(partition, 0, kFormat, "k", 0);
ASSERT_EQ(AlignUp(sizeof(EntryHeader) + 1 /* key */, align), entry.size());
}
}
@@ -58,7 +57,7 @@
FlashPartition partition(&flash, 0, flash.sector_count());
auto entry =
- Entry::Valid(partition, 1, kFormat, "k", as_bytes(span("123")), 1, 9876);
+ Entry::Valid(partition, 1, kFormat, "k", as_bytes(span("123")), 9876);
EXPECT_FALSE(entry.deleted());
EXPECT_EQ(entry.magic(), kFormat.magic);
@@ -70,7 +69,7 @@
FakeFlashBuffer<64, 2> flash(16);
FlashPartition partition(&flash, 0, flash.sector_count());
- auto entry = Entry::Tombstone(partition, 1, kFormat, "key", 1, 123);
+ auto entry = Entry::Tombstone(partition, 1, kFormat, "key", 123);
EXPECT_TRUE(entry.deleted());
EXPECT_EQ(entry.magic(), kFormat.magic);
@@ -92,6 +91,7 @@
constexpr auto kPadding1 = ByteStr("\0\0\0\0\0");
constexpr auto kEntry1 = AsBytes(kHeader1, kKey1, kValue1, kPadding1);
+static_assert(kEntry1.size() == 32);
class ValidEntryInFlash : public ::testing::Test {
protected:
@@ -186,12 +186,12 @@
TEST(ValidEntry, Write) {
FakeFlashBuffer<1024, 4> flash;
- FlashPartition partition(&flash);
+ FlashPartition partition(&flash, 0, flash.sector_count(), 32);
ChecksumCrc16 checksum;
const EntryFormat format{0x600DF00Du, &checksum};
Entry entry =
- Entry::Valid(partition, 53, format, "key45", kValue1, 32, 0x96979899u);
+ Entry::Valid(partition, 53, format, "key45", kValue1, 0x96979899u);
auto result = entry.Write("key45", kValue1);
EXPECT_EQ(Status::OK, result.status());
@@ -260,7 +260,7 @@
ChecksumCrc16 checksum;
const EntryFormat format{0x600DF00Du, &checksum};
- Entry entry = Entry::Tombstone(partition, 16, format, "K", 16, 0x03020100);
+ Entry entry = Entry::Tombstone(partition, 16, format, "K", 0x03020100);
auto result = entry.Write("K", {});
EXPECT_EQ(Status::OK, result.status());
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 09f3c49..f7fda90 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -816,19 +816,14 @@
last_transaction_id_ += 1;
if (state == KeyDescriptor::kDeleted) {
- return Entry::Tombstone(partition_,
- address,
- entry_header_format_,
- key,
- partition_.alignment_bytes(),
- last_transaction_id_);
+ return Entry::Tombstone(
+ partition_, address, entry_header_format_, key, last_transaction_id_);
}
return Entry::Valid(partition_,
address,
entry_header_format_,
key,
value,
- partition_.alignment_bytes(),
last_transaction_id_);
}
diff --git a/pw_kvs/public/pw_kvs/internal/entry.h b/pw_kvs/public/pw_kvs/internal/entry.h
index 03df6eb..1e9f116 100644
--- a/pw_kvs/public/pw_kvs/internal/entry.h
+++ b/pw_kvs/public/pw_kvs/internal/entry.h
@@ -61,16 +61,9 @@
const EntryFormat& format,
std::string_view key,
span<const std::byte> value,
- size_t alignment_bytes,
uint32_t transaction_id) {
- return Entry(partition,
- address,
- format,
- key,
- value,
- value.size(),
- alignment_bytes,
- transaction_id);
+ return Entry(
+ partition, address, format, key, value, value.size(), transaction_id);
}
// Creates a new Entry for a tombstone entry, which marks a deleted key.
@@ -78,7 +71,6 @@
Address address,
const EntryFormat& format,
std::string_view key,
- size_t alignment_bytes,
uint32_t transaction_id) {
return Entry(partition,
address,
@@ -86,7 +78,6 @@
key,
{},
kDeletedValueLength,
- alignment_bytes,
transaction_id);
}
@@ -181,7 +172,6 @@
std::string_view key,
span<const std::byte> value,
uint16_t value_size_bytes,
- size_t alignment_bytes,
uint32_t transaction_id);
constexpr Entry(FlashPartition* partition,