grpc 1.49.1 → 1.50.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +33 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +112 -96
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +84 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -15
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +1 -1
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/lib/grpc/version.rb +1 -1
  258. data/src/ruby/spec/channel_spec.rb +5 -0
  259. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  260. data/src/ruby/spec/user_agent_spec.rb +1 -1
  261. metadata +33 -19
  262. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  263. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  264. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  265. data/src/core/lib/event_engine/promise.h +0 -78
  266. data/src/core/lib/gpr/env_windows.cc +0 -74
  267. data/src/core/lib/gpr/string_windows.h +0 -32
  268. data/src/core/lib/profiling/basic_timers.cc +0 -295
  269. data/src/core/lib/profiling/stap_timers.cc +0 -50
  270. data/src/core/lib/profiling/timers.h +0 -94
@@ -29,6 +29,7 @@
29
29
 
30
30
  #include "absl/strings/str_cat.h"
31
31
 
32
+ #include <grpc/event_engine/endpoint_config.h>
32
33
  #include <grpc/support/alloc.h>
33
34
  #include <grpc/support/log.h>
34
35
  #include <grpc/support/log_windows.h>
@@ -37,7 +38,6 @@
37
38
  #include <grpc/support/time.h>
38
39
 
39
40
  #include "src/core/lib/address_utils/sockaddr_utils.h"
40
- #include "src/core/lib/channel/channel_args.h"
41
41
  #include "src/core/lib/iomgr/iocp_windows.h"
42
42
  #include "src/core/lib/iomgr/pollset_windows.h"
43
43
  #include "src/core/lib/iomgr/resolve_address.h"
@@ -45,10 +45,13 @@
45
45
  #include "src/core/lib/iomgr/socket_windows.h"
46
46
  #include "src/core/lib/iomgr/tcp_server.h"
47
47
  #include "src/core/lib/iomgr/tcp_windows.h"
48
+ #include "src/core/lib/resource_quota/api.h"
48
49
  #include "src/core/lib/slice/slice_internal.h"
49
50
 
50
51
  #define MIN_SAFE_ACCEPT_QUEUE_SIZE 100
51
52
 
53
+ using ::grpc_event_engine::experimental::EndpointConfig;
54
+
52
55
  /* one listening port */
53
56
  typedef struct grpc_tcp_listener grpc_tcp_listener;
54
57
  struct grpc_tcp_listener {
@@ -94,17 +97,14 @@ struct grpc_tcp_server {
94
97
 
95
98
  /* shutdown callback */
96
99
  grpc_closure* shutdown_complete;
97
-
98
- grpc_channel_args* channel_args;
99
100
  };
100
101
 
101
102
  /* Public function. Allocates the proper data structures to hold a
102
103
  grpc_tcp_server. */
103
104
  static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete,
104
- const grpc_channel_args* args,
105
+ const EndpointConfig& config,
105
106
  grpc_tcp_server** server) {
106
107
  grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server));
107
- s->channel_args = grpc_channel_args_copy(args);
108
108
  gpr_ref_init(&s->refs, 1);
109
109
  gpr_mu_init(&s->mu);
110
110
  s->active_ports = 0;
@@ -132,7 +132,6 @@ static void destroy_server(void* arg, grpc_error_handle error) {
132
132
  grpc_winsocket_destroy(sp->socket);
133
133
  gpr_free(sp);
134
134
  }
135
- grpc_channel_args_destroy(s->channel_args);
136
135
  gpr_mu_destroy(&s->mu);
137
136
  gpr_free(s);
138
137
  }
@@ -363,7 +362,7 @@ static void on_accept(void* arg, grpc_error_handle error) {
363
362
  }
364
363
  std::string fd_name = absl::StrCat("tcp_server:", peer_name_string);
365
364
  ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name.c_str()),
366
- sp->server->channel_args, peer_name_string);
365
+ peer_name_string);
367
366
  } else {
368
367
  closesocket(sock);
369
368
  }
@@ -505,7 +505,6 @@ static grpc_endpoint_vtable vtable = {win_read,
505
505
  win_can_track_err};
506
506
 
507
507
  grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
