misc: Update non-type template parameter style
Switch non-type template parameters to kConstant style in accordance
with https://pigweed.dev/docs/style_guide.html.
Change-Id: Ib52692bf4bcb4254df23ea6ba887f6f5948586a0
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/56829
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/docs/style_guide.rst b/docs/style_guide.rst
index 4b4c1d9..933f173 100644
--- a/docs/style_guide.rst
+++ b/docs/style_guide.rst
@@ -260,10 +260,6 @@
duration of the program, the naming convention is ``kCamelCase``, and so
that is the style we use in Pigweed.
- **Note:** At time of writing much of Pigweed incorrectly follows the
- ``snake_case`` naming for non-type template arguments. This is a bug that
- will be fixed eventually.
-
**C code**
In general, C symbols should be prefixed with the module name. If the symbol is
not associated with a module, use just ``pw`` as the module name. Facade
diff --git a/pw_containers/public/pw_containers/vector.h b/pw_containers/public/pw_containers/vector.h
index 1d05fd1..3438074 100644
--- a/pw_containers/public/pw_containers/vector.h
+++ b/pw_containers/public/pw_containers/vector.h
@@ -65,7 +65,7 @@
// the maximum size in a variable. This allows Vectors to be used without having
// to know their maximum size at compile time. It also keeps code size small
// since function implementations are shared for all maximum sizes.
-template <typename T, size_t max_size = vector_impl::kGeneric>
+template <typename T, size_t kMaxSize = vector_impl::kGeneric>
class Vector : public Vector<T, vector_impl::kGeneric> {
public:
using typename Vector<T, vector_impl::kGeneric>::value_type;
@@ -81,37 +81,37 @@
using typename Vector<T, vector_impl::kGeneric>::const_reverse_iterator;
// Construct
- Vector() noexcept : Vector<T, vector_impl::kGeneric>(max_size) {}
+ Vector() noexcept : Vector<T, vector_impl::kGeneric>(kMaxSize) {}
Vector(size_type count, const T& value)
- : Vector<T, vector_impl::kGeneric>(max_size, count, value) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, count, value) {}
explicit Vector(size_type count)
- : Vector<T, vector_impl::kGeneric>(max_size, count, T()) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, count, T()) {}
template <
typename Iterator,
typename...,
typename = std::enable_if_t<vector_impl::IsIterator<Iterator>::value>>
Vector(Iterator first, Iterator last)
- : Vector<T, vector_impl::kGeneric>(max_size, first, last) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, first, last) {}
Vector(const Vector& other)
- : Vector<T, vector_impl::kGeneric>(max_size, other) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, other) {}
template <size_t kOtherMaxSize>
Vector(const Vector<T, kOtherMaxSize>& other)
- : Vector<T, vector_impl::kGeneric>(max_size, other) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, other) {}
Vector(Vector&& other) noexcept
- : Vector<T, vector_impl::kGeneric>(max_size, std::move(other)) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, std::move(other)) {}
template <size_t kOtherMaxSize>
Vector(Vector<T, kOtherMaxSize>&& other) noexcept
- : Vector<T, vector_impl::kGeneric>(max_size, std::move(other)) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, std::move(other)) {}
Vector(std::initializer_list<T> list)
- : Vector<T, vector_impl::kGeneric>(max_size, list) {}
+ : Vector<T, vector_impl::kGeneric>(kMaxSize, list) {}
Vector& operator=(const Vector& other) {
Vector<T>::assign(other.begin(), other.end());
@@ -145,7 +145,7 @@
private:
friend class Vector<T, vector_impl::kGeneric>;
- static_assert(max_size <= std::numeric_limits<size_type>::max());
+ static_assert(kMaxSize <= std::numeric_limits<size_type>::max());
// Provides access to the underlying array as an array of T.
#ifdef __cpp_lib_launder
@@ -166,7 +166,7 @@
// The alignas specifier is required ensure that a zero-length array is
// aligned the same as an array with elements.
alignas(T) std::array<std::aligned_storage_t<sizeof(T), alignof(T)>,
- max_size> array_;
+ kMaxSize> array_;
};
// Defines the generic-sized Vector<T> specialization, which serves as the base
@@ -196,7 +196,7 @@
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
// A vector without an explicit maximum size (Vector<T>) cannot be constructed
- // directly. Instead, construct a Vector<T, max_size>. Vectors of any max size
+ // directly. Instead, construct a Vector<T, kMaxSize>. Vectors of any max size
// can be used through a Vector<T> pointer or reference.
// Assign
diff --git a/pw_i2c/public/pw_i2c/initiator_mock.h b/pw_i2c/public/pw_i2c/initiator_mock.h
index fa37cd2..789a38c 100644
--- a/pw_i2c/public/pw_i2c/initiator_mock.h
+++ b/pw_i2c/public/pw_i2c/initiator_mock.h
@@ -140,9 +140,9 @@
};
// Makes a new i2c transactions list.
-template <size_t size>
-constexpr std::array<Transaction, size> MakeExpectedTransactionArray(
- const Transaction (&transactions)[size]) {
+template <size_t kSize>
+constexpr std::array<Transaction, kSize> MakeExpectedTransactionArray(
+ const Transaction (&transactions)[kSize]) {
return std::to_array(transactions);
}
diff --git a/pw_kvs/entry_test.cc b/pw_kvs/entry_test.cc
index f9496e3..76def54 100644
--- a/pw_kvs/entry_test.cc
+++ b/pw_kvs/entry_test.cc
@@ -410,10 +410,10 @@
constexpr EntryFormat kFormatWithSum{kMagicWithSum, &sum_checksum};
constexpr internal::EntryFormats kFormatsWithSum(kFormatWithSum);
-template <size_t alignment>
+template <size_t kAlignment>
constexpr auto MakeNewFormatWithSumEntry() {
- constexpr uint8_t alignment_units = (alignment + 15) / 16 - 1;
- constexpr size_t size = AlignUp(kEntryWithoutPadding1.size(), alignment);
+ constexpr uint8_t alignment_units = (kAlignment + 15) / 16 - 1;
+ constexpr size_t size = AlignUp(kEntryWithoutPadding1.size(), kAlignment);
constexpr uint32_t checksum =
ByteSum(bytes::Concat(kFormatWithSum.magic)) + 0 /* checksum */ +
@@ -428,7 +428,7 @@
uint8_t(kKey1.size()), // key length
uint16_t(kValue1.size()), // value size
kTransactionId1 + 1); // transaction ID
- constexpr size_t padding = Padding(kEntryWithoutPadding1.size(), alignment);
+ constexpr size_t padding = Padding(kEntryWithoutPadding1.size(), kAlignment);
return bytes::Concat(
kNewHeader1, kKey1, kValue1, bytes::Initialized<padding>(0));
}
diff --git a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/array.h b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/array.h
index 441cd79..d559a54 100644
--- a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/array.h
+++ b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/array.h
@@ -26,28 +26,28 @@
namespace impl {
-template <typename T, size_t size, size_t... indices>
-constexpr array<remove_cv_t<T>, size> CopyArray(const T (&values)[size],
- index_sequence<indices...>) {
- return {{values[indices]...}};
+template <typename T, size_t kSize, size_t... kIndices>
+constexpr array<remove_cv_t<T>, kSize> CopyArray(const T (&values)[kSize],
+ index_sequence<kIndices...>) {
+ return {{values[kIndices]...}};
}
-template <typename T, size_t size, size_t... indices>
-constexpr array<remove_cv_t<T>, size> MoveArray(T(&&values)[size],
- index_sequence<indices...>) {
- return {{move(values[indices])...}};
+template <typename T, size_t kSize, size_t... kIndices>
+constexpr array<remove_cv_t<T>, kSize> MoveArray(T(&&values)[kSize],
+ index_sequence<kIndices...>) {
+ return {{move(values[kIndices])...}};
}
} // namespace impl
-template <typename T, size_t size>
-constexpr array<remove_cv_t<T>, size> to_array(T (&values)[size]) {
- return impl::CopyArray(values, make_index_sequence<size>{});
+template <typename T, size_t kSize>
+constexpr array<remove_cv_t<T>, kSize> to_array(T (&values)[kSize]) {
+ return impl::CopyArray(values, make_index_sequence<kSize>{});
}
-template <typename T, size_t size>
-constexpr array<remove_cv_t<T>, size> to_array(T(&&values)[size]) {
- return impl::MoveArray(move(values), make_index_sequence<size>{});
+template <typename T, size_t kSize>
+constexpr array<remove_cv_t<T>, kSize> to_array(T(&&values)[kSize]) {
+ return impl::MoveArray(move(values), make_index_sequence<kSize>{});
}
_PW_POLYFILL_END_NAMESPACE_STD
diff --git a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/type_traits.h b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/type_traits.h
index 1d9b9b2..f13130e 100644
--- a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/type_traits.h
+++ b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/type_traits.h
@@ -24,20 +24,20 @@
#ifndef __cpp_lib_transformation_trait_aliases
#define __cpp_lib_transformation_trait_aliases 201304L
-template <decltype(sizeof(int)) Len, decltype(sizeof(int)) Align>
-using aligned_storage_t = typename aligned_storage<Len, Align>::type;
+template <decltype(sizeof(int)) kLen, decltype(sizeof(int)) kAlign>
+using aligned_storage_t = typename aligned_storage<kLen, kAlign>::type;
template <typename... T>
using common_type_t = typename common_type<T...>::type;
-template <bool B, typename T, typename F>
-using conditional_t = typename conditional<B, T, F>::type;
+template <bool kBool, typename T, typename F>
+using conditional_t = typename conditional<kBool, T, F>::type;
template <typename T>
using decay_t = typename decay<T>::type;
-template <bool B, typename T = void>
-using enable_if_t = typename enable_if<B, T>::type;
+template <bool kBool, typename T = void>
+using enable_if_t = typename enable_if<kBool, T>::type;
template <typename T>
using make_signed_t = typename make_signed<T>::type;
@@ -67,14 +67,14 @@
#ifndef __cpp_lib_bool_constant
#define __cpp_lib_bool_constant 201505L
-template <bool value>
-using bool_constant = integral_constant<bool, value>;
+template <bool kValue>
+using bool_constant = integral_constant<bool, kValue>;
#endif // __cpp_lib_bool_constant
#ifndef __cpp_lib_logical_traits
#define __cpp_lib_logical_traits 201510L
-template <typename value>
-struct negation : bool_constant<!bool(value::value)> {};
+template <typename Value>
+struct negation : bool_constant<!bool(Value::value)> {};
template <typename...>
struct conjunction : std::true_type {};
diff --git a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/utility.h b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/utility.h
index 026068e..f81f948 100644
--- a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/utility.h
+++ b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/utility.h
@@ -22,32 +22,32 @@
_PW_POLYFILL_BEGIN_NAMESPACE_STD
-template <typename T, T... sequence>
+template <typename T, T... kSequence>
struct integer_sequence {
- static constexpr size_t size() noexcept { return sizeof...(sequence); }
+ static constexpr size_t size() noexcept { return sizeof...(kSequence); }
};
namespace impl {
// In the absence of a compiler builtin for this, have MakeSequence expand
// recursively to enumerate all indices up to count.
-template <size_t count, typename T, T... sequence>
-struct MakeSequence : MakeSequence<count - 1, T, count - 1, sequence...> {};
+template <size_t kCount, typename T, T... kSequence>
+struct MakeSequence : MakeSequence<kCount - 1, T, kCount - 1, kSequence...> {};
-template <typename T, T... sequence>
-struct MakeSequence<0, T, sequence...> : std::integer_sequence<T, sequence...> {
-};
+template <typename T, T... kSequence>
+struct MakeSequence<0, T, kSequence...>
+ : std::integer_sequence<T, kSequence...> {};
} // namespace impl
-template <size_t... sequence>
-using index_sequence = integer_sequence<size_t, sequence...>;
+template <size_t... kSequence>
+using index_sequence = integer_sequence<size_t, kSequence...>;
-template <typename T, T count>
-using make_integer_sequence = impl::MakeSequence<count, T>;
+template <typename T, T kCount>
+using make_integer_sequence = impl::MakeSequence<kCount, T>;
-template <size_t count>
-using make_index_sequence = make_integer_sequence<size_t, count>;
+template <size_t kCount>
+using make_index_sequence = make_integer_sequence<size_t, kCount>;
template <typename... T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;
diff --git a/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method.h b/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method.h
index 415ba75..a53caa2 100644
--- a/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method.h
+++ b/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method.h
@@ -130,11 +130,11 @@
using Service = T;
};
-template <auto method>
-using Request = typename MethodTraits<decltype(method)>::Request;
+template <auto kMethod>
+using Request = typename MethodTraits<decltype(kMethod)>::Request;
-template <auto method>
-using Response = typename MethodTraits<decltype(method)>::Response;
+template <auto kMethod>
+using Response = typename MethodTraits<decltype(kMethod)>::Response;
// The NanopbMethod class invokes user-defined service methods. When a
// pw::rpc::Server receives an RPC request packet, it looks up the matching
@@ -148,15 +148,15 @@
// structs.
class NanopbMethod : public Method {
public:
- template <auto method, typename RequestType, typename ResponseType>
+ template <auto kMethod, typename RequestType, typename ResponseType>
static constexpr bool matches() {
- return std::is_same_v<MethodImplementation<method>, NanopbMethod> &&
- std::is_same_v<RequestType, Request<method>> &&
- std::is_same_v<ResponseType, Response<method>>;
+ return std::is_same_v<MethodImplementation<kMethod>, NanopbMethod> &&
+ std::is_same_v<RequestType, Request<kMethod>> &&
+ std::is_same_v<ResponseType, Response<kMethod>>;
}
// Creates a NanopbMethod for a synchronous unary RPC.
- template <auto method>
+ template <auto kMethod>
static constexpr NanopbMethod Unary(uint32_t id,
NanopbMessageDescriptor request,
NanopbMessageDescriptor response) {
@@ -168,22 +168,22 @@
// this wrapper, elminating any overhead.
constexpr SynchronousUnaryFunction wrapper =
[](ServerCall& call, const void* req, void* resp) {
- return CallMethodImplFunction<method>(
+ return CallMethodImplFunction<kMethod>(
call,
- *static_cast<const Request<method>*>(req),
- *static_cast<Response<method>*>(resp));
+ *static_cast<const Request<kMethod>*>(req),
+ *static_cast<Response<kMethod>*>(resp));
};
return NanopbMethod(
id,
- SynchronousUnaryInvoker<AllocateSpaceFor<Request<method>>(),
- AllocateSpaceFor<Response<method>>()>,
+ SynchronousUnaryInvoker<AllocateSpaceFor<Request<kMethod>>(),
+ AllocateSpaceFor<Response<kMethod>>()>,
Function{.synchronous_unary = wrapper},
request,
response);
}
// Creates a NanopbMethod for a server-streaming RPC.
- template <auto method>
+ template <auto kMethod>
static constexpr NanopbMethod ServerStreaming(
uint32_t id,
NanopbMessageDescriptor request,
@@ -194,21 +194,21 @@
// the Function union, defined below.
constexpr UnaryRequestFunction wrapper =
[](ServerCall& call, const void* req, GenericNanopbResponder& writer) {
- return CallMethodImplFunction<method>(
+ return CallMethodImplFunction<kMethod>(
call,
- *static_cast<const Request<method>*>(req),
- static_cast<NanopbServerWriter<Response<method>>&>(writer));
+ *static_cast<const Request<kMethod>*>(req),
+ static_cast<NanopbServerWriter<Response<kMethod>>&>(writer));
};
return NanopbMethod(
id,
- UnaryRequestInvoker<AllocateSpaceFor<Request<method>>()>,
+ UnaryRequestInvoker<AllocateSpaceFor<Request<kMethod>>()>,
Function{.unary_request = wrapper},
request,
response);
}
// Creates a NanopbMethod for a client-streaming RPC.
- template <auto method>
+ template <auto kMethod>
static constexpr NanopbMethod ClientStreaming(
uint32_t id,
NanopbMessageDescriptor request,
@@ -216,34 +216,34 @@
constexpr StreamRequestFunction wrapper = [](ServerCall& call,
GenericNanopbResponder&
reader) {
- return CallMethodImplFunction<method>(
+ return CallMethodImplFunction<kMethod>(
call,
- static_cast<NanopbServerReader<Request<method>, Response<method>>&>(
+ static_cast<NanopbServerReader<Request<kMethod>, Response<kMethod>>&>(
reader));
};
return NanopbMethod(id,
- StreamRequestInvoker<Request<method>>,
+ StreamRequestInvoker<Request<kMethod>>,
Function{.stream_request = wrapper},
request,
response);
}
// Creates a NanopbMethod for a bidirectional-streaming RPC.
- template <auto method>
+ template <auto kMethod>
static constexpr NanopbMethod BidirectionalStreaming(
uint32_t id,
NanopbMessageDescriptor request,
NanopbMessageDescriptor response) {
constexpr StreamRequestFunction wrapper =
[](ServerCall& call, GenericNanopbResponder& reader_writer) {
- return CallMethodImplFunction<method>(
+ return CallMethodImplFunction<kMethod>(
call,
- static_cast<
- NanopbServerReaderWriter<Request<method>, Response<method>>&>(
+ static_cast<NanopbServerReaderWriter<Request<kMethod>,
+ Response<kMethod>>&>(
reader_writer));
};
return NanopbMethod(id,
- StreamRequestInvoker<Request<method>>,
+ StreamRequestInvoker<Request<kMethod>>,
Function{.stream_request = wrapper},
request,
response);
diff --git a/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method_union.h b/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method_union.h
index 12bfe1d..71e1d90 100644
--- a/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method_union.h
+++ b/pw_rpc/nanopb/public/pw_rpc/nanopb/internal/method_union.h
@@ -42,18 +42,18 @@
// Returns either a raw or nanopb method object, depending on the implemented
// function's signature.
-template <auto method, MethodType type, typename Request, typename Response>
+template <auto kMethod, MethodType kType, typename Request, typename Response>
constexpr auto GetNanopbOrRawMethodFor(
uint32_t id,
[[maybe_unused]] NanopbMessageDescriptor request_fields,
[[maybe_unused]] NanopbMessageDescriptor response_fields) {
- if constexpr (RawMethod::matches<method>()) {
- return GetMethodFor<method, RawMethod, type>(id);
- } else if constexpr (NanopbMethod::matches<method, Request, Response>()) {
- return GetMethodFor<method, NanopbMethod, type>(
+ if constexpr (RawMethod::matches<kMethod>()) {
+ return GetMethodFor<kMethod, RawMethod, kType>(id);
+ } else if constexpr (NanopbMethod::matches<kMethod, Request, Response>()) {
+ return GetMethodFor<kMethod, NanopbMethod, kType>(
id, request_fields, response_fields);
} else {
- return InvalidMethod<method, type, RawMethod>(id);
+ return InvalidMethod<kMethod, kType, RawMethod>(id);
}
};
diff --git a/pw_rpc/nanopb/pw_rpc_nanopb_private/internal_test_utils.h b/pw_rpc/nanopb/pw_rpc_nanopb_private/internal_test_utils.h
index 5312463..40efe85 100644
--- a/pw_rpc/nanopb/pw_rpc_nanopb_private/internal_test_utils.h
+++ b/pw_rpc/nanopb/pw_rpc_nanopb_private/internal_test_utils.h
@@ -37,11 +37,11 @@
::pw::rpc::internal::EncodeProtobuf<proto, proto##_fields>( \
proto{__VA_ARGS__}, _pb_buffer_##unique)
-template <typename T, auto fields>
+template <typename T, auto kFields>
std::span<const std::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));
+ EXPECT_TRUE(pb_encode(&output, kFields, &protobuf));
return std::as_bytes(buffer.first(output.bytes_written));
}
@@ -53,10 +53,10 @@
buffer.size()), \
result);
-template <typename T, auto fields>
+template <typename T, auto kFields>
void DecodeProtobuf(std::span<const pb_byte_t> buffer, T& protobuf) {
auto input = pb_istream_from_buffer(buffer.data(), buffer.size());
- EXPECT_TRUE(pb_decode(&input, fields, &protobuf));
+ EXPECT_TRUE(pb_decode(&input, kFields, &protobuf));
}
} // namespace pw::rpc::internal
diff --git a/pw_rpc/public/pw_rpc/internal/method.h b/pw_rpc/public/pw_rpc/internal/method.h
index 15535eb..92a9f25 100644
--- a/pw_rpc/public/pw_rpc/internal/method.h
+++ b/pw_rpc/public/pw_rpc/internal/method.h
@@ -28,15 +28,15 @@
/*
class MethodImpl : public Method {
// True if the provided function signature is valid for this method impl.
- template <auto method>
+ template <auto kMethod>
static constexpr bool matches();
// Creates a unary method instance.
- template <auto method>
+ template <auto kMethod>
static constexpr MethodImpl Unary(uint32_t id, [optional args]);
// Creates a server streaming method instance.
- template <auto method>
+ template <auto kMethod>
static constexpr MethodImpl ServerStreaming(uint32_t id, [optional args]);
// Creates a client streaming method instance.
@@ -101,22 +101,22 @@
using Response = void;
};
-template <auto method>
+template <auto kMethod>
using MethodImplementation =
- typename MethodTraits<decltype(method)>::Implementation;
+ typename MethodTraits<decltype(kMethod)>::Implementation;
// Function that calls a user-defined method implementation function from a
// ServerCall object.
-template <auto method, typename... Args>
+template <auto kMethod, typename... Args>
constexpr auto CallMethodImplFunction(ServerCall& call, Args&&... args) {
// If the method impl is a member function, deduce the type of the
// user-defined service from it, then call the method on the service.
- if constexpr (std::is_member_function_pointer_v<decltype(method)>) {
- return (static_cast<typename MethodTraits<decltype(method)>::Service&>(
+ if constexpr (std::is_member_function_pointer_v<decltype(kMethod)>) {
+ return (static_cast<typename MethodTraits<decltype(kMethod)>::Service&>(
call.service()).*
- method)(call.context(), std::forward<Args>(args)...);
+ kMethod)(call.context(), std::forward<Args>(args)...);
} else {
- return method(call.context(), std::forward<Args>(args)...);
+ return kMethod(call.context(), std::forward<Args>(args)...);
}
}
diff --git a/pw_rpc/public/pw_rpc/internal/method_union.h b/pw_rpc/public/pw_rpc/internal/method_union.h
index 154667d..4a7f4ca 100644
--- a/pw_rpc/public/pw_rpc/internal/method_union.h
+++ b/pw_rpc/public/pw_rpc/internal/method_union.h
@@ -72,32 +72,32 @@
// This function is called if an RPC method implementation's signature is not
// correct. It triggers a static_assert with an error message tailored to the
// expected RPC type.
-template <auto method,
- MethodType expected,
- typename InvalidImpl = MethodImplementation<method>>
+template <auto kMethod,
+ MethodType kExpected,
+ typename InvalidImpl = MethodImplementation<kMethod>>
constexpr auto InvalidMethod(uint32_t) {
- if constexpr (expected == MethodType::kUnary) {
+ if constexpr (kExpected == MethodType::kUnary) {
static_assert(
- kCheckMethodSignature<decltype(method)>,
+ kCheckMethodSignature<decltype(kMethod)>,
_PW_RPC_FUNCTION_ERROR("unary", "Status", "Request, Response"));
- } else if constexpr (expected == MethodType::kServerStreaming) {
+ } else if constexpr (kExpected == MethodType::kServerStreaming) {
static_assert(
- kCheckMethodSignature<decltype(method)>,
+ kCheckMethodSignature<decltype(kMethod)>,
_PW_RPC_FUNCTION_ERROR(
"server streaming", "void", "Request, ServerWriter<Response>&"));
- } else if constexpr (expected == MethodType::kClientStreaming) {
+ } else if constexpr (kExpected == MethodType::kClientStreaming) {
static_assert(
- kCheckMethodSignature<decltype(method)>,
+ kCheckMethodSignature<decltype(kMethod)>,
_PW_RPC_FUNCTION_ERROR(
"client streaming", "Status", "ServerReader<Request>&, Response"));
- } else if constexpr (expected == MethodType::kBidirectionalStreaming) {
- static_assert(kCheckMethodSignature<decltype(method)>,
+ } else if constexpr (kExpected == MethodType::kBidirectionalStreaming) {
+ static_assert(kCheckMethodSignature<decltype(kMethod)>,
_PW_RPC_FUNCTION_ERROR(
"bidirectional streaming",
"void",
"ServerReader<Request>&, ServerWriter<Response>&"));
} else {
- static_assert(kCheckMethodSignature<decltype(method)>,
+ static_assert(kCheckMethodSignature<decltype(kMethod)>,
"Unsupported MethodType");
}
return InvalidImpl::Invalid();
@@ -108,20 +108,20 @@
// This function checks the type of the method and calls the appropriate
// function to create the method instance.
-template <auto method, typename MethodImpl, MethodType type, typename... Args>
+template <auto kMethod, typename MethodImpl, MethodType kType, typename... Args>
constexpr auto GetMethodFor(uint32_t id, Args&&... args) {
- if constexpr (MethodTraits<decltype(method)>::kType != type) {
- return InvalidMethod<method, type>(id);
- } else if constexpr (type == MethodType::kUnary) {
- return MethodImpl::template Unary<method>(id, std::forward<Args>(args)...);
- } else if constexpr (type == MethodType::kServerStreaming) {
- return MethodImpl::template ServerStreaming<method>(
+ if constexpr (MethodTraits<decltype(kMethod)>::kType != kType) {
+ return InvalidMethod<kMethod, kType>(id);
+ } else if constexpr (kType == MethodType::kUnary) {
+ return MethodImpl::template Unary<kMethod>(id, std::forward<Args>(args)...);
+ } else if constexpr (kType == MethodType::kServerStreaming) {
+ return MethodImpl::template ServerStreaming<kMethod>(
id, std::forward<Args>(args)...);
- } else if constexpr (type == MethodType::kClientStreaming) {
- return MethodImpl::template ClientStreaming<method>(
+ } else if constexpr (kType == MethodType::kClientStreaming) {
+ return MethodImpl::template ClientStreaming<kMethod>(
id, std::forward<Args>(args)...);
- } else if constexpr (type == MethodType::kBidirectionalStreaming) {
- return MethodImpl::template BidirectionalStreaming<method>(
+ } else if constexpr (kType == MethodType::kBidirectionalStreaming) {
+ return MethodImpl::template BidirectionalStreaming<kMethod>(
id, std::forward<Args>(args)...);
} else {
static_assert(kCheckMethodSignature<MethodImpl>, "Invalid MethodType");
diff --git a/pw_rpc/raw/public/pw_rpc/raw/internal/method.h b/pw_rpc/raw/public/pw_rpc/raw/internal/method.h
index ddc9952..67706f7 100644
--- a/pw_rpc/raw/public/pw_rpc/raw/internal/method.h
+++ b/pw_rpc/raw/public/pw_rpc/raw/internal/method.h
@@ -30,47 +30,47 @@
// responses up to a channel's MTU.
class RawMethod : public Method {
public:
- template <auto method>
+ template <auto kMethod>
static constexpr bool matches() {
- return std::is_same_v<MethodImplementation<method>, RawMethod>;
+ return std::is_same_v<MethodImplementation<kMethod>, RawMethod>;
}
- template <auto method>
+ template <auto kMethod>
static constexpr RawMethod Unary(uint32_t id) {
constexpr SynchronousUnaryFunction wrapper =
[](ServerCall& call, ConstByteSpan req, ByteSpan res) {
- return CallMethodImplFunction<method>(call, req, res);
+ return CallMethodImplFunction<kMethod>(call, req, res);
};
return RawMethod(
id, SynchronousUnaryInvoker, Function{.synchronous_unary = wrapper});
}
- template <auto method>
+ template <auto kMethod>
static constexpr RawMethod ServerStreaming(uint32_t id) {
constexpr UnaryRequestFunction wrapper =
[](ServerCall& call, ConstByteSpan request, RawServerWriter& writer) {
- return CallMethodImplFunction<method>(call, request, writer);
+ return CallMethodImplFunction<kMethod>(call, request, writer);
};
return RawMethod(
id, UnaryRequestInvoker, Function{.unary_request = wrapper});
}
- template <auto method>
+ template <auto kMethod>
static constexpr RawMethod ClientStreaming(uint32_t id) {
constexpr StreamRequestFunction wrapper =
[](ServerCall& call, RawServerReaderWriter& reader) {
- return CallMethodImplFunction<method>(
+ return CallMethodImplFunction<kMethod>(
call, static_cast<RawServerReader&>(reader));
};
return RawMethod(
id, StreamRequestInvoker, Function{.stream_request = wrapper});
}
- template <auto method>
+ template <auto kMethod>
static constexpr RawMethod BidirectionalStreaming(uint32_t id) {
constexpr StreamRequestFunction wrapper =
[](ServerCall& call, RawServerReaderWriter& reader_writer) {
- return CallMethodImplFunction<method>(call, reader_writer);
+ return CallMethodImplFunction<kMethod>(call, reader_writer);
};
return RawMethod(
id, StreamRequestInvoker, Function{.stream_request = wrapper});
diff --git a/pw_rpc/raw/public/pw_rpc/raw/internal/method_union.h b/pw_rpc/raw/public/pw_rpc/raw/internal/method_union.h
index a93d6fa..d3eb2bc 100644
--- a/pw_rpc/raw/public/pw_rpc/raw/internal/method_union.h
+++ b/pw_rpc/raw/public/pw_rpc/raw/internal/method_union.h
@@ -38,12 +38,12 @@
// Deduces the type of an implemented service method from its signature, and
// returns the appropriate MethodUnion object to invoke it.
-template <auto method, MethodType type>
+template <auto kMethod, MethodType kType>
constexpr RawMethod GetRawMethodFor(uint32_t id) {
- if constexpr (RawMethod::matches<method>()) {
- return GetMethodFor<method, RawMethod, type>(id);
+ if constexpr (RawMethod::matches<kMethod>()) {
+ return GetMethodFor<kMethod, RawMethod, kType>(id);
} else {
- return InvalidMethod<method, type, RawMethod>(id);
+ return InvalidMethod<kMethod, kType, RawMethod>(id);
}
};