service_config_impl.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 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_IMPL_H
18 #define GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_IMPL_H
19 
21 
22 #include <stddef.h>
23 
24 #include <memory>
25 #include <string>
26 #include <unordered_map>
27 #include <vector>
28 
29 #include "absl/strings/string_view.h"
30 
32 #include <grpc/slice.h>
33 #include <grpc/support/log.h>
34 
37 #include "src/core/lib/json/json.h"
41 
42 // The main purpose of the code here is to parse the service config in
43 // JSON form, which will look like this:
44 //
45 // {
46 // "loadBalancingPolicy": "string", // optional
47 // "methodConfig": [ // array of one or more method_config objects
48 // {
49 // "name": [ // array of one or more name objects
50 // {
51 // "service": "string", // required
52 // "method": "string", // optional
53 // }
54 // ],
55 // // remaining fields are optional.
56 // // see https://developers.google.com/protocol-buffers/docs/proto3#json
57 // // for format details.
58 // "waitForReady": bool,
59 // "timeout": "duration_string",
60 // "maxRequestMessageBytes": "int64_string",
61 // "maxResponseMessageBytes": "int64_string",
62 // }
63 // ]
64 // }
65 
66 namespace grpc_core {
67 
68 class ServiceConfigImpl final : public ServiceConfig {
69  public:
75 
78  ~ServiceConfigImpl() override;
79 
80  absl::string_view json_string() const override { return json_string_; }
81 
86  size_t index) override {
88  return parsed_global_configs_[index].get();
89  }
90 
95  const grpc_slice& path) const override;
96 
97  private:
98  // Helper functions for parsing the method configs.
101  const Json& json);
102 
103  // Returns a path string for the JSON name object specified by json.
104  // Sets *error on error.
105  static std::string ParseJsonMethodName(const Json& json,
107 
110 
111  std::vector<std::unique_ptr<ServiceConfigParser::ParsedConfig>>
113  // A map from the method name to the parsed config vector. Note that we are
114  // using a raw pointer and not a unique pointer so that we can use the same
115  // vector for multiple names.
116  std::unordered_map<grpc_slice, const ServiceConfigParser::ParsedConfigVector*,
117  SliceHash>
119  // Default method config.
121  nullptr;
122  // Storage for all the vectors that are being used in
123  // parsed_method_configs_table_.
124  std::vector<std::unique_ptr<ServiceConfigParser::ParsedConfigVector>>
126 };
127 
128 } // namespace grpc_core
129 
130 #endif /* GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_IMPL_H */
grpc_core::SliceHash
Definition: slice_internal.h:84
grpc_core::ServiceConfigImpl::GetMethodParsedConfigVector
const ServiceConfigParser::ParsedConfigVector * GetMethodParsedConfigVector(const grpc_slice &path) const override
Definition: service_config_impl.cc:217
log.h
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:103
slice.h
grpc_core::ServiceConfigImpl::ParsePerMethodParams
grpc_error_handle ParsePerMethodParams(const grpc_channel_args *args)
Definition: service_config_impl.cc:143
grpc_core
Definition: call_metric_recorder.h:31
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ServiceConfigParser::ParsedConfigVector
std::vector< std::unique_ptr< ParsedConfig > > ParsedConfigVector
Definition: lib/service_config/service_config_parser.h:77
check_documentation.path
path
Definition: check_documentation.py:57
grpc_channel_args
Definition: grpc_types.h:132
grpc_types.h
grpc_core::ServiceConfigImpl
Definition: service_config_impl.h:68
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_slice
struct grpc_slice grpc_slice
Definition: include/grpc/impl/codegen/slice.h:30
grpc_core::ServiceConfigImpl::default_method_config_vector_
const ServiceConfigParser::ParsedConfigVector * default_method_config_vector_
Definition: service_config_impl.h:120
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
grpc_core::ServiceConfigImpl::json_string
absl::string_view json_string() const override
Definition: service_config_impl.h:80
grpc_core::ServiceConfig
Definition: service_config.h:59
grpc_core::ServiceConfigImpl::parsed_global_configs_
std::vector< std::unique_ptr< ServiceConfigParser::ParsedConfig > > parsed_global_configs_
Definition: service_config_impl.h:112
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
error.h
json.h
slice_internal.h
grpc_core::ServiceConfigImpl::Create
static RefCountedPtr< ServiceConfig > Create(const grpc_channel_args *args, absl::string_view json_string, grpc_error_handle *error)
Definition: service_config_impl.cc:41
service_config_parser.h
grpc_core::ServiceConfigImpl::parsed_method_config_vectors_storage_
std::vector< std::unique_ptr< ServiceConfigParser::ParsedConfigVector > > parsed_method_config_vectors_storage_
Definition: service_config_impl.h:125
grpc_core::ServiceConfigImpl::parsed_method_configs_map_
std::unordered_map< grpc_slice, const ServiceConfigParser::ParsedConfigVector *, SliceHash > parsed_method_configs_map_
Definition: service_config_impl.h:118
grpc_core::ServiceConfigImpl::json_string_
std::string json_string_
Definition: service_config_impl.h:108
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
ref_counted_ptr.h
grpc_core::ServiceConfigImpl::~ServiceConfigImpl
~ServiceConfigImpl() override
Definition: service_config_impl.cc:75
grpc_core::ServiceConfigImpl::json_
Json json_
Definition: service_config_impl.h:109
service_config.h
grpc_core::ServiceConfigImpl::ParseJsonMethodName
static std::string ParseJsonMethodName(const Json &json, grpc_error_handle *error)
Definition: service_config_impl.cc:167
grpc_error
Definition: error_internal.h:42
grpc_core::ServiceConfigImpl::GetGlobalParsedConfig
ServiceConfigParser::ParsedConfig * GetGlobalParsedConfig(size_t index) override
Definition: service_config_impl.h:85
grpc_core::ServiceConfigParser::ParsedConfig
Definition: lib/service_config/service_config_parser.h:45
grpc_core::ServiceConfigImpl::ServiceConfigImpl
ServiceConfigImpl(const grpc_channel_args *args, std::string json_string, Json json, grpc_error_handle *error)
Definition: service_config_impl.cc:51
grpc_core::ServiceConfigImpl::ParseJsonMethodConfig
grpc_error_handle ParseJsonMethodConfig(const grpc_channel_args *args, const Json &json)
Definition: service_config_impl.cc:81
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:17