Skip to content

Commit 6218313

Browse files
committed
feat grpc: use utils::StringLiteral for gRPC service and method names
Tests: протестировано CI commit_hash:f4dbd3a19d20c4a99175ec34a7c52033f803277c
1 parent b2f7e62 commit 6218313

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

grpc/include/userver/ugrpc/impl/static_service_metadata.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string_view>
55

66
#include <userver/utils/span.hpp>
7+
#include <userver/utils/string_literal.hpp>
78

89
#include <userver/ugrpc/impl/rpc_type.hpp>
910

@@ -13,13 +14,13 @@ namespace ugrpc::impl {
1314

1415
/// Descriptor of an RPC method
1516
struct MethodDescriptor final {
16-
std::string_view method_full_name;
17-
RpcType method_type;
17+
utils::StringLiteral method_full_name;
18+
RpcType method_type{RpcType::kUnary};
1819
};
1920

2021
/// Per-gRPC-service statically generated data
2122
struct StaticServiceMetadata final {
22-
std::string_view service_full_name;
23+
utils::StringLiteral service_full_name;
2324
utils::span<const MethodDescriptor> methods;
2425
};
2526

@@ -32,13 +33,14 @@ constexpr std::size_t GetMethodsCount(const StaticServiceMetadata& metadata) noe
3233
return metadata.methods.size();
3334
}
3435

35-
constexpr std::string_view GetMethodFullName(const StaticServiceMetadata& metadata, std::size_t method_id) {
36+
constexpr utils::StringLiteral GetMethodFullName(const StaticServiceMetadata& metadata, std::size_t method_id) {
3637
return metadata.methods[method_id].method_full_name;
3738
}
3839

39-
constexpr std::string_view GetMethodName(const StaticServiceMetadata& metadata, std::size_t method_id) {
40-
auto method_full_name = GetMethodFullName(metadata, method_id);
41-
return method_full_name.substr(metadata.service_full_name.size() + 1);
40+
constexpr utils::StringLiteral GetMethodName(const StaticServiceMetadata& metadata, std::size_t method_id) {
41+
auto result = ugrpc::impl::GetMethodFullName(metadata, method_id);
42+
result.remove_prefix(metadata.service_full_name.size() + 1);
43+
return result;
4244
}
4345

4446
constexpr RpcType GetMethodType(const StaticServiceMetadata& metadata, std::size_t method_id) {

grpc/include/userver/ugrpc/server/impl/service_worker_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ struct MethodData final {
7676
typename CallTraits::ServiceBase& service;
7777
const typename CallTraits::ServiceMethod service_method;
7878

79-
std::string_view call_name{GetMethodFullName(service_data.metadata, method_id)};
79+
utils::StringLiteral call_name{ugrpc::impl::GetMethodFullName(service_data.metadata, method_id)};
8080
// Remove name of the service and slash
81-
std::string_view method_name{GetMethodName(service_data.metadata, method_id)};
81+
utils::StringLiteral method_name{ugrpc::impl::GetMethodName(service_data.metadata, method_id)};
8282
ugrpc::impl::MethodStatistics& statistics{service_data.service_statistics.GetMethodStatistics(method_id)};
8383
};
8484

grpc/src/ugrpc/server/impl/generic_service_worker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace ugrpc::server::impl {
1212

1313
namespace {
1414

15-
constexpr std::string_view kGenericServiceFullNameFake = "Generic";
15+
constexpr utils::StringLiteral kGenericServiceFullNameFake = "Generic";
1616

1717
constexpr std::array kGenericMethodsFake = {ugrpc::impl::MethodDescriptor{
18-
/*method_full_name*/ "Generic/Generic",
18+
/*method_full_name*/ utils::StringLiteral{"Generic/Generic"},
1919
/*method_type*/ ugrpc::impl::RpcType::kBidiStreaming,
2020
}};
2121

0 commit comments

Comments
 (0)