508
- grpc_channel_args* channel_args,
509
508
  absl::string_view peer_string) {
510
509
  // TODO(jtattermusch): C++ize grpc_tcp and its dependencies (i.e. add
511
510
  // constructors) to ensure proper initialization
@@ -41,7 +41,6 @@
41
41
  * Takes ownership of the handle.
42
42
  */
43
43
  grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
44
- grpc_channel_args* channel_args,
45
44
  absl::string_view peer_string);
46
45
 
47
46
  grpc_error_handle grpc_tcp_prepare_socket(SOCKET sock);
@@ -253,7 +253,7 @@ static void timer_list_init() {
253
253
  g_shared_mutables.initialized = true;
254
254
  g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER;
255
255
  gpr_mu_init(&g_shared_mutables.mu);
256
- g_shared_mutables.min_timer = grpc_core::ExecCtx::Get()->Now();
256
+ g_shared_mutables.min_timer = grpc_core::Timestamp::Now();
257
257
 
258
258
  g_last_seen_min_timer = 0;
259
259
 
@@ -343,7 +343,7 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline,
343
343
  if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
344
344
  gpr_log(GPR_INFO, "TIMER %p: SET %" PRId64 " now %" PRId64 " call %p[%p]",
345
345
  timer, deadline.milliseconds_after_process_epoch(),
346
- grpc_core::ExecCtx::Get()->Now().milliseconds_after_process_epoch(),
346
+ grpc_core::Timestamp::Now().milliseconds_after_process_epoch(),
347
347
  closure, closure->cb);
348
348
  }
349
349
 
@@ -358,7 +358,7 @@ static void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline,
358
358
 
359
359
  gpr_mu_lock(&shard->mu);
360
360
  timer->pending = true;
