lib/service_config/service_config_parser.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_PARSER_H
18 #define GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_PARSER_H
19 
21 
22 #include <stddef.h>
23 
24 #include <algorithm>
25 #include <memory>
26 #include <utility>
27 #include <vector>
28 
29 #include "absl/strings/string_view.h"
30 
32 #include <grpc/support/log.h>
33 
35 #include "src/core/lib/json/json.h"
36 
37 namespace grpc_core {
38 
39 // Service config parser registry.
40 // See service_config.h for more information.
42  public:
45  class ParsedConfig {
46  public:
47  virtual ~ParsedConfig() = default;
48  };
49 
51  class Parser {
52  public:
53  virtual ~Parser() = default;
54 
55  virtual absl::string_view name() const = 0;
56 
57  virtual std::unique_ptr<ParsedConfig> ParseGlobalParams(
58  const grpc_channel_args*, const Json& /* json */,
60  // Avoid unused parameter warning on debug-only parameter
61  (void)error;
62  GPR_DEBUG_ASSERT(error != nullptr);
63  return nullptr;
64  }
65 
66  virtual std::unique_ptr<ParsedConfig> ParsePerMethodParams(
67  const grpc_channel_args*, const Json& /* json */,
69  // Avoid unused parameter warning on debug-only parameter
70  (void)error;
71  GPR_DEBUG_ASSERT(error != nullptr);
72  return nullptr;
73  }
74  };
75 
76  using ServiceConfigParserList = std::vector<std::unique_ptr<Parser>>;
77  using ParsedConfigVector = std::vector<std::unique_ptr<ParsedConfig>>;
78 
79  class Builder {
80  public:
85  void RegisterParser(std::unique_ptr<Parser> parser);
86 
88 
89  private:
91  };
92 
94  const Json& json,
95  grpc_error_handle* error) const;
96 
98  const Json& json,
99  grpc_error_handle* error) const;
100 
101  // Return the index for a given registered parser.
102  // If there is an error, return -1.
103  size_t GetParserIndex(absl::string_view name) const;
104 
105  private:
106  explicit ServiceConfigParser(ServiceConfigParserList registered_parsers)
107  : registered_parsers_(std::move(registered_parsers)) {}
109 };
110 
111 } // namespace grpc_core
112 
113 #endif /* GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_PARSER_H */
grpc_core::ServiceConfigParser::Parser::name
virtual absl::string_view name() const =0
grpc_core::ServiceConfigParser::Builder
Definition: lib/service_config/service_config_parser.h:79
log.h
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:103
grpc_core::ServiceConfigParser::Parser::ParseGlobalParams
virtual std::unique_ptr< ParsedConfig > ParseGlobalParams(const grpc_channel_args *, const Json &, grpc_error_handle *error)
Definition: lib/service_config/service_config_parser.h:57
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::ServiceConfigParser::Parser
This is the base class that all service config parsers should derive from.
Definition: lib/service_config/service_config_parser.h:51
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ServiceConfigParser::Builder::Build
ServiceConfigParser Build()
Definition: lib/service_config/service_config_parser.cc:31
grpc_core::ServiceConfigParser::ParsedConfigVector
std::vector< std::unique_ptr< ParsedConfig > > ParsedConfigVector
Definition: lib/service_config/service_config_parser.h:77
setup.name
name
Definition: setup.py:542
grpc_channel_args
Definition: grpc_types.h:132
grpc_types.h
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ServiceConfigParser
Definition: lib/service_config/service_config_parser.h:41
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
grpc_core::ServiceConfigParser::Parser::~Parser
virtual ~Parser()=default
grpc_core::ServiceConfigParser::GetParserIndex
size_t GetParserIndex(absl::string_view name) const
Definition: lib/service_config/service_config_parser.cc:92
grpc_core::ServiceConfigParser::Builder::RegisterParser
void RegisterParser(std::unique_ptr< Parser > parser)
Definition: lib/service_config/service_config_parser.cc:35
error.h
json.h
grpc_core::ServiceConfigParser::ParsedConfig::~ParsedConfig
virtual ~ParsedConfig()=default
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::ServiceConfigParser::Parser::ParsePerMethodParams
virtual std::unique_ptr< ParsedConfig > ParsePerMethodParams(const grpc_channel_args *, const Json &, grpc_error_handle *error)
Definition: lib/service_config/service_config_parser.h:66
grpc_core::ServiceConfigParser::ServiceConfigParserList
std::vector< std::unique_ptr< Parser > > ServiceConfigParserList
Definition: lib/service_config/service_config_parser.h:76
grpc_core::ServiceConfigParser::Builder::registered_parsers_
ServiceConfigParserList registered_parsers_
Definition: lib/service_config/service_config_parser.h:90
grpc_core::ServiceConfigParser::ParseGlobalParameters
ParsedConfigVector ParseGlobalParameters(const grpc_channel_args *args, const Json &json, grpc_error_handle *error) const
Definition: lib/service_config/service_config_parser.cc:51
grpc_error
Definition: error_internal.h:42
grpc_core::ServiceConfigParser::ParsedConfig
Definition: lib/service_config/service_config_parser.h:45
grpc_core::ServiceConfigParser::registered_parsers_
ServiceConfigParserList registered_parsers_
Definition: lib/service_config/service_config_parser.h:108
grpc_core::ServiceConfigParser::ServiceConfigParser
ServiceConfigParser(ServiceConfigParserList registered_parsers)
Definition: lib/service_config/service_config_parser.h:106
grpc_core::ServiceConfigParser::ParsePerMethodParameters
ParsedConfigVector ParsePerMethodParameters(const grpc_channel_args *args, const Json &json, grpc_error_handle *error) const
Definition: lib/service_config/service_config_parser.cc:72
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:12