style: update non-type template args to kCamelCase
Updates most, if not all, deviations from our non-type template
arg style guide.
Change-Id: I275639a7c15e38e0db9d198a6802f9cd5bb9cf89
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39661
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_allocator/public/pw_allocator/freelist.h b/pw_allocator/public/pw_allocator/freelist.h
index a77f7e4..e10692a 100644
--- a/pw_allocator/public/pw_allocator/freelist.h
+++ b/pw_allocator/public/pw_allocator/freelist.h
@@ -21,7 +21,7 @@
namespace pw::allocator {
-template <size_t num_buckets>
+template <size_t kNumBuckets>
class FreeListBuffer;
// Basic freelist implementation for an allocator.
@@ -84,7 +84,7 @@
size_t FindChunkPtrForSize(size_t size, bool non_null) const;
private:
- template <size_t num_buckets>
+ template <size_t kNumBuckets>
friend class FreeListBuffer;
struct FreeListNode {
@@ -101,21 +101,21 @@
};
// Holder for FreeList's storage.
-template <size_t num_buckets>
+template <size_t kNumBuckets>
class FreeListBuffer : public FreeList {
public:
// These constructors are a little hacky because of the initialization order.
// Because FreeList has a trivial constructor, this is safe, however.
explicit FreeListBuffer(std::initializer_list<size_t> sizes)
- : FreeList(chunks_, sizes_), sizes_(sizes), chunks_(num_buckets + 1, 0) {}
- explicit FreeListBuffer(std::array<size_t, num_buckets> sizes)
+ : FreeList(chunks_, sizes_), sizes_(sizes), chunks_(kNumBuckets + 1, 0) {}
+ explicit FreeListBuffer(std::array<size_t, kNumBuckets> sizes)
: FreeList(chunks_, sizes_),
sizes_(sizes.begin(), sizes.end()),
- chunks_(num_buckets + 1, 0) {}
+ chunks_(kNumBuckets + 1, 0) {}
private:
- Vector<size_t, num_buckets> sizes_;
- Vector<FreeList::FreeListNode*, num_buckets + 1> chunks_;
+ Vector<size_t, kNumBuckets> sizes_;
+ Vector<FreeList::FreeListNode*, kNumBuckets + 1> chunks_;
};
} // namespace pw::allocator
diff --git a/pw_allocator/public/pw_allocator/freelist_heap.h b/pw_allocator/public/pw_allocator/freelist_heap.h
index cdd1aa1..8073ec3 100644
--- a/pw_allocator/public/pw_allocator/freelist_heap.h
+++ b/pw_allocator/public/pw_allocator/freelist_heap.h
@@ -24,7 +24,7 @@
class FreeListHeap {
public:
- template <size_t N>
+ template <size_t kNumBuckets>
friend class FreeListHeapBuffer;
struct HeapStats {
size_t total_bytes;
@@ -55,10 +55,10 @@
HeapStats heap_stats_;
};
-template <size_t N = 6>
+template <size_t kNumBuckets = 6>
class FreeListHeapBuffer {
public:
- static constexpr std::array<size_t, N> defaultBuckets{
+ static constexpr std::array<size_t, kNumBuckets> defaultBuckets{
16, 32, 64, 128, 256, 512};
FreeListHeapBuffer(std::span<std::byte> region)
@@ -76,7 +76,7 @@
void LogHeapStats() { heap_.LogHeapStats(); }
private:
- FreeListBuffer<N> freelist_;
+ FreeListBuffer<kNumBuckets> freelist_;
FreeListHeap heap_;
};
diff --git a/pw_bytes/docs.rst b/pw_bytes/docs.rst
index 01b5e0f..2e21aaa 100644
--- a/pw_bytes/docs.rst
+++ b/pw_bytes/docs.rst
@@ -31,7 +31,7 @@
bytes in a fixed-size buffer. ByteBuilder handles reading and writing integers
with varying endianness.
-.. cpp:class:: template <size_t max_size> ByteBuffer
+.. cpp:class:: template <size_t kMaxSize> ByteBuffer
``ByteBuilder`` with an internally allocated buffer.
diff --git a/pw_bytes/public/pw_bytes/array.h b/pw_bytes/public/pw_bytes/array.h
index 8f93ddd..453f9ea 100644
--- a/pw_bytes/public/pw_bytes/array.h
+++ b/pw_bytes/public/pw_bytes/array.h
@@ -88,9 +88,9 @@
// Converts a string literal to an array of bytes, without the trailing '\0'.
template <typename B = std::byte,
- size_t size,
- typename Indices = std::make_index_sequence<size - 1>>
-consteval auto String(const char (&str)[size]) {
+ size_t kSize,
+ typename Indices = std::make_index_sequence<kSize - 1>>
+consteval auto String(const char (&str)[kSize]) {
return internal::String<B>(str, Indices{});
}
@@ -116,11 +116,11 @@
// Creates an initialized array of bytes. Initializes the array to a value or
// the return values from a function that accepts the index as a parameter.
-template <typename B, size_t size, typename T>
+template <typename B, size_t kSize, typename T>
constexpr auto Initialized(const T& value_or_function) {
- std::array<B, size> array{};
+ std::array<B, kSize> array{};
- for (size_t i = 0; i < size; ++i) {
+ for (size_t i = 0; i < kSize; ++i) {
if constexpr (std::is_integral_v<T>) {
array[i] = static_cast<B>(value_or_function);
} else {
@@ -131,9 +131,9 @@
}
// Initialized(value_or_function) defaults to using std::byte.
-template <size_t size, typename T>
+template <size_t kSize, typename T>
constexpr auto Initialized(const T& value_or_function) {
- return Initialized<std::byte, size>(value_or_function);
+ return Initialized<std::byte, kSize>(value_or_function);
}
// Creates an array of bytes from a series of function arguments. Unlike
diff --git a/pw_bytes/public/pw_bytes/byte_builder.h b/pw_bytes/public/pw_bytes/byte_builder.h
index a145353..ae931b0 100644
--- a/pw_bytes/public/pw_bytes/byte_builder.h
+++ b/pw_bytes/public/pw_bytes/byte_builder.h
@@ -350,7 +350,7 @@
};
// ByteBuffers declare a buffer along with a ByteBuilder.
-template <size_t size_bytes>
+template <size_t kSizeBytes>
class ByteBuffer : public ByteBuilder {
public:
ByteBuffer() : ByteBuilder(buffer_) {}
@@ -361,28 +361,28 @@
}
// A smaller ByteBuffer may be copied or assigned into a larger one.
- template <size_t other_size_bytes>
- ByteBuffer(const ByteBuffer<other_size_bytes>& other)
+ template <size_t kOtherSizeBytes>
+ ByteBuffer(const ByteBuffer<kOtherSizeBytes>& other)
: ByteBuilder(buffer_, other) {
- static_assert(ByteBuffer<other_size_bytes>::max_size() <= max_size(),
+ static_assert(ByteBuffer<kOtherSizeBytes>::max_size() <= max_size(),
"A ByteBuffer cannot be copied into a smaller buffer");
CopyContents(other);
}
- template <size_t other_size_bytes>
- ByteBuffer& operator=(const ByteBuffer<other_size_bytes>& other) {
- assign<other_size_bytes>(other);
+ template <size_t kOtherSizeBytes>
+ ByteBuffer& operator=(const ByteBuffer<kOtherSizeBytes>& other) {
+ assign<kOtherSizeBytes>(other);
return *this;
}
ByteBuffer& operator=(const ByteBuffer& other) {
- assign<size_bytes>(other);
+ assign<kSizeBytes>(other);
return *this;
}
- template <size_t other_size_bytes>
- ByteBuffer& assign(const ByteBuffer<other_size_bytes>& other) {
- static_assert(ByteBuffer<other_size_bytes>::max_size() <= max_size(),
+ template <size_t kOtherSizeBytes>
+ ByteBuffer& assign(const ByteBuffer<kOtherSizeBytes>& other) {
+ static_assert(ByteBuffer<kOtherSizeBytes>::max_size() <= max_size(),
"A ByteBuffer cannot be copied into a smaller buffer");
CopySizeAndStatus(other);
CopyContents(other);
@@ -391,9 +391,9 @@
// Returns the maximum length of the bytes that can be inserted in the bytes
// buffer.
- static constexpr size_t max_size() { return size_bytes; }
+ static constexpr size_t max_size() { return kSizeBytes; }
- // Returns a ByteBuffer<size_bytes>& instead of a generic ByteBuilder& for
+ // Returns a ByteBuffer<kSizeBytes>& instead of a generic ByteBuilder& for
// append calls.
template <typename... Args>
ByteBuffer& append(Args&&... args) {
@@ -407,7 +407,7 @@
std::memcpy(buffer_.data(), other.data(), other.size());
}
- std::array<std::byte, size_bytes> buffer_;
+ std::array<std::byte, kSizeBytes> buffer_;
};
} // namespace pw
diff --git a/pw_bytes/public/pw_bytes/endian.h b/pw_bytes/public/pw_bytes/endian.h
index 9eb1d71..08b6503 100644
--- a/pw_bytes/public/pw_bytes/endian.h
+++ b/pw_bytes/public/pw_bytes/endian.h
@@ -153,23 +153,23 @@
// ReadInOrder from a static-extent span, with compile-time bounds checking.
template <typename T,
typename B,
- size_t buffer_size,
- typename = std::enable_if_t<buffer_size != std::dynamic_extent &&
+ size_t kBufferSize,
+ typename = std::enable_if_t<kBufferSize != std::dynamic_extent &&
sizeof(B) == sizeof(std::byte)>>
-T ReadInOrder(std::endian order, std::span<B, buffer_size> buffer) {
- static_assert(buffer_size >= sizeof(T));
+T ReadInOrder(std::endian order, std::span<B, kBufferSize> buffer) {
+ static_assert(kBufferSize >= sizeof(T));
return ReadInOrder<T>(order, buffer.data());
}
// ReadInOrder from a std::array, with compile-time bounds checking.
-template <typename T, typename B, size_t buffer_size>
-T ReadInOrder(std::endian order, const std::array<B, buffer_size>& buffer) {
+template <typename T, typename B, size_t kBufferSize>
+T ReadInOrder(std::endian order, const std::array<B, kBufferSize>& buffer) {
return ReadInOrder<T>(order, std::span(buffer));
}
// ReadInOrder from a C array, with compile-time bounds checking.
-template <typename T, typename B, size_t buffer_size>
-T ReadInOrder(std::endian order, const B (&buffer)[buffer_size]) {
+template <typename T, typename B, size_t kBufferSize>
+T ReadInOrder(std::endian order, const B (&buffer)[kBufferSize]) {
return ReadInOrder<T>(order, std::span(buffer));
}
diff --git a/pw_containers/public/pw_containers/flat_map.h b/pw_containers/public/pw_containers/flat_map.h
index 29daab0..b4c2ab5 100644
--- a/pw_containers/public/pw_containers/flat_map.h
+++ b/pw_containers/public/pw_containers/flat_map.h
@@ -28,7 +28,7 @@
//
// The keys do not need to be sorted as the constructor will sort the items
// if need be.
-template <typename Key, typename Value, size_t array_size>
+template <typename Key, typename Value, size_t kArraySize>
class FlatMap {
public:
// Define and use a custom Pair object. This is because std::pair does not
@@ -45,22 +45,22 @@
using value_type = Pair<key_type, mapped_type>;
using size_type = size_t;
using difference_type = ptrdiff_t;
- using container_type = typename std::array<value_type, array_size>;
+ using container_type = typename std::array<value_type, kArraySize>;
using iterator = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
- constexpr FlatMap(const std::array<value_type, array_size>& items)
+ constexpr FlatMap(const std::array<value_type, kArraySize>& items)
: items_(items) {
- ConstexprSort(items_.data(), array_size);
+ ConstexprSort(items_.data(), kArraySize);
}
FlatMap(FlatMap&) = delete;
FlatMap& operator=(FlatMap&) = delete;
// Capacity.
- constexpr size_type size() const { return array_size; }
+ constexpr size_type size() const { return kArraySize; }
constexpr size_type empty() const { return size() == 0; }
- constexpr size_type max_size() const { return array_size; }
+ constexpr size_type max_size() const { return kArraySize; }
// Lookup.
constexpr bool contains(const key_type& key) const {
@@ -131,7 +131,7 @@
}
}
- std::array<value_type, array_size> items_;
+ std::array<value_type, kArraySize> items_;
};
} // namespace pw::containers
diff --git a/pw_containers/public/pw_containers/vector.h b/pw_containers/public/pw_containers/vector.h
index b629aa4..1d05fd1 100644
--- a/pw_containers/public/pw_containers/vector.h
+++ b/pw_containers/public/pw_containers/vector.h
@@ -38,7 +38,7 @@
// The DestructorHelper is used to make Vector<T> trivially destructible if T
// is. This could be replaced with a C++20 constraint.
-template <typename VectorClass, bool is_trivially_destructible>
+template <typename VectorClass, bool kIsTriviallyDestructible>
class DestructorHelper;
template <typename VectorClass>
@@ -99,15 +99,15 @@
Vector(const Vector& other)
: Vector<T, vector_impl::kGeneric>(max_size, other) {}
- template <size_t other_max_size>
- Vector(const Vector<T, other_max_size>& other)
+ template <size_t kOtherMaxSize>
+ Vector(const Vector<T, kOtherMaxSize>& other)
: Vector<T, vector_impl::kGeneric>(max_size, other) {}
Vector(Vector&& other) noexcept
: Vector<T, vector_impl::kGeneric>(max_size, std::move(other)) {}
- template <size_t other_max_size>
- Vector(Vector<T, other_max_size>&& other) noexcept
+ template <size_t kOtherMaxSize>
+ Vector(Vector<T, kOtherMaxSize>&& other) noexcept
: Vector<T, vector_impl::kGeneric>(max_size, std::move(other)) {}
Vector(std::initializer_list<T> list)
@@ -118,8 +118,8 @@
return *this;
}
- template <size_t other_max_size>
- Vector& operator=(const Vector<T, other_max_size>& other) noexcept {
+ template <size_t kOtherMaxSize>
+ Vector& operator=(const Vector<T, kOtherMaxSize>& other) noexcept {
Vector<T>::assign(other.begin(), other.end());
return *this;
}
@@ -129,8 +129,8 @@
return *this;
}
- template <size_t other_max_size>
- Vector& operator=(Vector<T, other_max_size>&& other) noexcept {
+ template <size_t kOtherMaxSize>
+ Vector& operator=(Vector<T, kOtherMaxSize>&& other) noexcept {
Vector<T>::operator=(std::move(other));
return *this;
}
diff --git a/pw_fuzzer/public/pw_fuzzer/fuzzed_data_provider.h b/pw_fuzzer/public/pw_fuzzer/fuzzed_data_provider.h
index 1d661fa..f8f4777 100644
--- a/pw_fuzzer/public/pw_fuzzer/fuzzed_data_provider.h
+++ b/pw_fuzzer/public/pw_fuzzer/fuzzed_data_provider.h
@@ -107,9 +107,9 @@
return static_cast<T>(0);
}
- template <typename T, size_t size>
- T PickValueInArray(const T (&array)[size]) {
- static_assert(size > 0, "The array must be non empty.");
+ template <typename T, size_t kSize>
+ T PickValueInArray(const T (&array)[kSize]) {
+ static_assert(kSize > 0, "The array must be non empty.");
return array[0];
}
diff --git a/pw_hdlc/public/pw_hdlc/decoder.h b/pw_hdlc/public/pw_hdlc/decoder.h
index b956c0e..a9e3c03 100644
--- a/pw_hdlc/public/pw_hdlc/decoder.h
+++ b/pw_hdlc/public/pw_hdlc/decoder.h
@@ -157,19 +157,19 @@
};
// DecoderBuffers declare a buffer along with a Decoder.
-template <size_t size_bytes>
+template <size_t kSizeBytes>
class DecoderBuffer : public Decoder {
public:
DecoderBuffer() : Decoder(frame_buffer_) {}
// Returns the maximum length of the bytes that can be inserted in the bytes
// buffer.
- static constexpr size_t max_size() { return size_bytes; }
+ static constexpr size_t max_size() { return kSizeBytes; }
private:
- static_assert(size_bytes >= Frame::kMinSizeBytes);
+ static_assert(kSizeBytes >= Frame::kMinSizeBytes);
- std::array<std::byte, size_bytes> frame_buffer_;
+ std::array<std::byte, kSizeBytes> frame_buffer_;
};
} // namespace pw::hdlc
diff --git a/pw_hdlc/public/pw_hdlc/rpc_channel.h b/pw_hdlc/public/pw_hdlc/rpc_channel.h
index f2210cb..58dac72 100644
--- a/pw_hdlc/public/pw_hdlc/rpc_channel.h
+++ b/pw_hdlc/public/pw_hdlc/rpc_channel.h
@@ -62,7 +62,7 @@
//
// WARNING: This ChannelOutput is not thread-safe. If thread-safety is required,
// wrap this in a pw::rpc::SynchronizedChannelOutput.
-template <size_t buffer_size>
+template <size_t kBufferSize>
class RpcChannelOutputBuffer : public rpc::ChannelOutput {
public:
constexpr RpcChannelOutputBuffer(stream::Writer& writer,
@@ -82,7 +82,7 @@
private:
stream::Writer& writer_;
- std::array<std::byte, buffer_size> buffer_;
+ std::array<std::byte, kBufferSize> buffer_;
const uint64_t address_;
};
diff --git a/pw_kvs/key_value_store_test.cc b/pw_kvs/key_value_store_test.cc
index 846f1ba..2926cce 100644
--- a/pw_kvs/key_value_store_test.cc
+++ b/pw_kvs/key_value_store_test.cc
@@ -48,14 +48,14 @@
constexpr size_t kMaxUsableSectors = 256;
// This is a self contained flash unit with both memory and a single partition.
-template <uint32_t sector_size_bytes, uint16_t sector_count>
+template <uint32_t kSectorSizeBytes, uint16_t kSectorCount>
struct FlashWithPartitionFake {
// Default to 16 byte alignment, which is common in practice.
FlashWithPartitionFake() : FlashWithPartitionFake(16) {}
FlashWithPartitionFake(size_t alignment_bytes)
: memory(alignment_bytes), partition(&memory, 0, memory.sector_count()) {}
- FakeFlashMemoryBuffer<sector_size_bytes, sector_count> memory;
+ FakeFlashMemoryBuffer<kSectorSizeBytes, kSectorCount> memory;
FlashPartition partition;
public:
diff --git a/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h b/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
index 4a180c8..02babfa 100644
--- a/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
+++ b/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
@@ -89,35 +89,35 @@
// This class, which is aliased to pw::log_tokenized::Metadata below, is used to
// access the log metadata packed into the tokenizer's payload argument.
-template <unsigned level_bits,
- unsigned module_bits,
- unsigned flag_bits,
+template <unsigned kLevelBits,
+ unsigned kModuleBits,
+ unsigned kFlagBits,
typename T = uintptr_t>
class GenericMetadata {
public:
template <T log_level, T module, T flags>
static constexpr GenericMetadata Set() {
- static_assert(log_level < (1 << level_bits), "The level is too large!");
- static_assert(module < (1 << module_bits), "The module is too large!");
- static_assert(flags < (1 << flag_bits), "The flags are too large!");
+ static_assert(log_level < (1 << kLevelBits), "The level is too large!");
+ static_assert(module < (1 << kModuleBits), "The module is too large!");
+ static_assert(flags < (1 << kFlagBits), "The flags are too large!");
- return GenericMetadata(log_level | (module << level_bits) |
- (flags << (module_bits + level_bits)));
+ return GenericMetadata(log_level | (module << kLevelBits) |
+ (flags << (kModuleBits + kLevelBits)));
}
constexpr GenericMetadata(T value) : bits_(value) {}
// The log level of this message.
- constexpr T level() const { return bits_ & Mask<level_bits>(); }
+ constexpr T level() const { return bits_ & Mask<kLevelBits>(); }
// The 16 bit tokenized version of the module name (PW_LOG_MODULE_NAME).
constexpr T module() const {
- return (bits_ >> level_bits) & Mask<module_bits>();
+ return (bits_ >> kLevelBits) & Mask<kModuleBits>();
}
// The flags provided to the log call.
constexpr T flags() const {
- return (bits_ >> (level_bits + module_bits)) & Mask<flag_bits>();
+ return (bits_ >> (kLevelBits + kModuleBits)) & Mask<kFlagBits>();
}
private:
@@ -128,7 +128,7 @@
T bits_;
- static_assert(level_bits + module_bits + flag_bits <= sizeof(bits_) * 8);
+ static_assert(kLevelBits + kModuleBits + kFlagBits <= sizeof(bits_) * 8);
};
} // namespace internal
diff --git a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
index e0d52c3..bba5bb3 100644
--- a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
+++ b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
@@ -182,20 +182,20 @@
// Write data that is filled with a byte value that increments each write. Write
// many times without read/pop and then check to make sure correct contents are
// in the ring buffer.
-template <bool user_data>
+template <bool kUserData>
void CountingUpWriteReadTest() {
- PrefixedEntryRingBuffer ring(user_data);
+ PrefixedEntryRingBuffer ring(kUserData);
byte test_buffer[single_entry_test_buffer_size];
EXPECT_EQ(ring.SetBuffer(test_buffer), OkStatus());
EXPECT_EQ(ring.EntryCount(), 0u);
- constexpr size_t data_size = sizeof(single_entry_data) - (user_data ? 1 : 0);
+ constexpr size_t kDataSize = sizeof(single_entry_data) - (kUserData ? 1 : 0);
for (size_t i = 0; i < kOuterCycles; i++) {
size_t seed = i;
- byte write_buffer[data_size];
+ byte write_buffer[kDataSize];
size_t j;
for (j = 0; j < kSingleEntryCycles; j++) {
@@ -217,7 +217,7 @@
memset(write_buffer, fill_val + j, sizeof(write_buffer));
ASSERT_EQ(ring.PeekFront(read_buffer, &read_size), OkStatus());
- ASSERT_EQ(memcmp(write_buffer, read_buffer, data_size), 0);
+ ASSERT_EQ(memcmp(write_buffer, read_buffer, kDataSize), 0);
ASSERT_EQ(ring.PopFront(), OkStatus());
}
diff --git a/pw_rpc/base_client_call_test.cc b/pw_rpc/base_client_call_test.cc
index 44a3243..7f15146 100644
--- a/pw_rpc/base_client_call_test.cc
+++ b/pw_rpc/base_client_call_test.cc
@@ -26,8 +26,8 @@
{
BaseClientCall call(&context.channel(),
- context.kServiceId,
- context.kMethodId,
+ context.service_id(),
+ context.method_id(),
[](BaseClientCall&, const Packet&) {});
EXPECT_EQ(context.client().active_calls(), 1u);
}
@@ -53,8 +53,8 @@
TEST(BaseClientCall, SendsPacketWithPayload) {
ClientContextForTest context;
FakeClientCall call(&context.channel(),
- context.kServiceId,
- context.kMethodId,
+ context.service_id(),
+ context.method_id(),
[](BaseClientCall&, const Packet&) {});
constexpr std::byte payload[]{std::byte{0x08}, std::byte{0x39}};
@@ -63,8 +63,8 @@
EXPECT_EQ(context.output().packet_count(), 1u);
Packet packet = context.output().sent_packet();
EXPECT_EQ(packet.channel_id(), context.channel().id());
- EXPECT_EQ(packet.service_id(), context.kServiceId);
- EXPECT_EQ(packet.method_id(), context.kMethodId);
+ EXPECT_EQ(packet.service_id(), context.service_id());
+ EXPECT_EQ(packet.method_id(), context.method_id());
EXPECT_EQ(std::memcmp(packet.payload().data(), payload, sizeof(payload)), 0);
}
diff --git a/pw_rpc/base_server_writer_test.cc b/pw_rpc/base_server_writer_test.cc
index 0e4ffe8..f2d9d27 100644
--- a/pw_rpc/base_server_writer_test.cc
+++ b/pw_rpc/base_server_writer_test.cc
@@ -120,8 +120,8 @@
const Packet& packet = context.output().sent_packet();
EXPECT_EQ(packet.type(), PacketType::SERVER_STREAM_END);
- EXPECT_EQ(packet.channel_id(), context.kChannelId);
- EXPECT_EQ(packet.service_id(), context.kServiceId);
+ EXPECT_EQ(packet.channel_id(), context.channel_id());
+ EXPECT_EQ(packet.service_id(), context.service_id());
EXPECT_EQ(packet.method_id(), context.get().method().id());
EXPECT_TRUE(packet.payload().empty());
EXPECT_EQ(packet.status(), OkStatus());
diff --git a/pw_rpc/client_test.cc b/pw_rpc/client_test.cc
index 9249877..a5993fea 100644
--- a/pw_rpc/client_test.cc
+++ b/pw_rpc/client_test.cc
@@ -48,7 +48,7 @@
ClientContextForTest context;
TestClientCall call(
- &context.channel(), context.kServiceId, context.kMethodId);
+ &context.channel(), context.service_id(), context.method_id());
EXPECT_EQ(context.SendResponse(OkStatus(), {}), OkStatus());
EXPECT_TRUE(call.invoked());
@@ -62,9 +62,9 @@
ASSERT_EQ(context.output().packet_count(), 1u);
const Packet& packet = context.output().sent_packet();
EXPECT_EQ(packet.type(), PacketType::CLIENT_ERROR);
- EXPECT_EQ(packet.channel_id(), context.kChannelId);
- EXPECT_EQ(packet.service_id(), context.kServiceId);
- EXPECT_EQ(packet.method_id(), context.kMethodId);
+ EXPECT_EQ(packet.channel_id(), context.channel_id());
+ EXPECT_EQ(packet.service_id(), context.service_id());
+ EXPECT_EQ(packet.method_id(), context.method_id());
EXPECT_TRUE(packet.payload().empty());
EXPECT_EQ(packet.status(), Status::FailedPrecondition());
}
diff --git a/pw_rpc/nanopb/nanopb_method_test.cc b/pw_rpc/nanopb/nanopb_method_test.cc
index ca2653c..d38c461 100644
--- a/pw_rpc/nanopb/nanopb_method_test.cc
+++ b/pw_rpc/nanopb/nanopb_method_test.cc
@@ -195,7 +195,7 @@
const Packet& packet = context.output().sent_packet();
EXPECT_EQ(PacketType::SERVER_ERROR, packet.type());
EXPECT_EQ(Status::DataLoss(), packet.status());
- EXPECT_EQ(context.kServiceId, packet.service_id());
+ EXPECT_EQ(context.service_id(), packet.service_id());
EXPECT_EQ(method.id(), packet.method_id());
}
@@ -216,7 +216,7 @@
const Packet& packet = context.output().sent_packet();
EXPECT_EQ(PacketType::SERVER_ERROR, packet.type());
EXPECT_EQ(Status::Internal(), packet.status());
- EXPECT_EQ(context.kServiceId, packet.service_id());
+ EXPECT_EQ(context.service_id(), packet.service_id());
EXPECT_EQ(method.id(), packet.method_id());
EXPECT_EQ(value, last_request.integer);
diff --git a/pw_rpc/nanopb/public/pw_rpc/internal/nanopb_method.h b/pw_rpc/nanopb/public/pw_rpc/internal/nanopb_method.h
index dc4d45b..6944e4a 100644
--- a/pw_rpc/nanopb/public/pw_rpc/internal/nanopb_method.h
+++ b/pw_rpc/nanopb/public/pw_rpc/internal/nanopb_method.h
@@ -249,15 +249,15 @@
// Invoker function for unary RPCs. Allocates request and response structs by
// size, with maximum alignment, to avoid generating unnecessary copies of
// this function for each request/response type.
- template <size_t request_size, size_t response_size>
+ template <size_t kRequestSize, size_t kResponseSize>
static void UnaryInvoker(const Method& method,
ServerCall& call,
const Packet& request) {
_PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
- std::aligned_storage_t<request_size, alignof(std::max_align_t)>
+ std::aligned_storage_t<kRequestSize, alignof(std::max_align_t)>
request_struct{};
_PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
- std::aligned_storage_t<response_size, alignof(std::max_align_t)>
+ std::aligned_storage_t<kResponseSize, alignof(std::max_align_t)>
response_struct{};
static_cast<const NanopbMethod&>(method).CallUnary(
@@ -267,12 +267,12 @@
// Invoker function for server streaming RPCs. Allocates space for a request
// struct. Ignores the payload buffer since resposnes are sent through the
// ServerWriter.
- template <size_t request_size>
+ template <size_t kRequestSize>
static void ServerStreamingInvoker(const Method& method,
ServerCall& call,
const Packet& request) {
_PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
- std::aligned_storage_t<request_size, alignof(std::max_align_t)>
+ std::aligned_storage_t<kRequestSize, alignof(std::max_align_t)>
request_struct{};
static_cast<const NanopbMethod&>(method).CallServerStreaming(
diff --git a/pw_rpc/nanopb/public/pw_rpc/nanopb_test_method_context.h b/pw_rpc/nanopb/public/pw_rpc/nanopb_test_method_context.h
index ba2e482..1dbc1e1 100644
--- a/pw_rpc/nanopb/public/pw_rpc/nanopb_test_method_context.h
+++ b/pw_rpc/nanopb/public/pw_rpc/nanopb_test_method_context.h
@@ -63,8 +63,8 @@
//
// PW_NANOPB_TEST_METHOD_CONTEXT takes two optional arguments:
//
-// size_t max_responses: maximum responses to store; ignored unless streaming
-// size_t output_size_bytes: buffer size; must be large enough for a packet
+// size_t kMaxResponse: maximum responses to store; ignored unless streaming
+// size_t kOutputSizeBytes: buffer size; must be large enough for a packet
//
// Example:
//
@@ -78,9 +78,9 @@
##__VA_ARGS__>
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses = 4,
- size_t output_size_bytes = 128>
+ uint32_t kMethodId,
+ size_t kMaxResponse = 4,
+ size_t kOutputSizeBytes = 128>
class NanopbTestMethodContext;
// Internal classes that implement NanopbTestMethodContext.
@@ -125,16 +125,16 @@
// Collects everything needed to invoke a particular RPC.
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
struct InvocationContext {
using Request = internal::Request<method>;
using Response = internal::Response<method>;
template <typename... Args>
InvocationContext(Args&&... args)
- : output(MethodLookup::GetNanopbMethod<Service, method_id>(),
+ : output(MethodLookup::GetNanopbMethod<Service, kMethodId>(),
responses,
buffer),
channel(Channel::Create<123>(&output)),
@@ -143,25 +143,25 @@
call(static_cast<internal::Server&>(server),
static_cast<internal::Channel&>(channel),
service,
- MethodLookup::GetNanopbMethod<Service, method_id>()) {}
+ MethodLookup::GetNanopbMethod<Service, kMethodId>()) {}
MessageOutput<Response> output;
rpc::Channel channel;
rpc::Server server;
Service service;
- Vector<Response, max_responses> responses;
- std::array<std::byte, output_size> buffer = {};
+ Vector<Response, kMaxResponse> responses;
+ std::array<std::byte, kOutputSize> buffer = {};
internal::ServerCall call;
};
// Method invocation context for a unary RPC. Returns the status in call() and
// provides the response through the response() method.
-template <typename Service, auto method, uint32_t method_id, size_t output_size>
+template <typename Service, auto method, uint32_t kMethodId, size_t kOutputSize>
class UnaryContext {
private:
- InvocationContext<Service, method, method_id, 1, output_size> ctx_;
+ InvocationContext<Service, method, kMethodId, 1, kOutputSize> ctx_;
public:
using Request = typename decltype(ctx_)::Request;
@@ -191,13 +191,12 @@
// Method invocation context for a server streaming RPC.
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
class ServerStreamingContext {
private:
- InvocationContext<Service, method, method_id, max_responses, output_size>
- ctx_;
+ InvocationContext<Service, method, kMethodId, kMaxResponse, kOutputSize> ctx_;
public:
using Request = typename decltype(ctx_)::Request;
@@ -249,17 +248,17 @@
// RPC it is for.
template <typename Service,
auto method,
- uint32_t method_id,
- size_t responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
using Context = std::tuple_element_t<
static_cast<size_t>(internal::MethodTraits<decltype(method)>::kType),
- std::tuple<UnaryContext<Service, method, method_id, output_size>,
+ std::tuple<UnaryContext<Service, method, kMethodId, kOutputSize>,
ServerStreamingContext<Service,
method,
- method_id,
- responses,
- output_size>
+ kMethodId,
+ kMaxResponse,
+ kOutputSize>
// TODO(hepler): Support client and bidi streaming
>>;
@@ -308,25 +307,19 @@
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size_bytes>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSizeBytes>
class NanopbTestMethodContext
- : public internal::test::nanopb::Context<Service,
- method,
- method_id,
- max_responses,
- output_size_bytes> {
+ : public internal::test::nanopb::
+ Context<Service, method, kMethodId, kMaxResponse, kOutputSizeBytes> {
public:
// Forwards constructor arguments to the service class.
template <typename... ServiceArgs>
NanopbTestMethodContext(ServiceArgs&&... service_args)
- : internal::test::nanopb::Context<Service,
- method,
- method_id,
- max_responses,
- output_size_bytes>(
- std::forward<ServiceArgs>(service_args)...) {}
+ : internal::test::nanopb::
+ Context<Service, method, kMethodId, kMaxResponse, kOutputSizeBytes>(
+ std::forward<ServiceArgs>(service_args)...) {}
};
} // namespace pw::rpc
diff --git a/pw_rpc/public/pw_rpc/channel.h b/pw_rpc/public/pw_rpc/channel.h
index f773fe1..d17cd52 100644
--- a/pw_rpc/public/pw_rpc/channel.h
+++ b/pw_rpc/public/pw_rpc/channel.h
@@ -70,10 +70,10 @@
// Creates a channel with a static ID. The channel's output can also be
// static, or it can set to null to allow dynamically opening connections
// through the channel.
- template <uint32_t id>
+ template <uint32_t kId>
constexpr static Channel Create(ChannelOutput* output) {
- static_assert(id != kUnassignedChannelId, "Channel ID cannot be 0");
- return Channel(id, output);
+ static_assert(kId != kUnassignedChannelId, "Channel ID cannot be 0");
+ return Channel(kId, output);
}
constexpr uint32_t id() const { return id_; }
diff --git a/pw_rpc/public/pw_rpc/internal/method_lookup.h b/pw_rpc/public/pw_rpc/internal/method_lookup.h
index cd7ddcb..7383a01 100644
--- a/pw_rpc/public/pw_rpc/internal/method_lookup.h
+++ b/pw_rpc/public/pw_rpc/internal/method_lookup.h
@@ -25,24 +25,24 @@
// union member in a constant expression, so this results in a compiler error.
class MethodLookup {
public:
- template <typename Service, uint32_t method_id>
+ template <typename Service, uint32_t kMethodId>
static constexpr const auto& GetRawMethod() {
- const auto& method = GetMethodUnion<Service, method_id>().raw_method();
- static_assert(method.id() == method_id, "Incorrect method implementation");
+ const auto& method = GetMethodUnion<Service, kMethodId>().raw_method();
+ static_assert(method.id() == kMethodId, "Incorrect method implementation");
return method;
}
- template <typename Service, uint32_t method_id>
+ template <typename Service, uint32_t kMethodId>
static constexpr const auto& GetNanopbMethod() {
- const auto& method = GetMethodUnion<Service, method_id>().nanopb_method();
- static_assert(method.id() == method_id, "Incorrect method implementation");
+ const auto& method = GetMethodUnion<Service, kMethodId>().nanopb_method();
+ static_assert(method.id() == kMethodId, "Incorrect method implementation");
return method;
}
private:
- template <typename Service, uint32_t method_id>
+ template <typename Service, uint32_t kMethodId>
static constexpr const auto& GetMethodUnion() {
- constexpr auto method = GetMethodUnionPointer<Service>(method_id);
+ constexpr auto method = GetMethodUnionPointer<Service>(kMethodId);
static_assert(method != nullptr,
"The selected function is not an RPC service method");
return *method;
@@ -51,9 +51,9 @@
template <typename Service>
static constexpr
typename decltype(GeneratedService<Service>::kMethods)::const_pointer
- GetMethodUnionPointer(uint32_t method_id) {
+ GetMethodUnionPointer(uint32_t kMethodId) {
for (size_t i = 0; i < GeneratedService<Service>::kMethodIds.size(); ++i) {
- if (GeneratedService<Service>::kMethodIds[i] == method_id) {
+ if (GeneratedService<Service>::kMethodIds[i] == kMethodId) {
return &GeneratedService<Service>::kMethods[i];
}
}
diff --git a/pw_rpc/public/pw_rpc/service.h b/pw_rpc/public/pw_rpc/service.h
index e9b0715..3884d02 100644
--- a/pw_rpc/public/pw_rpc/service.h
+++ b/pw_rpc/public/pw_rpc/service.h
@@ -34,13 +34,13 @@
uint32_t id() const { return id_; }
protected:
- template <typename T, size_t method_count>
- constexpr Service(uint32_t id, const std::array<T, method_count>& methods)
+ template <typename T, size_t kMethodCount>
+ constexpr Service(uint32_t id, const std::array<T, kMethodCount>& methods)
: id_(id),
methods_(methods.data()),
method_size_(sizeof(T)),
- method_count_(static_cast<uint16_t>(method_count)) {
- static_assert(method_count <= std::numeric_limits<uint16_t>::max());
+ method_count_(static_cast<uint16_t>(kMethodCount)) {
+ static_assert(kMethodCount <= std::numeric_limits<uint16_t>::max());
}
// For use by tests with only one method.
diff --git a/pw_rpc/pw_rpc_private/internal_test_utils.h b/pw_rpc/pw_rpc_private/internal_test_utils.h
index ff7290f..ef0b468 100644
--- a/pw_rpc/pw_rpc_private/internal_test_utils.h
+++ b/pw_rpc/pw_rpc_private/internal_test_utils.h
@@ -30,10 +30,10 @@
namespace pw::rpc {
-template <size_t output_buffer_size>
+template <size_t kOutputBufferSize>
class TestOutput : public ChannelOutput {
public:
- static constexpr size_t buffer_size() { return output_buffer_size; }
+ static constexpr size_t buffer_size() { return kOutputBufferSize; }
constexpr TestOutput(const char* name = "TestOutput")
: ChannelOutput(name), sent_data_{} {}
@@ -82,13 +82,13 @@
};
template <typename Service,
- size_t output_buffer_size = 128,
- uint32_t channel_id = 99,
- uint32_t service_id = 16>
+ size_t kOutputBufferSize = 128,
+ uint32_t kChannelId = 99,
+ uint32_t kServiceId = 16>
class ServerContextForTest {
public:
- static constexpr uint32_t kChannelId = channel_id;
- static constexpr uint32_t kServiceId = service_id;
+ static constexpr uint32_t channel_id() { return kChannelId; }
+ static constexpr uint32_t service_id() { return kServiceId; }
ServerContextForTest(const internal::Method& method)
: channel_(Channel::Create<kChannelId>(&output_)),
@@ -116,7 +116,7 @@
TestServer& server() { return static_cast<TestServer&>(server_); }
private:
- TestOutput<output_buffer_size> output_;
+ TestOutput<kOutputBufferSize> output_;
Channel channel_;
Server server_;
Service service_;
@@ -124,16 +124,16 @@
internal::ServerCall context_;
};
-template <size_t output_buffer_size = 128,
+template <size_t kOutputBufferSize = 128,
size_t input_buffer_size = 128,
- uint32_t channel_id = 99,
- uint32_t service_id = 16,
- uint32_t method_id = 111>
+ uint32_t kChannelId = 99,
+ uint32_t kServiceId = 16,
+ uint32_t kMethodId = 111>
class ClientContextForTest {
public:
- static constexpr uint32_t kChannelId = channel_id;
- static constexpr uint32_t kServiceId = service_id;
- static constexpr uint32_t kMethodId = method_id;
+ static constexpr uint32_t channel_id() { return kChannelId; }
+ static constexpr uint32_t service_id() { return kServiceId; }
+ static constexpr uint32_t method_id() { return kMethodId; }
ClientContextForTest()
: channel_(Channel::Create<kChannelId>(&output_)),
@@ -161,7 +161,7 @@
}
private:
- TestOutput<output_buffer_size> output_;
+ TestOutput<kOutputBufferSize> output_;
Channel channel_;
Client client_;
};
diff --git a/pw_rpc/raw/public/pw_rpc/raw_test_method_context.h b/pw_rpc/raw/public/pw_rpc/raw_test_method_context.h
index 9a4f399..321ea61 100644
--- a/pw_rpc/raw/public/pw_rpc/raw_test_method_context.h
+++ b/pw_rpc/raw/public/pw_rpc/raw_test_method_context.h
@@ -65,8 +65,8 @@
//
// PW_RAW_TEST_METHOD_CONTEXT takes two optional arguments:
//
-// size_t max_responses: maximum responses to store; ignored unless streaming
-// size_t output_size_bytes: buffer size; must be large enough for a packet
+// size_t kMaxResponse: maximum responses to store; ignored unless streaming
+// size_t kOutputSizeBytes: buffer size; must be large enough for a packet
//
// Example:
//
@@ -80,19 +80,19 @@
##__VA_ARGS__>
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses = 4,
- size_t output_size_bytes = 128>
+ uint32_t kMethodId,
+ size_t kMaxResponse = 4,
+ size_t kOutputSizeBytes = 128>
class RawTestMethodContext;
// Internal classes that implement RawTestMethodContext.
namespace internal::test::raw {
// A ChannelOutput implementation that stores the outgoing payloads and status.
-template <size_t output_size>
+template <size_t kOutputSize>
class MessageOutput final : public ChannelOutput {
public:
- using ResponseBuffer = std::array<std::byte, output_size>;
+ using ResponseBuffer = std::array<std::byte, kOutputSize>;
MessageOutput(Vector<ByteSpan>& responses,
Vector<ResponseBuffer>& buffers,
@@ -134,9 +134,9 @@
// Collects everything needed to invoke a particular RPC.
template <typename Service,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
struct InvocationContext {
template <typename... Args>
InvocationContext(Args&&... args)
@@ -147,26 +147,26 @@
call(static_cast<internal::Server&>(server),
static_cast<internal::Channel&>(channel),
service,
- MethodLookup::GetRawMethod<Service, method_id>()) {}
+ MethodLookup::GetRawMethod<Service, kMethodId>()) {}
- using ResponseBuffer = std::array<std::byte, output_size>;
+ using ResponseBuffer = std::array<std::byte, kOutputSize>;
- MessageOutput<output_size> output;
+ MessageOutput<kOutputSize> output;
rpc::Channel channel;
rpc::Server server;
Service service;
- Vector<ByteSpan, max_responses> responses;
- Vector<ResponseBuffer, max_responses> buffers;
- std::array<std::byte, output_size> packet_buffer = {};
+ Vector<ByteSpan, kMaxResponse> responses;
+ Vector<ResponseBuffer, kMaxResponse> buffers;
+ std::array<std::byte, kOutputSize> packet_buffer = {};
internal::ServerCall call;
};
// Method invocation context for a unary RPC. Returns the status in call() and
// provides the response through the response() method.
-template <typename Service, auto method, uint32_t method_id, size_t output_size>
+template <typename Service, auto method, uint32_t kMethodId, size_t kOutputSize>
class UnaryContext {
private:
- using Context = InvocationContext<Service, method_id, 1, output_size>;
+ using Context = InvocationContext<Service, kMethodId, 1, kOutputSize>;
Context ctx_;
public:
@@ -198,13 +198,13 @@
// Method invocation context for a server streaming RPC.
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
class ServerStreamingContext {
private:
using Context =
- InvocationContext<Service, method_id, max_responses, output_size>;
+ InvocationContext<Service, kMethodId, kMaxResponse, kOutputSize>;
Context ctx_;
public:
@@ -252,22 +252,22 @@
// RPC it is for.
template <typename Service,
auto method,
- uint32_t method_id,
- size_t responses,
- size_t output_size>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSize>
using Context = std::tuple_element_t<
static_cast<size_t>(MethodTraits<decltype(method)>::kType),
- std::tuple<UnaryContext<Service, method, method_id, output_size>,
+ std::tuple<UnaryContext<Service, method, kMethodId, kOutputSize>,
ServerStreamingContext<Service,
method,
- method_id,
- responses,
- output_size>
+ kMethodId,
+ kMaxResponse,
+ kOutputSize>
// TODO(hepler): Support client and bidi streaming
>>;
-template <size_t output_size>
-Status MessageOutput<output_size>::SendAndReleaseBuffer(
+template <size_t kOutputSize>
+Status MessageOutput<kOutputSize>::SendAndReleaseBuffer(
std::span<const std::byte> buffer) {
PW_ASSERT(!stream_ended_);
PW_ASSERT(buffer.data() == packet_buffer_.data());
@@ -306,25 +306,19 @@
template <typename Service,
auto method,
- uint32_t method_id,
- size_t max_responses,
- size_t output_size_bytes>
+ uint32_t kMethodId,
+ size_t kMaxResponse,
+ size_t kOutputSizeBytes>
class RawTestMethodContext
- : public internal::test::raw::Context<Service,
- method,
- method_id,
- max_responses,
- output_size_bytes> {
+ : public internal::test::raw::
+ Context<Service, method, kMethodId, kMaxResponse, kOutputSizeBytes> {
public:
// Forwards constructor arguments to the service class.
template <typename... ServiceArgs>
RawTestMethodContext(ServiceArgs&&... service_args)
- : internal::test::raw::Context<Service,
- method,
- method_id,
- max_responses,
- output_size_bytes>(
- std::forward<ServiceArgs>(service_args)...) {}
+ : internal::test::raw::
+ Context<Service, method, kMethodId, kMaxResponse, kOutputSizeBytes>(
+ std::forward<ServiceArgs>(service_args)...) {}
};
} // namespace pw::rpc
diff --git a/pw_rpc/raw/raw_method_test.cc b/pw_rpc/raw/raw_method_test.cc
index c8c9c44..fd60781 100644
--- a/pw_rpc/raw/raw_method_test.cc
+++ b/pw_rpc/raw/raw_method_test.cc
@@ -198,8 +198,8 @@
const internal::Packet& packet = context.output().sent_packet();
EXPECT_EQ(packet.type(), internal::PacketType::RESPONSE);
- EXPECT_EQ(packet.channel_id(), context.kChannelId);
- EXPECT_EQ(packet.service_id(), context.kServiceId);
+ EXPECT_EQ(packet.channel_id(), context.channel_id());
+ EXPECT_EQ(packet.service_id(), context.service_id());
EXPECT_EQ(packet.method_id(), context.get().method().id());
EXPECT_EQ(std::memcmp(packet.payload().data(), data.data(), data.size()), 0);
EXPECT_EQ(packet.status(), OkStatus());
@@ -216,8 +216,8 @@
const internal::Packet& packet = context.output().sent_packet();
EXPECT_EQ(packet.type(), internal::PacketType::RESPONSE);
- EXPECT_EQ(packet.channel_id(), context.kChannelId);
- EXPECT_EQ(packet.service_id(), context.kServiceId);
+ EXPECT_EQ(packet.channel_id(), context.channel_id());
+ EXPECT_EQ(packet.service_id(), context.service_id());
EXPECT_EQ(packet.method_id(), context.get().method().id());
EXPECT_EQ(std::memcmp(packet.payload().data(), data.data(), data.size()), 0);
EXPECT_EQ(packet.status(), OkStatus());
diff --git a/pw_stream/public/pw_stream/memory_stream.h b/pw_stream/public/pw_stream/memory_stream.h
index 299fb3a..948b1d3 100644
--- a/pw_stream/public/pw_stream/memory_stream.h
+++ b/pw_stream/public/pw_stream/memory_stream.h
@@ -48,13 +48,13 @@
size_t bytes_written_ = 0;
};
-template <size_t size_bytes>
+template <size_t kSizeBytes>
class MemoryWriterBuffer final : public MemoryWriter {
public:
MemoryWriterBuffer() : MemoryWriter(buffer_) {}
private:
- std::array<std::byte, size_bytes> buffer_;
+ std::array<std::byte, kSizeBytes> buffer_;
};
class MemoryReader final : public Reader {
diff --git a/pw_string/public/pw_string/string_builder.h b/pw_string/public/pw_string/string_builder.h
index 47db98f..c85e6be 100644
--- a/pw_string/public/pw_string/string_builder.h
+++ b/pw_string/public/pw_string/string_builder.h
@@ -269,7 +269,7 @@
// str.c_str(); // null terminated C string "The answer is 42."
// str.view(); // std::string_view of "The answer is 42."
//
-template <size_t size_bytes>
+template <size_t kSizeBytes>
class StringBuffer : public StringBuilder {
public:
StringBuffer() : StringBuilder(buffer_) {}
@@ -295,7 +295,7 @@
}
StringBuffer& operator=(const StringBuffer& other) {
- assign<size_bytes>(other);
+ assign<kSizeBytes>(other);
return *this;
}
@@ -309,9 +309,9 @@
}
// Returns the maximum length of the string, excluding the null terminator.
- static constexpr size_t max_size() { return size_bytes - 1; }
+ static constexpr size_t max_size() { return kSizeBytes - 1; }
- // Returns a StringBuffer<size_bytes>& instead of a generic StringBuilder& for
+ // Returns a StringBuffer<kSizeBytes>& instead of a generic StringBuilder& for
// append calls and stream-style operations.
template <typename... Args>
StringBuffer& append(Args&&... args) {
@@ -331,8 +331,8 @@
std::memcpy(buffer_, other.data(), other.size() + 1); // include the \0
}
- static_assert(size_bytes >= 1u, "StringBuffers must be at least 1 byte long");
- char buffer_[size_bytes];
+ static_assert(kSizeBytes >= 1u, "StringBuffers must be at least 1 byte long");
+ char buffer_[kSizeBytes];
};
namespace string_internal {
diff --git a/pw_tokenizer/global_handlers_test.cc b/pw_tokenizer/global_handlers_test.cc
index fc11456..bef914e 100644
--- a/pw_tokenizer/global_handlers_test.cc
+++ b/pw_tokenizer/global_handlers_test.cc
@@ -25,9 +25,9 @@
namespace {
// Constructs an array with the hashed string followed by the provided bytes.
-template <uint8_t... data, size_t size>
+template <uint8_t... data, size_t kSize>
constexpr auto ExpectedData(
- const char (&format)[size],
+ const char (&format)[kSize],
uint32_t token_mask = std::numeric_limits<uint32_t>::max()) {
const uint32_t value = Hash(format) & token_mask;
return std::array<uint8_t, sizeof(uint32_t) + sizeof...(data)>{
diff --git a/pw_tokenizer/hash_test.cc b/pw_tokenizer/hash_test.cc
index 3895b13..f6af14e 100644
--- a/pw_tokenizer/hash_test.cc
+++ b/pw_tokenizer/hash_test.cc
@@ -59,10 +59,10 @@
// Gets the size of the string, excluding the null terminator. A uint32_t is
// used instead of a size_t since the hash calculation requires a uint32_t.
-template <uint32_t size_with_null>
-constexpr uint32_t StringLength(const char (&)[size_with_null]) {
- static_assert(size_with_null > 0u);
- return size_with_null - 1; // subtract the null terminator
+template <uint32_t kSizeWithNull>
+constexpr uint32_t StringLength(const char (&)[kSizeWithNull]) {
+ static_assert(kSizeWithNull > 0u);
+ return kSizeWithNull - 1; // subtract the null terminator
}
TEST(Hashing, Runtime) PW_NO_SANITIZE("unsigned-integer-overflow") {
diff --git a/pw_tokenizer/public/pw_tokenizer/hash.h b/pw_tokenizer/public/pw_tokenizer/hash.h
index 2cd8cf3..f97d32f 100644
--- a/pw_tokenizer/public/pw_tokenizer/hash.h
+++ b/pw_tokenizer/public/pw_tokenizer/hash.h
@@ -69,10 +69,10 @@
// Take the string as an array to support either literals or character arrays,
// but not const char*.
-template <size_t size>
-constexpr uint32_t Hash(const char (&string)[size]) {
- static_assert(size > 0);
- return Hash(std::string_view(string, size - 1));
+template <size_t kSize>
+constexpr uint32_t Hash(const char (&string)[kSize]) {
+ static_assert(kSize > 0);
+ return Hash(std::string_view(string, kSize - 1));
}
// This hash function is equivalent to the C hashing macros. It hashses a string
@@ -93,12 +93,12 @@
}
// Character array version of PwTokenizer65599FixedLengthHash.
-template <size_t size>
+template <size_t kSize>
constexpr uint32_t PwTokenizer65599FixedLengthHash(
- const char (&string)[size],
+ const char (&string)[kSize],
size_t hash_length = PW_TOKENIZER_CFG_C_HASH_LENGTH) {
- static_assert(size > 0);
- return PwTokenizer65599FixedLengthHash(std::string_view(string, size - 1),
+ static_assert(kSize > 0);
+ return PwTokenizer65599FixedLengthHash(std::string_view(string, kSize - 1),
hash_length);
}
diff --git a/pw_tokenizer/public/pw_tokenizer/internal/tokenize_string.h b/pw_tokenizer/public/pw_tokenizer/internal/tokenize_string.h
index 783b84d..07591c0 100644
--- a/pw_tokenizer/public/pw_tokenizer/internal/tokenize_string.h
+++ b/pw_tokenizer/public/pw_tokenizer/internal/tokenize_string.h
@@ -39,29 +39,29 @@
// The C++ tokenzied string entry supports both string literals and char arrays,
// such as __func__.
-template <uint32_t domain_size, uint32_t string_size>
+template <uint32_t kDomainSize, uint32_t kStringSize>
PW_PACKED(class)
Entry {
public:
constexpr Entry(uint32_t token,
- const char(&domain)[domain_size],
- const char(&string)[string_size])
+ const char(&domain)[kDomainSize],
+ const char(&string)[kStringSize])
: magic_(_PW_TOKENIZER_ENTRY_MAGIC),
token_(token),
- domain_size_(domain_size),
- string_size_(string_size),
+ domain_size_(kDomainSize),
+ string_size_(kStringSize),
domain_(std::to_array(domain)),
string_(std::to_array(string)) {}
private:
- static_assert(string_size > 0u && domain_size > 0u);
+ static_assert(kStringSize > 0u && kDomainSize > 0u);
uint32_t magic_;
uint32_t token_;
uint32_t domain_size_;
uint32_t string_size_;
- std::array<char, domain_size> domain_;
- std::array<char, string_size> string_;
+ std::array<char, kDomainSize> domain_;
+ std::array<char, kStringSize> string_;
};
} // namespace internal
diff --git a/pw_tokenizer/tokenize_test.cc b/pw_tokenizer/tokenize_test.cc
index 9849a54..393d8f7 100644
--- a/pw_tokenizer/tokenize_test.cc
+++ b/pw_tokenizer/tokenize_test.cc
@@ -29,17 +29,17 @@
namespace {
// Constructs an array with the hashed string followed by the provided bytes.
-template <uint8_t... data, size_t size>
+template <uint8_t... kData, size_t kSize>
constexpr auto ExpectedData(
- const char (&format)[size],
+ const char (&format)[kSize],
uint32_t token_mask = std::numeric_limits<uint32_t>::max()) {
const uint32_t value = Hash(format) & token_mask;
- return std::array<uint8_t, sizeof(uint32_t) + sizeof...(data)>{
+ return std::array<uint8_t, sizeof(uint32_t) + sizeof...(kData)>{
static_cast<uint8_t>(value & 0xff),
static_cast<uint8_t>(value >> 8 & 0xff),
static_cast<uint8_t>(value >> 16 & 0xff),
static_cast<uint8_t>(value >> 24 & 0xff),
- data...};
+ kData...};
}
TEST(TokenizeString, EmptyString_IsZero) {