361
- grpc_core::Timestamp now = grpc_core::ExecCtx::Get()->Now();
361
+ grpc_core::Timestamp now = grpc_core::Timestamp::Now();
362
362
  if (deadline <= now) {
363
363
  timer->pending = false;
364
364
  grpc_core::ExecCtx::Run(DEBUG_LOCATION, timer->closure, GRPC_ERROR_NONE);
@@ -665,7 +665,7 @@ static grpc_timer_check_result run_some_expired_timers(
665
665
 
666
666
  static grpc_timer_check_result timer_check(grpc_core::Timestamp* next) {
667
667
  // prelude
668
- grpc_core::Timestamp now = grpc_core::ExecCtx::Get()->Now();
668
+ grpc_core::Timestamp now = grpc_core::Timestamp::Now();
669
669
 
670
670
  /* fetch from a thread-local first: this avoids contention on a globally
671
671
  mutable cacheline in the common case */
@@ -184,8 +184,7 @@ static bool wait_until(grpc_core::Timestamp next) {
184
184
  g_timed_waiter_deadline = next;
185
185
 
186
186
  if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
187
- grpc_core::Duration wait_time =
188
- next - grpc_core::ExecCtx::Get()->Now();
187
+ grpc_core::Duration wait_time = next - grpc_core::Timestamp::Now();
189
188
  gpr_log(GPR_INFO, "sleep for a %" PRId64 " milliseconds",
190
189
  wait_time.millis());
191
190
  }
@@ -29,7 +29,6 @@
29
29
  #include <grpc/support/log.h>
30
30
 
31
31
  #include "src/core/lib/iomgr/wakeup_fd_posix.h"
32
- #include "src/core/lib/profiling/timers.h"
33
32
 
34
33
  static grpc_error_handle eventfd_create(grpc_wakeup_fd* fd_info) {
35
34
  fd_info->read_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
@@ -53,7 +52,6 @@ static grpc_error_handle eventfd_consume(grpc_wakeup_fd* fd_info) {
53
52
  }
54
53
 
55
54
  static grpc_error_handle eventfd_wakeup(grpc_wakeup_fd* fd_info) {
56
- GPR_TIMER_SCOPE("eventfd_wakeup", 0);
57
55
  int err;
58
56
  do {
59
57
  err = eventfd_write(fd_info->read_fd, 1);
@@ -16,53 +16,17 @@
16
16
 
17
17
  #include "src/core/lib/json/json_object_loader.h"
18
18
 
19
- #include <algorithm>
20
19
  #include <utility>
21
20
 
22
- #include "absl/status/status.h"
23
21
  #include "absl/strings/ascii.h"
24
22
  #include "absl/strings/str_cat.h"
25
- #include "absl/strings/str_join.h"
26
23
  #include "absl/strings/strip.h"
27
24
 
28
25
  namespace grpc_core {
29
-
30
- void ErrorList::PushField(absl::string_view ext) {
31
- // Skip leading '.' for top-level field names.
32
- if (fields_.empty()) absl::ConsumePrefix(&ext, ".");
33
- fields_.emplace_back(std::string(ext));
34
- }
35
-
36
- void ErrorList::PopField() { fields_.pop_back(); }
37
-
38
- void ErrorList::AddError(absl::string_view error) {
39
- field_errors_[absl::StrJoin(fields_, "")].emplace_back(error);
40
- }
41
-
42
- bool ErrorList::FieldHasErrors() const {
43
- return field_errors_.find(absl::StrJoin(fields_, "")) != field_errors_.end();
44
- }
45
-
46
- absl::Status ErrorList::status() const {
47
- if (field_errors_.empty()) return absl::OkStatus();
48
- std::vector<std::string> errors;
49
- for (const auto& p : field_errors_) {
50
- if (p.second.size() > 1) {
51
- errors.emplace_back(absl::StrCat("field:", p.first, " errors:[",
52
- absl::StrJoin(p.second, "; "), "]"));
53
- } else {
54
- errors.emplace_back(
55
- absl::StrCat("field:", p.first, " error:", p.second[0]));
56
- }
57
- }
58
- return absl::InvalidArgumentError(absl::StrCat(
59
- "errors validating JSON: [", absl::StrJoin(errors, "; "), "]"));
60
- }
61
-
62
26
  namespace json_detail {
63
27
 
64
28
  void LoadScalar::LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst,
65
- ErrorList* errors) const {
29
+ ValidationErrors* errors) const {
66
30
  // We accept either STRING or NUMBER for numeric values, as per
67
31
  // https://developers.google.com/protocol-buffers/docs/proto3#json.
68
32
  if (json.type() != Json::Type::STRING &&
@@ -77,14 +41,14 @@ void LoadScalar::LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst,
77
41
  bool LoadString::IsNumber() const { return false; }
78
42
 
79
43
  void LoadString::LoadInto(const std::string& value, void* dst,
80
- ErrorList*) const {
44
+ ValidationErrors*) const {
81
45
  *static_cast<std::string*>(dst) = value;
82
46
  }
83
47
 
84
48
  bool LoadDuration::IsNumber() const { return false; }
85
49
 
86
50
  void LoadDuration::LoadInto(const std::string& value, void* dst,
87
- ErrorList* errors) const {
51
+ ValidationErrors* errors) const {
88
52
  absl::string_view buf(value);
89
53
  if (!absl::ConsumeSuffix(&buf, "s")) {
90
54
  errors->AddError("Not a duration (no s suffix)");
@@ -121,7 +85,7 @@ void LoadDuration::LoadInto(const std::string& value, void* dst,
121
85
  bool LoadNumber::IsNumber() const { return true; }
122
86
 
123
87
  void LoadBool::LoadInto(const Json& json, const JsonArgs&, void* dst,
124
- ErrorList* errors) const {
88
+ ValidationErrors* errors) const {
125
89
  if (json.type() == Json::Type::JSON_TRUE) {
126
90
  *static_cast<bool*>(dst) = true;
127
91
  } else if (json.type() == Json::Type::JSON_FALSE) {
@@ -132,7 +96,8 @@ void LoadBool::LoadInto(const Json& json, const JsonArgs&, void* dst,
132
96
  }
133
97
 
134
98
  void LoadUnprocessedJsonObject::LoadInto(const Json& json, const JsonArgs&,
135
- void* dst, ErrorList* errors) const {
99
+ void* dst,
100
+ ValidationErrors* errors) const {
136
101
  if (json.type() != Json::Type::OBJECT) {
137
102
  errors->AddError("is not an object");
138
103
  return;
@@ -141,7 +106,7 @@ void LoadUnprocessedJsonObject::LoadInto(const Json& json, const JsonArgs&,
141
106
  }
142
107
 
143
108
  void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst,
144
- ErrorList* errors) const {
109
+ ValidationErrors* errors) const {
145
110
  if (json.type() != Json::Type::ARRAY) {
146
111
  errors->AddError("is not an array");
147
112
  return;
@@ -149,7 +114,7 @@ void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst,
149
114
  const auto& array = json.array_value();
150
115
  const LoaderInterface* element_loader = ElementLoader();
151
116
  for (size_t i = 0; i < array.size(); ++i) {
152
- ScopedField field(errors, absl::StrCat("[", i, "]"));
117
+ ValidationErrors::ScopedField field(errors, absl::StrCat("[", i, "]"));
153
118
  void* element = EmplaceBack(dst);
154
119
  element_loader->LoadInto(array[i], args, element, errors);
155
120
  }
@@ -157,7 +122,7 @@ void LoadVector::LoadInto(const Json& json, const JsonArgs& args, void* dst,
157
122
 
158
123
  void AutoLoader<std::vector<bool>>::LoadInto(const Json& json,
159
124
  const JsonArgs& args, void* dst,
160
- ErrorList* errors) const {
125
+ ValidationErrors* errors) const {
161
126
  if (json.type() != Json::Type::ARRAY) {
162
127
  errors->AddError("is not an array");
163
128
  return;
@@ -166,7 +131,7 @@ void AutoLoader<std::vector<bool>>::LoadInto(const Json& json,
166
131
  const LoaderInterface* element_loader = LoaderForType<bool>();
167
132
  std::vector<bool>* vec = static_cast<std::vector<bool>*>(dst);
168
133
  for (size_t i = 0; i < array.size(); ++i) {
169
- ScopedField field(errors, absl::StrCat("[", i, "]"));
134
+ ValidationErrors::ScopedField field(errors, absl::StrCat("[", i, "]"));
170
135
  bool elem = false;
171
136
  element_loader->LoadInto(array[i], args, &elem, errors);
172
137
  vec->push_back(elem);
@@ -174,28 +139,31 @@ void AutoLoader<std::vector<bool>>::LoadInto(const Json& json,
174
139
  }
175
140
 
176
141
  void LoadMap::LoadInto(const Json& json, const JsonArgs& args, void* dst,
177
- ErrorList* errors) const {
142
+ ValidationErrors* errors) const {
178
143
  if (json.type() != Json::Type::OBJECT) {
179
144
  errors->AddError("is not an object");
180
145
  return;
181
146
  }
182
147
  const LoaderInterface* element_loader = ElementLoader();
183
148
  for (const auto& pair : json.object_value()) {
184
- ScopedField field(errors, absl::StrCat("[\"", pair.first, "\"]"));
149
+ ValidationErrors::ScopedField field(errors,
150
+ absl::StrCat("[\"", pair.first, "\"]"));
185
151
  void* element = Insert(pair.first, dst);
186
152
  element_loader->LoadInto(pair.second, args, element, errors);
187
153
  }
188
154
  }
189
155
 
190
156
  void LoadOptional::LoadInto(const Json& json, const JsonArgs& args, void* dst,
191
- ErrorList* errors) const {
157
+ ValidationErrors* errors) const {
192
158
  if (json.type() == Json::Type::JSON_NULL) return;
193
159
  void* element = Emplace(dst);
160
+ size_t starting_error_size = errors->size();
194
161
  ElementLoader()->LoadInto(json, args, element, errors);
162
+ if (errors->size() > starting_error_size) Reset(dst);
195
163
  }
196
164
 
197
165
  bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
198
- size_t num_elements, void* dst, ErrorList* errors) {
166
+ size_t num_elements, void* dst, ValidationErrors* errors) {
199
167
  if (json.type() != Json::Type::OBJECT) {
200
168
  errors->AddError("is not an object");
201
169
  return false;
@@ -205,7 +173,8 @@ bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
205
173
  if (element.enable_key != nullptr && !args.IsEnabled(element.enable_key)) {
206
174
  continue;
207
175
  }
208
- ScopedField field(errors, absl::StrCat(".", element.name));
176
+ ValidationErrors::ScopedField field(errors,
177
+ absl::StrCat(".", element.name));
209
178
  const auto& it = json.object_value().find(element.name);
210
179
  if (it == json.object_value().end()) {
211
180
  if (element.optional) continue;
@@ -219,8 +188,8 @@ bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
219
188
  }
220
189
 
221
190
  const Json* GetJsonObjectField(const Json::Object& json,
222
- absl::string_view field, ErrorList* errors,
223
- bool required) {
191
+ absl::string_view field,
192
+ ValidationErrors* errors, bool required) {
224
193
  auto it = json.find(std::string(field));
225
194
  if (it == json.end()) {
226
195
  if (required) errors->AddError("field not present");
@@ -24,7 +24,6 @@
24
24
  #include <vector>
25
25
 
26
26
  #include "absl/meta/type_traits.h"
27
- #include "absl/status/status.h"
28
27
  #include "absl/status/statusor.h"
29
28
  #include "absl/strings/numbers.h"
30
29
  #include "absl/strings/str_cat.h"
@@ -32,7 +31,9 @@
32
31
  #include "absl/types/optional.h"
33
32
 
34
33
  #include "src/core/lib/gprpp/no_destruct.h"
34
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
35
35
  #include "src/core/lib/gprpp/time.h"
36
+ #include "src/core/lib/gprpp/validation_errors.h"
36
37
  #include "src/core/lib/json/json.h"
37
38
  #include "src/core/lib/json/json_args.h"
38
39
 
@@ -51,7 +52,7 @@
51
52
  // struct Foo {
52
53
  // int a;
53
54
  // int b;
54
- // static const JsonLoaderInterface* JsonLoader() {
55
+ // static const JsonLoaderInterface* JsonLoader(const JsonArgs& args) {
55
56
  // // Note: Field names must be string constants; they are not copied.
56
57
  // static const auto* loader = JsonObjectLoader<Foo>()
57
58
  // .Field("a", &Foo::a)
@@ -60,63 +61,24 @@
60
61
  // return loader;
61
62
  // }
62
63
  // // Optional; omit if no post-processing needed.
63
- // void JsonPostLoad(const Json& source, ErrorList* errors) { ++a; }
64
+ // void JsonPostLoad(const Json& source, const JsonArgs& args,
65
+ // ValidationErrors* errors) {
66
+ // ++a;
67
+ // }
64
68
  // };
65
69
  // Now we can load Foo objects from JSON:
66
70
  // absl::StatusOr<Foo> foo = LoadFromJson<Foo>(json);
67
71
  namespace grpc_core {
68
72
 
69
- // A list of errors that occurred during JSON parsing.
70
- // If a non-empty list occurs during parsing, the parsing failed.
71
- class ErrorList {
72
- public:
73
- // Record that we're reading some field.
74
- void PushField(absl::string_view ext) GPR_ATTRIBUTE_NOINLINE;
75
- // Record that we've finished reading that field.
76
- void PopField() GPR_ATTRIBUTE_NOINLINE;
77
-
78
- // Record that we've encountered an error.
79
- void AddError(absl::string_view error) GPR_ATTRIBUTE_NOINLINE;
80
- // Returns true if the current field has errors.
81
- bool FieldHasErrors() const GPR_ATTRIBUTE_NOINLINE;
82
-
83
- // Returns the resulting status of parsing.
84
- absl::Status status() const;
85
-
86
- // Return true if there are no errors.
87
- bool ok() const { return field_errors_.empty(); }
88
-
89
- size_t size() const { return field_errors_.size(); }
90
-
91
- private:
92
- // TODO(roth): If we don't actually have any fields for which we
93
- // report more than one error, simplify this data structure.
94
- std::map<std::string /*field_name*/, std::vector<std::string>> field_errors_;
95
- std::vector<std::string> fields_;
96
- };
97
-
98
- // Note that we're reading a field, and remove it at the end of the scope.
99
- class ScopedField {
100
- public:
101
- ScopedField(ErrorList* error_list, absl::string_view field_name)
102
- : error_list_(error_list) {
103
- error_list_->PushField(field_name);
104
- }
105
- ~ScopedField() { error_list_->PopField(); }
106
-
107
- private:
108
- ErrorList* error_list_;
109
- };
110
-
111
73
  namespace json_detail {
112
74
 
113
75
  // An un-typed JSON loader.
114
76
  class LoaderInterface {
115
77
  public:
116
78
  // Convert json value to whatever type we're loading at dst.
117
- // If errors occur, add them to error_list.
79
+ // If errors occur, add them to errors.
118
80
  virtual void LoadInto(const Json& json, const JsonArgs& args, void* dst,
119
- ErrorList* errors) const = 0;
81
+ ValidationErrors* errors) const = 0;
120
82
 
121
83
  protected:
122
84
  ~LoaderInterface() = default;
@@ -126,7 +88,7 @@ class LoaderInterface {
126
88
  class LoadScalar : public LoaderInterface {
127
89
  public:
128
90
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
129
- ErrorList* errors) const override;
91
+ ValidationErrors* errors) const override;
130
92
 
131
93
  protected:
132
94
  ~LoadScalar() = default;
@@ -138,7 +100,7 @@ class LoadScalar : public LoaderInterface {
138
100
  virtual bool IsNumber() const = 0;
139
101
 
140
102
  virtual void LoadInto(const std::string& json, void* dst,
141
- ErrorList* errors) const = 0;
103
+ ValidationErrors* errors) const = 0;
142
104
  };
143
105
 
144
106
  // Load a string.
@@ -149,7 +111,7 @@ class LoadString : public LoadScalar {
149
111
  private:
150
112
  bool IsNumber() const override;
151
113
  void LoadInto(const std::string& value, void* dst,
152
- ErrorList* errors) const override;
114
+ ValidationErrors* errors) const override;
153
115
  };
154
116
 
155
117
  // Load a Duration.
@@ -160,7 +122,7 @@ class LoadDuration : public LoadScalar {
160
122
  private:
161
123
  bool IsNumber() const override;
162
124
  void LoadInto(const std::string& value, void* dst,
163
- ErrorList* errors) const override;
125
+ ValidationErrors* errors) const override;
164
126
  };
165
127
 
166
128
  // Load a number.
@@ -180,7 +142,7 @@ class TypedLoadSignedNumber : public LoadNumber {
180
142
 
181
143
  private:
182
144
  void LoadInto(const std::string& value, void* dst,
183
- ErrorList* errors) const override {
145
+ ValidationErrors* errors) const override {
184
146
  if (!absl::SimpleAtoi(value, static_cast<T*>(dst))) {
185
147
  errors->AddError("failed to parse number");
186
148
  }
@@ -195,7 +157,7 @@ class TypedLoadUnsignedNumber : public LoadNumber {
195
157
 
196
158
  private:
197
159
  void LoadInto(const std::string& value, void* dst,
198
- ErrorList* errors) const override {
160
+ ValidationErrors* errors) const override {
199
161
  if (!absl::SimpleAtoi(value, static_cast<T*>(dst))) {
200
162
  errors->AddError("failed to parse non-negative number");
201
163
  }
@@ -209,7 +171,7 @@ class LoadFloat : public LoadNumber {
209
171
 
210
172
  private:
211
173
  void LoadInto(const std::string& value, void* dst,
212
- ErrorList* errors) const override {
174
+ ValidationErrors* errors) const override {
213
175
  if (!absl::SimpleAtof(value, static_cast<float*>(dst))) {
214
176
  errors->AddError("failed to parse floating-point number");
215
177
  }
@@ -223,7 +185,7 @@ class LoadDouble : public LoadNumber {
223
185
 
224
186
  private:
225
187
  void LoadInto(const std::string& value, void* dst,
226
- ErrorList* errors) const override {
188
+ ValidationErrors* errors) const override {
227
189
  if (!absl::SimpleAtod(value, static_cast<double*>(dst))) {
228
190
  errors->AddError("failed to parse floating-point number");
229
191
  }
@@ -234,7 +196,7 @@ class LoadDouble : public LoadNumber {
234
196
  class LoadBool : public LoaderInterface {
235
197
  public:
236
198
  void LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst,
237
- ErrorList* errors) const override;
199
+ ValidationErrors* errors) const override;
238
200
 
239
201
  protected:
240
202
  ~LoadBool() = default;
@@ -244,7 +206,7 @@ class LoadBool : public LoaderInterface {
244
206
  class LoadUnprocessedJsonObject : public LoaderInterface {
245
207
  public:
246
208
  void LoadInto(const Json& json, const JsonArgs& /*args*/, void* dst,
247
- ErrorList* errors) const override;
209
+ ValidationErrors* errors) const override;
248
210
 
249
211
  protected:
250
212
  ~LoadUnprocessedJsonObject() = default;
@@ -254,7 +216,7 @@ class LoadUnprocessedJsonObject : public LoaderInterface {
254
216
  class LoadVector : public LoaderInterface {
255
217
  public:
256
218
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
257
- ErrorList* errors) const override;
219
+ ValidationErrors* errors) const override;
258
220
 
259
221
  protected:
260
222
  ~LoadVector() = default;
@@ -268,7 +230,7 @@ class LoadVector : public LoaderInterface {
268
230
  class LoadMap : public LoaderInterface {
269
231
  public:
270
232
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
271
- ErrorList* errors) const override;
233
+ ValidationErrors* errors) const override;
272
234
 
273
235
  protected:
274
236
  ~LoadMap() = default;
@@ -282,13 +244,14 @@ class LoadMap : public LoaderInterface {
282
244
  class LoadOptional : public LoaderInterface {
283
245
  public:
284
246
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
285
- ErrorList* errors) const override;
247
+ ValidationErrors* errors) const override;
286
248
 
287
249
  protected:
288
250
  ~LoadOptional() = default;
289
251
 
290
252
  private:
291
253
  virtual void* Emplace(void* dst) const = 0;
254
+ virtual void Reset(void* dst) const = 0;
292
255
  virtual const LoaderInterface* ElementLoader() const = 0;
293
256
  };
294
257
 
@@ -304,7 +267,7 @@ template <typename T>
304
267
  class AutoLoader final : public LoaderInterface {
305
268
  public:
306
269
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
307
- ErrorList* errors) const override {
270
+ ValidationErrors* errors) const override {
308
271
  T::JsonLoader(args)->LoadInto(json, args, dst, errors);
309
272
  }
310
273
 
@@ -387,7 +350,7 @@ template <>
387
350
  class AutoLoader<std::vector<bool>> final : public LoaderInterface {
388
351
  public:
389
352
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
390
- ErrorList* errors) const override;
353
+ ValidationErrors* errors) const override;
391
354
 
392
355
  private:
393
356
  ~AutoLoader() = default;
@@ -417,6 +380,9 @@ class AutoLoader<absl::optional<T>> final : public LoadOptional {
417
380
  void* Emplace(void* dst) const final {
418
381
  return &static_cast<absl::optional<T>*>(dst)->emplace();
419
382
  }
383
+ void Reset(void* dst) const final {
384
+ static_cast<absl::optional<T>*>(dst)->reset();
385
+ }
420
386
  const LoaderInterface* ElementLoader() const final {
421
387
  return LoaderForType<T>();
422
388
  }
@@ -485,7 +451,7 @@ class Vec<T, 0> {
485
451
  // the object from some parsed JSON.
486
452
  // Returns false if the JSON object was not of type Json::Type::OBJECT.
487
453
  bool LoadObject(const Json& json, const JsonArgs& args, const Element* elements,
488
- size_t num_elements, void* dst, ErrorList* errors);
454
+ size_t num_elements, void* dst, ValidationErrors* errors);
489
455
 
490
456
  // Adaptor type - takes a compile time computed list of elements and
491
457
  // implements LoaderInterface by calling LoadObject.
@@ -496,7 +462,7 @@ class FinishedJsonObjectLoader final : public LoaderInterface {
496
462
  : elements_(elements) {}
497
463
 
498
464
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
499
- ErrorList* errors) const override {
465
+ ValidationErrors* errors) const override {
500
466
  LoadObject(json, args, elements_.data(), elements_.size(), dst, errors);
501
467
  }
502
468
 
@@ -514,7 +480,7 @@ class FinishedJsonObjectLoader<T, kElemCount,
514
480
  : elements_(elements) {}
515
481
 
516
482
  void LoadInto(const Json& json, const JsonArgs& args, void* dst,
517
- ErrorList* errors) const override {
483
+ ValidationErrors* errors) const override {
518
484
  // Call JsonPostLoad() only if json is a JSON object.
519
485
  if (LoadObject(json, args, elements_.data(), elements_.size(), dst,
520
486
  errors)) {
@@ -570,8 +536,8 @@ class JsonObjectLoader final {
570
536
  };
571
537
 
572
538
  const Json* GetJsonObjectField(const Json::Object& json,
573
- absl::string_view field, ErrorList* errors,
574
- bool required);
539
+ absl::string_view field,
540
+ ValidationErrors* errors, bool required);
575
541
 
576
542
  } // namespace json_detail
577
543
 
@@ -581,19 +547,32 @@ using JsonObjectLoader = json_detail::JsonObjectLoader<T>;
581
547
  using JsonLoaderInterface = json_detail::LoaderInterface;
582
548
 
583
549
  template <typename T>
584
- absl::StatusOr<T> LoadFromJson(const Json& json,
585
- const JsonArgs& args = JsonArgs()) {
586
- ErrorList error_list;
550
+ absl::StatusOr<T> LoadFromJson(
551
+ const Json& json, const JsonArgs& args = JsonArgs(),
552
+ absl::string_view error_prefix = "errors validating JSON") {
553
+ ValidationErrors errors;
587
554
  T result{};
588
- json_detail::LoaderForType<T>()->LoadInto(json, args, &result, &error_list);
589
- if (!error_list.ok()) return error_list.status();
555
+ json_detail::LoaderForType<T>()->LoadInto(json, args, &result, &errors);
556
+ if (!errors.ok()) return errors.status(error_prefix);
557
+ return std::move(result);
558
+ }
559
+
560
+ template <typename T>
561
+ absl::StatusOr<RefCountedPtr<T>> LoadRefCountedFromJson(
562
+ const Json& json, const JsonArgs& args = JsonArgs(),
563
+ absl::string_view error_prefix = "errors validating JSON") {
564
+ ValidationErrors errors;
565
+ auto result = MakeRefCounted<T>();
566
+ json_detail::LoaderForType<T>()->LoadInto(json, args, result.get(), &errors);
567
+ if (!errors.ok()) return errors.status(error_prefix);
590
568
  return std::move(result);
591
569
  }
592
570
 
593
571
  template <typename T>
594
- T LoadFromJson(const Json& json, const JsonArgs& args, ErrorList* error_list) {
572
+ T LoadFromJson(const Json& json, const JsonArgs& args,
573
+ ValidationErrors* errors) {
595
574
  T result{};
596
- json_detail::LoaderForType<T>()->LoadInto(json, args, &result, error_list);
575
+ json_detail::LoaderForType<T>()->LoadInto(json, args, &result, errors);
597
576
  return result;
598
577
  }
599
578
 
@@ -601,8 +580,9 @@ template <typename T>
601
580
  absl::optional<T> LoadJsonObjectField(const Json::Object& json,
602
581
  const JsonArgs& args,
603
582
  absl::string_view field,
604
- ErrorList* errors, bool required = true) {
605
- ScopedField error_field(errors, absl::StrCat(".", field));
583
+ ValidationErrors* errors,
584
+ bool required = true) {
585
+ ValidationErrors::ScopedField error_field(errors, absl::StrCat(".", field));
606
586
  const Json* field_json =
607
587
  json_detail::GetJsonObjectField(json, field, errors, required);
608
588
  if (field_json == nullptr) return absl::nullopt;
@@ -21,13 +21,14 @@
21
21
  #include "src/core/lib/json/json_util.h"
22
22
 
23
23
  #include "src/core/lib/gprpp/no_destruct.h"
24
+ #include "src/core/lib/gprpp/validation_errors.h"
24
25
  #include "src/core/lib/json/json_args.h"
25
26
  #include "src/core/lib/json/json_object_loader.h"
26
27
 
27
28
  namespace grpc_core {
28
29
 
29
30
  bool ParseDurationFromJson(const Json& field, Duration* duration) {
30
- ErrorList errors;
31
+ ValidationErrors errors;
31
32
  static_cast<json_detail::LoaderInterface*>(
32
33
  NoDestructSingleton<json_detail::AutoLoader<Duration>>::Get())
33
34
  ->LoadInto(field, JsonArgs(), duration, &errors);