grpc 1.33.0.pre1 → 1.34.0

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 (533) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +342 -134
  3. data/include/grpc/grpc.h +1 -2
  4. data/include/grpc/grpc_security.h +149 -172
  5. data/include/grpc/impl/codegen/grpc_types.h +9 -2
  6. data/include/grpc/impl/codegen/port_platform.h +22 -55
  7. data/src/core/ext/filters/client_channel/client_channel.cc +11 -34
  8. data/src/core/ext/filters/client_channel/config_selector.h +2 -3
  9. data/src/core/ext/filters/client_channel/health/health_check_client.cc +4 -1
  10. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -2
  11. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  12. data/src/core/ext/filters/client_channel/lb_policy.cc +5 -1
  13. data/src/core/ext/filters/client_channel/lb_policy.h +3 -3
  14. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +1 -1
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +80 -71
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +3 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +2 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +47 -17
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +2 -2
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -5
  22. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -3
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +1 -1
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +16 -243
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +53 -17
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +809 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +20 -25
  28. data/src/core/ext/filters/client_channel/resolver.cc +3 -1
  29. data/src/core/ext/filters/client_channel/resolver.h +4 -1
  30. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  33. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  34. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -1
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +20 -0
  36. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +66 -7
  37. data/src/core/ext/filters/client_channel/resolver_registry.cc +4 -4
  38. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +13 -25
  39. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +1 -1
  40. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +2 -2
  41. data/src/core/ext/filters/client_channel/retry_throttle.h +1 -1
  42. data/src/core/ext/filters/client_channel/server_address.h +0 -4
  43. data/src/core/ext/filters/client_channel/service_config.cc +3 -1
  44. data/src/core/ext/filters/client_channel/service_config.h +1 -1
  45. data/src/core/ext/filters/client_channel/subchannel.cc +18 -15
  46. data/src/core/ext/filters/client_channel/subchannel.h +2 -2
  47. data/src/core/ext/filters/client_channel/subchannel_interface.h +7 -15
  48. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +6 -2
  49. data/src/core/ext/filters/deadline/deadline_filter.cc +83 -77
  50. data/src/core/ext/filters/deadline/deadline_filter.h +7 -11
  51. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -1
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -3
  53. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  54. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +17 -3
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -7
  57. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +4 -24
  58. data/src/core/ext/transport/chttp2/transport/flow_control.h +2 -2
  59. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
  60. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +12 -8
  61. data/src/core/ext/transport/chttp2/transport/internal.h +0 -1
  62. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
  63. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -2
  64. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +38 -0
  65. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.h +30 -0
  66. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c +41 -0
  67. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.h +35 -0
  68. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +254 -0
  69. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +105 -0
  70. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +100 -0
  71. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +45 -0
  72. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +558 -0
  73. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +145 -0
  74. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c +53 -0
  75. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.h +35 -0
  76. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +133 -0
  77. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.h +35 -0
  78. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c +127 -0
  79. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.h +65 -0
  80. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c +56 -0
  81. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.h +35 -0
  82. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +266 -0
  83. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +125 -0
  84. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +143 -0
  85. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +55 -0
  86. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c +56 -0
  87. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.h +35 -0
  88. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +66 -0
  89. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +40 -0
  90. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +263 -0
  91. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.h +100 -0
  92. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +233 -0
  93. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +70 -0
  94. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c +56 -0
  95. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.h +35 -0
  96. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +228 -0
  97. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +80 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +46 -0
  99. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.h +35 -0
  100. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c +59 -0
  101. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.h +35 -0
  102. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +55 -0
  103. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.h +35 -0
  104. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +110 -0
  105. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.h +50 -0
  106. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +113 -0
  107. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +50 -0
  108. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c +146 -0
  109. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.h +55 -0
  110. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c +50 -0
  111. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.h +35 -0
  112. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +190 -0
  113. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +55 -0
  114. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +185 -0
  115. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.h +65 -0
  116. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +62 -0
  117. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.h +40 -0
  118. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +97 -0
  119. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +40 -0
  120. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +915 -0
  121. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +280 -0
  122. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c +71 -0
  123. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.h +45 -0
  124. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +64 -0
  125. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.h +40 -0
  126. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +511 -0
  127. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +115 -0
  128. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -0
  129. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +30 -0
  130. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +166 -0
  131. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +55 -0
  132. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +105 -0
  133. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +45 -0
  134. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +249 -0
  135. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +60 -0
  136. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c +72 -0
  137. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.h +35 -0
  138. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c +60 -0
  139. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.h +35 -0
  140. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +152 -0
  141. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +60 -0
  142. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +83 -0
  143. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.h +35 -0
  144. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +82 -0
  145. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.h +35 -0
  146. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +83 -0
  147. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.h +40 -0
  148. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +86 -0
  149. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.h +35 -0
  150. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c +74 -0
  151. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.h +35 -0
  152. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +64 -0
  153. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.h +40 -0
  154. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c +54 -0
  155. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.h +35 -0
  156. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c +53 -0
  157. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.h +35 -0
  158. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +73 -0
  159. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.h +45 -0
  160. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +72 -0
  161. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.h +40 -0
  162. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c +81 -0
  163. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.h +45 -0
  164. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c +92 -0
  165. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.h +65 -0
  166. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c +95 -0
  167. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.h +55 -0
  168. data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c +34 -0
  169. data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.h +30 -0
  170. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c +59 -0
  171. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.h +40 -0
  172. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c +54 -0
  173. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.h +45 -0
  174. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c +47 -0
  175. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.h +35 -0
  176. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c +40 -0
  177. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.h +30 -0
  178. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.c +61 -0
  179. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.h +45 -0
  180. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c +38 -0
  181. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.h +35 -0
  182. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +386 -0
  183. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.h +165 -0
  184. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c +39 -0
  185. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.h +35 -0
  186. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c +37 -0
  187. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.h +35 -0
  188. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c +65 -0
  189. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.h +50 -0
  190. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c +39 -0
  191. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.h +35 -0
  192. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c +66 -0
  193. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.h +75 -0
  194. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +42 -0
  195. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.h +35 -0
  196. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +70 -0
  197. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.h +45 -0
  198. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +56 -0
  199. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.h +35 -0
  200. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +33 -0
  201. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.h +30 -0
  202. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +49 -0
  203. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.h +35 -0
  204. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +43 -0
  205. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.h +35 -0
  206. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +42 -0
  207. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +35 -0
  208. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +62 -0
  209. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +40 -0
  210. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +45 -0
  211. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +40 -0
  212. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +49 -0
  213. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +35 -0
  214. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +68 -0
  215. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +40 -0
  216. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +51 -0
  217. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +35 -0
  218. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +307 -0
  219. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.h +145 -0
  220. data/src/core/ext/xds/certificate_provider_factory.h +7 -5
  221. data/src/core/ext/xds/certificate_provider_store.cc +84 -0
  222. data/src/core/ext/xds/certificate_provider_store.h +65 -8
  223. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +119 -0
  224. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +72 -0
  225. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +28 -140
  226. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +6 -4
  227. data/src/core/ext/xds/xds_api.cc +241 -718
  228. data/src/core/ext/xds/xds_api.h +50 -9
  229. data/src/core/ext/xds/xds_bootstrap.cc +172 -25
  230. data/src/core/ext/xds/xds_bootstrap.h +23 -7
  231. data/src/core/ext/xds/xds_certificate_provider.cc +240 -0
  232. data/src/core/ext/xds/xds_certificate_provider.h +74 -0
  233. data/src/core/ext/xds/xds_client.cc +161 -128
  234. data/src/core/ext/xds/xds_client.h +12 -11
  235. data/src/core/ext/xds/xds_client_stats.cc +41 -4
  236. data/src/core/ext/xds/xds_client_stats.h +2 -2
  237. data/src/core/lib/channel/channel_args.cc +2 -1
  238. data/src/core/lib/channel/channel_trace.cc +4 -2
  239. data/src/core/lib/channel/channelz.h +2 -2
  240. data/src/core/lib/channel/handshaker.h +2 -2
  241. data/src/core/lib/compression/compression.cc +8 -4
  242. data/src/core/lib/compression/compression_internal.cc +10 -5
  243. data/src/core/lib/compression/compression_internal.h +2 -1
  244. data/src/core/lib/compression/stream_compression_identity.cc +1 -3
  245. data/src/core/lib/debug/stats_data.cc +1 -0
  246. data/src/core/lib/gpr/cpu_iphone.cc +10 -2
  247. data/src/core/lib/gpr/log_linux.cc +17 -3
  248. data/src/core/lib/gpr/log_posix.cc +13 -1
  249. data/src/core/lib/gpr/log_windows.cc +16 -4
  250. data/src/core/lib/gpr/murmur_hash.cc +1 -1
  251. data/src/core/lib/gpr/string.cc +1 -1
  252. data/src/core/lib/gpr/time_precise.cc +3 -2
  253. data/src/core/lib/gpr/tls.h +4 -0
  254. data/src/core/lib/gpr/tls_msvc.h +2 -0
  255. data/src/core/lib/gpr/tls_stdcpp.h +48 -0
  256. data/src/core/lib/gpr/useful.h +5 -4
  257. data/src/core/lib/gprpp/dual_ref_counted.h +44 -49
  258. data/src/core/lib/gprpp/examine_stack.cc +43 -0
  259. data/src/core/lib/gprpp/examine_stack.h +46 -0
  260. data/src/core/lib/gprpp/fork.cc +2 -2
  261. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  262. data/src/core/lib/gprpp/orphanable.h +4 -8
  263. data/src/core/lib/gprpp/ref_counted.h +40 -46
  264. data/src/core/lib/gprpp/ref_counted_ptr.h +9 -11
  265. data/src/core/lib/{security/authorization/mock_cel/statusor.h → gprpp/stat.h} +13 -25
  266. data/src/core/lib/gprpp/stat_posix.cc +49 -0
  267. data/src/core/lib/gprpp/stat_windows.cc +48 -0
  268. data/src/core/lib/gprpp/thd.h +2 -2
  269. data/src/core/lib/gprpp/thd_posix.cc +36 -36
  270. data/src/core/lib/http/parser.cc +46 -25
  271. data/src/core/lib/iomgr/error.cc +2 -1
  272. data/src/core/lib/iomgr/ev_epollex_linux.cc +8 -4
  273. data/src/core/lib/iomgr/exec_ctx.cc +1 -1
  274. data/src/core/lib/iomgr/executor/mpmcqueue.h +5 -5
  275. data/src/core/lib/iomgr/executor/threadpool.h +3 -3
  276. data/src/core/lib/iomgr/parse_address.cc +84 -6
  277. data/src/core/lib/iomgr/parse_address.h +20 -0
  278. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +2 -1
  279. data/src/core/lib/iomgr/python_util.h +3 -3
  280. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -5
  281. data/src/core/lib/iomgr/tcp_posix.cc +3 -2
  282. data/src/core/lib/iomgr/timer_custom.cc +2 -2
  283. data/src/core/lib/iomgr/unix_sockets_posix.cc +27 -15
  284. data/src/core/lib/iomgr/unix_sockets_posix.h +5 -0
  285. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +7 -0
  286. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -2
  287. data/src/core/lib/json/json.h +2 -2
  288. data/src/core/lib/json/json_reader.cc +8 -4
  289. data/src/core/lib/json/json_util.h +167 -0
  290. data/src/core/lib/json/json_writer.cc +2 -1
  291. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +3 -1
  292. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +5 -4
  293. data/src/core/lib/security/authorization/mock_cel/cel_value.h +4 -0
  294. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +6 -6
  295. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +10 -9
  296. data/src/core/lib/security/context/security_context.h +3 -1
  297. data/src/core/lib/security/credentials/credentials.cc +1 -1
  298. data/src/core/lib/security/credentials/credentials.h +3 -3
  299. data/src/core/lib/security/credentials/external/aws_request_signer.cc +208 -0
  300. data/src/core/lib/security/credentials/external/aws_request_signer.h +73 -0
  301. data/src/core/lib/security/credentials/external/external_account_credentials.cc +311 -0
  302. data/src/core/lib/security/credentials/external/external_account_credentials.h +118 -0
  303. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +136 -0
  304. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +49 -0
  305. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +211 -0
  306. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +59 -0
  307. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +51 -0
  308. data/src/core/lib/security/credentials/jwt/json_token.cc +5 -2
  309. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +4 -3
  310. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +5 -1
  311. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  312. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +35 -5
  313. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +12 -8
  314. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +78 -0
  315. data/src/core/lib/security/{certificate_provider.h → credentials/tls/grpc_tls_certificate_provider.h} +32 -18
  316. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +77 -149
  317. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +58 -187
  318. data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -12
  319. data/src/core/lib/security/credentials/tls/tls_credentials.h +2 -2
  320. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +2 -2
  321. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +88 -0
  322. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +70 -0
  323. data/src/core/lib/security/security_connector/load_system_roots.h +4 -0
  324. data/src/core/lib/security/security_connector/load_system_roots_linux.h +2 -0
  325. data/src/core/lib/security/security_connector/local/local_security_connector.cc +2 -2
  326. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  327. data/src/core/lib/security/security_connector/security_connector.h +4 -2
  328. data/src/core/lib/security/security_connector/ssl_utils.h +4 -2
  329. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +293 -275
  330. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +106 -61
  331. data/src/core/lib/security/transport/security_handshaker.cc +1 -1
  332. data/src/core/lib/security/transport/server_auth_filter.cc +2 -1
  333. data/src/core/lib/security/util/json_util.h +1 -0
  334. data/src/core/lib/slice/slice.cc +7 -4
  335. data/src/core/lib/slice/slice_buffer.cc +2 -1
  336. data/src/core/lib/slice/slice_intern.cc +2 -2
  337. data/src/core/lib/surface/call.cc +9 -8
  338. data/src/core/lib/surface/completion_queue.cc +7 -6
  339. data/src/core/lib/surface/server.cc +4 -2
  340. data/src/core/lib/surface/server.h +2 -2
  341. data/src/core/lib/surface/validate_metadata.h +3 -0
  342. data/src/core/lib/surface/version.cc +2 -2
  343. data/src/core/lib/transport/authority_override.h +2 -0
  344. data/src/core/lib/transport/bdp_estimator.cc +1 -1
  345. data/src/core/lib/transport/byte_stream.h +3 -3
  346. data/src/core/lib/transport/connectivity_state.h +3 -3
  347. data/src/core/lib/transport/metadata.h +2 -2
  348. data/src/core/lib/transport/timeout_encoding.cc +4 -4
  349. data/src/core/lib/transport/transport.cc +5 -3
  350. data/src/core/lib/transport/transport.h +1 -1
  351. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
  352. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +4 -3
  353. data/src/core/tsi/fake_transport_security.cc +1 -0
  354. data/src/core/tsi/local_transport_security.cc +5 -1
  355. data/src/core/tsi/local_transport_security.h +6 -7
  356. data/src/core/tsi/ssl/session_cache/ssl_session.h +3 -0
  357. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -1
  358. data/src/core/tsi/ssl_transport_security.cc +14 -7
  359. data/src/core/tsi/ssl_transport_security.h +3 -0
  360. data/src/core/tsi/transport_security.cc +4 -2
  361. data/src/ruby/ext/grpc/extconf.rb +1 -1
  362. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +22 -14
  363. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -24
  364. data/src/ruby/lib/grpc/version.rb +1 -1
  365. data/third_party/abseil-cpp/absl/algorithm/container.h +59 -22
  366. data/third_party/abseil-cpp/absl/base/attributes.h +99 -38
  367. data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
  368. data/third_party/abseil-cpp/absl/base/casts.h +9 -6
  369. data/third_party/abseil-cpp/absl/base/config.h +60 -17
  370. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +428 -335
  371. data/third_party/abseil-cpp/absl/base/internal/bits.h +17 -16
  372. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +5 -0
  373. data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +398 -0
  374. data/third_party/abseil-cpp/absl/base/internal/invoke.h +4 -4
  375. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +1 -1
  376. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +29 -1
  377. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +2 -2
  378. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +7 -5
  379. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +25 -38
  380. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +19 -25
  381. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +8 -0
  382. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +28 -5
  383. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +8 -0
  384. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +3 -1
  385. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +2 -2
  386. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +3 -3
  387. data/third_party/abseil-cpp/absl/base/macros.h +36 -109
  388. data/third_party/abseil-cpp/absl/base/optimization.h +61 -1
  389. data/third_party/abseil-cpp/absl/base/options.h +31 -4
  390. data/third_party/abseil-cpp/absl/base/policy_checks.h +1 -1
  391. data/third_party/abseil-cpp/absl/base/thread_annotations.h +94 -39
  392. data/third_party/abseil-cpp/absl/container/fixed_array.h +42 -25
  393. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +2 -1
  394. data/third_party/abseil-cpp/absl/container/inlined_vector.h +33 -36
  395. data/third_party/abseil-cpp/absl/container/internal/common.h +6 -2
  396. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +33 -8
  397. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +49 -29
  398. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +15 -0
  399. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +24 -7
  400. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -1
  401. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +35 -11
  402. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +10 -9
  403. data/third_party/abseil-cpp/absl/container/internal/layout.h +7 -5
  404. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +55 -34
  405. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +5 -4
  406. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +66 -16
  407. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +4 -0
  408. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +13 -4
  409. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +43 -24
  410. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +12 -3
  411. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +10 -2
  412. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +22 -1
  413. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +0 -21
  414. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +12 -1
  415. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +101 -0
  416. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +100 -20
  417. data/third_party/abseil-cpp/absl/functional/bind_front.h +184 -0
  418. data/third_party/abseil-cpp/absl/functional/function_ref.h +1 -1
  419. data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +95 -0
  420. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +2 -2
  421. data/third_party/abseil-cpp/absl/hash/hash.h +6 -5
  422. data/third_party/abseil-cpp/absl/hash/internal/hash.h +73 -65
  423. data/third_party/abseil-cpp/absl/memory/memory.h +4 -0
  424. data/third_party/abseil-cpp/absl/meta/type_traits.h +2 -8
  425. data/third_party/abseil-cpp/absl/numeric/int128.cc +13 -27
  426. data/third_party/abseil-cpp/absl/numeric/int128.h +16 -15
  427. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +51 -0
  428. data/third_party/abseil-cpp/absl/status/status.cc +4 -6
  429. data/third_party/abseil-cpp/absl/status/status.h +502 -113
  430. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +5 -10
  431. data/third_party/abseil-cpp/absl/strings/charconv.cc +2 -2
  432. data/third_party/abseil-cpp/absl/strings/cord.cc +91 -112
  433. data/third_party/abseil-cpp/absl/strings/cord.h +360 -205
  434. data/third_party/abseil-cpp/absl/strings/escaping.cc +9 -9
  435. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +1 -1
  436. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
  437. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +2 -2
  438. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +2 -2
  439. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +45 -23
  440. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +222 -136
  441. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +136 -64
  442. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +1 -1
  443. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +14 -21
  444. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +7 -14
  445. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +31 -7
  446. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +147 -135
  447. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +999 -87
  448. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +3 -3
  449. data/third_party/abseil-cpp/absl/strings/internal/str_format/output.h +4 -12
  450. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +8 -6
  451. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +13 -11
  452. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +2 -2
  453. data/third_party/abseil-cpp/absl/strings/str_cat.cc +4 -4
  454. data/third_party/abseil-cpp/absl/strings/str_cat.h +1 -1
  455. data/third_party/abseil-cpp/absl/strings/str_format.h +289 -13
  456. data/third_party/abseil-cpp/absl/strings/str_split.cc +2 -2
  457. data/third_party/abseil-cpp/absl/strings/str_split.h +1 -0
  458. data/third_party/abseil-cpp/absl/strings/string_view.h +26 -19
  459. data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -5
  460. data/third_party/abseil-cpp/absl/strings/substitute.h +32 -29
  461. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +3 -3
  462. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +3 -3
  463. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +28 -28
  464. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +4 -16
  465. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +1 -1
  466. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +8 -0
  467. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -2
  468. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +75 -64
  469. data/third_party/abseil-cpp/absl/synchronization/mutex.h +15 -6
  470. data/third_party/abseil-cpp/absl/time/civil_time.cc +9 -9
  471. data/third_party/abseil-cpp/absl/time/clock.cc +3 -3
  472. data/third_party/abseil-cpp/absl/time/duration.cc +90 -59
  473. data/third_party/abseil-cpp/absl/time/format.cc +43 -36
  474. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +26 -16
  475. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +4 -2
  476. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +1 -1
  477. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +136 -29
  478. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +13 -21
  479. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +1 -1
  480. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +136 -129
  481. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +4 -5
  482. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +8 -7
  483. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -6
  484. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +2 -1
  485. data/third_party/abseil-cpp/absl/time/time.h +15 -16
  486. data/third_party/abseil-cpp/absl/types/internal/variant.h +4 -4
  487. data/third_party/abseil-cpp/absl/types/optional.h +9 -9
  488. data/third_party/abseil-cpp/absl/types/span.h +49 -36
  489. data/third_party/abseil-cpp/absl/utility/utility.h +2 -2
  490. data/third_party/address_sorting/include/address_sorting/address_sorting.h +2 -0
  491. data/third_party/boringssl-with-bazel/err_data.c +340 -336
  492. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +2 -0
  493. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +173 -35
  494. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +46 -7
  495. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +8 -2
  496. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +90 -63
  497. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +60 -60
  498. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +179 -47
  499. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +766 -0
  500. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +10 -0
  501. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +5 -3
  502. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +14 -14
  503. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
  504. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +24 -0
  505. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +7 -5
  506. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +5 -2
  507. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +4 -0
  508. data/third_party/boringssl-with-bazel/src/include/openssl/des.h +6 -0
  509. data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +3 -0
  510. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +202 -134
  511. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +55 -1
  512. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
  513. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +31 -23
  514. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +435 -394
  515. data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +18 -5
  516. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +35 -0
  517. data/third_party/boringssl-with-bazel/src/ssl/internal.h +36 -1
  518. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +42 -1
  519. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +67 -0
  520. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +11 -14
  521. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +216 -11
  522. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +53 -11
  523. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +133 -39
  524. data/third_party/upb/upb/def.c +2169 -0
  525. data/third_party/upb/upb/def.h +330 -0
  526. data/third_party/upb/upb/def.hpp +525 -0
  527. data/third_party/upb/upb/reflection.c +391 -0
  528. data/third_party/upb/upb/reflection.h +168 -0
  529. data/third_party/upb/upb/text_encode.c +398 -0
  530. data/third_party/upb/upb/text_encode.h +35 -0
  531. metadata +227 -37
  532. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +0 -571
  533. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +0 -129
@@ -16,26 +16,21 @@
16
16
  #include <atomic>
17
17
 
18
18
  #include "absl/base/attributes.h"
19
+ #include "absl/base/internal/atomic_hook.h"
19
20
 
20
21
  namespace absl {
21
22
  ABSL_NAMESPACE_BEGIN
22
23
  namespace status_internal {
23
24
 
24
- namespace {
25
- // Tried constant initialized global variable but it doesn't work with Lexan
26
- // (MSVC's `std::atomic` has trouble constant initializing).
27
- std::atomic<StatusPayloadPrinter>& GetStatusPayloadPrinterStorage() {
28
- ABSL_CONST_INIT static std::atomic<StatusPayloadPrinter> instance{nullptr};
29
- return instance;
30
- }
31
- } // namespace
25
+ ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
26
+ static absl::base_internal::AtomicHook<StatusPayloadPrinter> storage;
32
27
 
33
28
  void SetStatusPayloadPrinter(StatusPayloadPrinter printer) {
34
- GetStatusPayloadPrinterStorage().store(printer, std::memory_order_relaxed);
29
+ storage.Store(printer);
35
30
  }
36
31
 
37
32
  StatusPayloadPrinter GetStatusPayloadPrinter() {
38
- return GetStatusPayloadPrinterStorage().load(std::memory_order_relaxed);
33
+ return storage.Load();
39
34
  }
40
35
 
41
36
  } // namespace status_internal
@@ -619,10 +619,10 @@ from_chars_result FromCharsImpl(const char* first, const char* last,
619
619
  // Either we failed to parse a hex float after the "0x", or we read
620
620
  // "0xinf" or "0xnan" which we don't want to match.
621
621
  //
622
- // However, a std::string that begins with "0x" also begins with "0", which
622
+ // However, a string that begins with "0x" also begins with "0", which
623
623
  // is normally a valid match for the number zero. So we want these
624
624
  // strings to match zero unless fmt_flags is `scientific`. (This flag
625
- // means an exponent is required, which the std::string "0" does not have.)
625
+ // means an exponent is required, which the string "0" does not have.)
626
626
  if (fmt_flags == chars_format::scientific) {
627
627
  result.ec = std::errc::invalid_argument;
628
628
  } else {
@@ -15,10 +15,12 @@
15
15
  #include "absl/strings/cord.h"
16
16
 
17
17
  #include <algorithm>
18
+ #include <atomic>
18
19
  #include <cstddef>
19
20
  #include <cstdio>
20
21
  #include <cstdlib>
21
22
  #include <iomanip>
23
+ #include <iostream>
22
24
  #include <limits>
23
25
  #include <ostream>
24
26
  #include <sstream>
@@ -28,6 +30,7 @@
28
30
 
29
31
  #include "absl/base/casts.h"
30
32
  #include "absl/base/internal/raw_logging.h"
33
+ #include "absl/base/macros.h"
31
34
  #include "absl/base/port.h"
32
35
  #include "absl/container/fixed_array.h"
33
36
  #include "absl/container/inlined_vector.h"
@@ -58,48 +61,6 @@ enum CordRepKind {
58
61
  FLAT = 3,
59
62
  };
60
63
 
61
- namespace {
62
-
63
- // Type used with std::allocator for allocating and deallocating
64
- // `CordRepExternal`. std::allocator is used because it opaquely handles the
65
- // different new / delete overloads available on a given platform.
66
- struct alignas(absl::cord_internal::ExternalRepAlignment()) ExternalAllocType {
67
- unsigned char value[absl::cord_internal::ExternalRepAlignment()];
68
- };
69
-
70
- // Returns the number of objects to pass in to std::allocator<ExternalAllocType>
71
- // allocate() and deallocate() to create enough room for `CordRepExternal` with
72
- // `releaser_size` bytes on the end.
73
- constexpr size_t GetExternalAllocNumObjects(size_t releaser_size) {
74
- // Be sure to round up since `releaser_size` could be smaller than
75
- // `sizeof(ExternalAllocType)`.
76
- return (sizeof(CordRepExternal) + releaser_size + sizeof(ExternalAllocType) -
77
- 1) /
78
- sizeof(ExternalAllocType);
79
- }
80
-
81
- // Allocates enough memory for `CordRepExternal` and a releaser with size
82
- // `releaser_size` bytes.
83
- void* AllocateExternal(size_t releaser_size) {
84
- return std::allocator<ExternalAllocType>().allocate(
85
- GetExternalAllocNumObjects(releaser_size));
86
- }
87
-
88
- // Deallocates the memory for a `CordRepExternal` assuming it was allocated with
89
- // a releaser of given size and alignment.
90
- void DeallocateExternal(CordRepExternal* p, size_t releaser_size) {
91
- std::allocator<ExternalAllocType>().deallocate(
92
- reinterpret_cast<ExternalAllocType*>(p),
93
- GetExternalAllocNumObjects(releaser_size));
94
- }
95
-
96
- // Returns a pointer to the type erased releaser for the given CordRepExternal.
97
- void* GetExternalReleaser(CordRepExternal* rep) {
98
- return rep + 1;
99
- }
100
-
101
- } // namespace
102
-
103
64
  namespace cord_internal {
104
65
 
105
66
  inline CordRepConcat* CordRep::concat() {
@@ -136,8 +97,6 @@ inline const CordRepExternal* CordRep::external() const {
136
97
 
137
98
  static const size_t kFlatOverhead = offsetof(CordRep, data);
138
99
 
139
- static_assert(kFlatOverhead == 13, "Unittests assume kFlatOverhead == 13");
140
-
141
100
  // Largest and smallest flat node lengths we are willing to allocate
142
101
  // Flat allocation size is stored in tag, which currently can encode sizes up
143
102
  // to 4K, encoded as multiple of either 8 or 32 bytes.
@@ -195,52 +154,18 @@ static_assert(Fibonacci(63) == 6557470319842,
195
154
  // The root node depth is allowed to become twice as large to reduce rebalancing
196
155
  // for larger strings (see IsRootBalanced).
197
156
  static constexpr uint64_t min_length[] = {
198
- Fibonacci(2),
199
- Fibonacci(3),
200
- Fibonacci(4),
201
- Fibonacci(5),
202
- Fibonacci(6),
203
- Fibonacci(7),
204
- Fibonacci(8),
205
- Fibonacci(9),
206
- Fibonacci(10),
207
- Fibonacci(11),
208
- Fibonacci(12),
209
- Fibonacci(13),
210
- Fibonacci(14),
211
- Fibonacci(15),
212
- Fibonacci(16),
213
- Fibonacci(17),
214
- Fibonacci(18),
215
- Fibonacci(19),
216
- Fibonacci(20),
217
- Fibonacci(21),
218
- Fibonacci(22),
219
- Fibonacci(23),
220
- Fibonacci(24),
221
- Fibonacci(25),
222
- Fibonacci(26),
223
- Fibonacci(27),
224
- Fibonacci(28),
225
- Fibonacci(29),
226
- Fibonacci(30),
227
- Fibonacci(31),
228
- Fibonacci(32),
229
- Fibonacci(33),
230
- Fibonacci(34),
231
- Fibonacci(35),
232
- Fibonacci(36),
233
- Fibonacci(37),
234
- Fibonacci(38),
235
- Fibonacci(39),
236
- Fibonacci(40),
237
- Fibonacci(41),
238
- Fibonacci(42),
239
- Fibonacci(43),
240
- Fibonacci(44),
241
- Fibonacci(45),
242
- Fibonacci(46),
243
- Fibonacci(47),
157
+ Fibonacci(2), Fibonacci(3), Fibonacci(4), Fibonacci(5),
158
+ Fibonacci(6), Fibonacci(7), Fibonacci(8), Fibonacci(9),
159
+ Fibonacci(10), Fibonacci(11), Fibonacci(12), Fibonacci(13),
160
+ Fibonacci(14), Fibonacci(15), Fibonacci(16), Fibonacci(17),
161
+ Fibonacci(18), Fibonacci(19), Fibonacci(20), Fibonacci(21),
162
+ Fibonacci(22), Fibonacci(23), Fibonacci(24), Fibonacci(25),
163
+ Fibonacci(26), Fibonacci(27), Fibonacci(28), Fibonacci(29),
164
+ Fibonacci(30), Fibonacci(31), Fibonacci(32), Fibonacci(33),
165
+ Fibonacci(34), Fibonacci(35), Fibonacci(36), Fibonacci(37),
166
+ Fibonacci(38), Fibonacci(39), Fibonacci(40), Fibonacci(41),
167
+ Fibonacci(42), Fibonacci(43), Fibonacci(44), Fibonacci(45),
168
+ Fibonacci(46), Fibonacci(47),
244
169
  0xffffffffffffffffull, // Avoid overflow
245
170
  };
246
171
 
@@ -337,11 +262,7 @@ static void UnrefInternal(CordRep* rep) {
337
262
  }
338
263
  } else if (rep->tag == EXTERNAL) {
339
264
  CordRepExternal* rep_external = rep->external();
340
- absl::string_view data(rep_external->base, rep->length);
341
- void* releaser = GetExternalReleaser(rep_external);
342
- size_t releaser_size = rep_external->releaser_invoker(releaser, data);
343
- rep_external->~CordRepExternal();
344
- DeallocateExternal(rep_external, releaser_size);
265
+ rep_external->releaser_invoker(rep_external);
345
266
  rep = nullptr;
346
267
  } else if (rep->tag == SUBSTRING) {
347
268
  CordRepSubstring* rep_substring = rep->substring();
@@ -491,18 +412,12 @@ static CordRep* NewTree(const char* data,
491
412
 
492
413
  namespace cord_internal {
493
414
 
494
- ExternalRepReleaserPair NewExternalWithUninitializedReleaser(
495
- absl::string_view data, ExternalReleaserInvoker invoker,
496
- size_t releaser_size) {
415
+ void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep) {
497
416
  assert(!data.empty());
498
-
499
- void* raw_rep = AllocateExternal(releaser_size);
500
- auto* rep = new (raw_rep) CordRepExternal();
501
417
  rep->length = data.size();
502
418
  rep->tag = EXTERNAL;
503
419
  rep->base = data.data();
504
- rep->releaser_invoker = invoker;
505
- return {VerifyTree(rep), GetExternalReleaser(rep)};
420
+ VerifyTree(rep);
506
421
  }
507
422
 
508
423
  } // namespace cord_internal
@@ -526,10 +441,7 @@ static CordRep* NewSubstring(CordRep* child, size_t offset, size_t length) {
526
441
  // --------------------------------------------------------------------
527
442
  // Cord::InlineRep functions
528
443
 
529
- // This will trigger LNK2005 in MSVC.
530
- #ifndef COMPILER_MSVC
531
- const unsigned char Cord::InlineRep::kMaxInline;
532
- #endif // COMPILER_MSVC
444
+ constexpr unsigned char Cord::InlineRep::kMaxInline;
533
445
 
534
446
  inline void Cord::InlineRep::set_data(const char* data, size_t n,
535
447
  bool nullify_tail) {
@@ -585,7 +497,7 @@ void Cord::InlineRep::AppendTree(CordRep* tree) {
585
497
  }
586
498
 
587
499
  void Cord::InlineRep::PrependTree(CordRep* tree) {
588
- if (tree == nullptr) return;
500
+ assert(tree != nullptr);
589
501
  size_t len = data_[kMaxInline];
590
502
  if (len == 0) {
591
503
  set_tree(tree);
@@ -738,6 +650,37 @@ Cord::Cord(absl::string_view src) {
738
650
  }
739
651
  }
740
652
 
653
+ template <typename T, Cord::EnableIfString<T>>
654
+ Cord::Cord(T&& src) {
655
+ if (
656
+ // String is short: copy data to avoid external block overhead.
657
+ src.size() <= kMaxBytesToCopy ||
658
+ // String is wasteful: copy data to avoid pinning too much unused memory.
659
+ src.size() < src.capacity() / 2
660
+ ) {
661
+ if (src.size() <= InlineRep::kMaxInline) {
662
+ contents_.set_data(src.data(), src.size(), false);
663
+ } else {
664
+ contents_.set_tree(NewTree(src.data(), src.size(), 0));
665
+ }
666
+ } else {
667
+ struct StringReleaser {
668
+ void operator()(absl::string_view /* data */) {}
669
+ std::string data;
670
+ };
671
+ const absl::string_view original_data = src;
672
+ auto* rep = static_cast<
673
+ ::absl::cord_internal::CordRepExternalImpl<StringReleaser>*>(
674
+ absl::cord_internal::NewExternalRep(
675
+ original_data, StringReleaser{std::forward<T>(src)}));
676
+ // Moving src may have invalidated its data pointer, so adjust it.
677
+ rep->base = rep->template get<0>().data.data();
678
+ contents_.set_tree(rep);
679
+ }
680
+ }
681
+
682
+ template Cord::Cord(std::string&& src);
683
+
741
684
  // The destruction code is separate so that the compiler can determine
742
685
  // that it does not need to call the destructor on a moved-from Cord.
743
686
  void Cord::DestroyCordSlow() {
@@ -775,6 +718,18 @@ Cord& Cord::operator=(absl::string_view src) {
775
718
  return *this;
776
719
  }
777
720
 
721
+ template <typename T, Cord::EnableIfString<T>>
722
+ Cord& Cord::operator=(T&& src) {
723
+ if (src.size() <= kMaxBytesToCopy) {
724
+ *this = absl::string_view(src);
725
+ } else {
726
+ *this = Cord(std::forward<T>(src));
727
+ }
728
+ return *this;
729
+ }
730
+
731
+ template Cord& Cord::operator=(std::string&& src);
732
+
778
733
  // TODO(sanjay): Move to Cord::InlineRep section of file. For now,
779
734
  // we keep it here to make diffs easier.
780
735
  void Cord::InlineRep::AppendArray(const char* src_data, size_t src_size) {
@@ -886,6 +841,17 @@ void Cord::Append(const Cord& src) { AppendImpl(src); }
886
841
 
887
842
  void Cord::Append(Cord&& src) { AppendImpl(std::move(src)); }
888
843
 
844
+ template <typename T, Cord::EnableIfString<T>>
845
+ void Cord::Append(T&& src) {
846
+ if (src.size() <= kMaxBytesToCopy) {
847
+ Append(absl::string_view(src));
848
+ } else {
849
+ Append(Cord(std::forward<T>(src)));
850
+ }
851
+ }
852
+
853
+ template void Cord::Append(std::string&& src);
854
+
889
855
  void Cord::Prepend(const Cord& src) {
890
856
  CordRep* src_tree = src.contents_.tree();
891
857
  if (src_tree != nullptr) {
@@ -915,6 +881,17 @@ void Cord::Prepend(absl::string_view src) {
915
881
  }
916
882
  }
917
883
 
884
+ template <typename T, Cord::EnableIfString<T>>
885
+ inline void Cord::Prepend(T&& src) {
886
+ if (src.size() <= kMaxBytesToCopy) {
887
+ Prepend(absl::string_view(src));
888
+ } else {
889
+ Prepend(Cord(std::forward<T>(src)));
890
+ }
891
+ }
892
+
893
+ template void Cord::Prepend(std::string&& src);
894
+
918
895
  static CordRep* RemovePrefixFrom(CordRep* node, size_t n) {
919
896
  if (n >= node->length) return nullptr;
920
897
  if (n == 0) return Ref(node);
@@ -1175,7 +1152,7 @@ class CordForest {
1175
1152
  void AddNode(CordRep* node) {
1176
1153
  CordRep* sum = nullptr;
1177
1154
 
1178
- // Collect together everything with which we will merge node
1155
+ // Collect together everything with which we will merge with node
1179
1156
  int i = 0;
1180
1157
  for (; node->length > min_length[i + 1]; ++i) {
1181
1158
  auto& tree_at_i = trees_[i];
@@ -1506,7 +1483,8 @@ void Cord::CopyToArraySlowPath(char* dst) const {
1506
1483
  }
1507
1484
 
1508
1485
  Cord::ChunkIterator& Cord::ChunkIterator::operator++() {
1509
- assert(bytes_remaining_ > 0 && "Attempted to iterate past `end()`");
1486
+ ABSL_HARDENING_ASSERT(bytes_remaining_ > 0 &&
1487
+ "Attempted to iterate past `end()`");
1510
1488
  assert(bytes_remaining_ >= current_chunk_.size());
1511
1489
  bytes_remaining_ -= current_chunk_.size();
1512
1490
 
@@ -1545,7 +1523,8 @@ Cord::ChunkIterator& Cord::ChunkIterator::operator++() {
1545
1523
  }
1546
1524
 
1547
1525
  Cord Cord::ChunkIterator::AdvanceAndReadBytes(size_t n) {
1548
- assert(bytes_remaining_ >= n && "Attempted to iterate past `end()`");
1526
+ ABSL_HARDENING_ASSERT(bytes_remaining_ >= n &&
1527
+ "Attempted to iterate past `end()`");
1549
1528
  Cord subcord;
1550
1529
 
1551
1530
  if (n <= InlineRep::kMaxInline) {
@@ -1716,7 +1695,7 @@ void Cord::ChunkIterator::AdvanceBytesSlowPath(size_t n) {
1716
1695
  }
1717
1696
 
1718
1697
  char Cord::operator[](size_t i) const {
1719
- assert(i < size());
1698
+ ABSL_HARDENING_ASSERT(i < size());
1720
1699
  size_t offset = i;
1721
1700
  const CordRep* rep = contents_.tree();
1722
1701
  if (rep == nullptr) {
@@ -11,25 +11,52 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
-
15
- // A Cord is a sequence of characters with some unusual access propreties.
16
- // A Cord supports efficient insertions and deletions at the start and end of
17
- // the byte sequence, but random access reads are slower, and random access
18
- // modifications are not supported by the API. Cord also provides cheap copies
19
- // (using a copy-on-write strategy) and cheap substring operations.
20
14
  //
21
- // Thread safety
22
- // -------------
15
+ // -----------------------------------------------------------------------------
16
+ // File: cord.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file defines the `absl::Cord` data structure and operations on that data
20
+ // structure. A Cord is a string-like sequence of characters optimized for
21
+ // specific use cases. Unlike a `std::string`, which stores an array of
22
+ // contiguous characters, Cord data is stored in a structure consisting of
23
+ // separate, reference-counted "chunks." (Currently, this implementation is a
24
+ // tree structure, though that implementation may change.)
25
+ //
26
+ // Because a Cord consists of these chunks, data can be added to or removed from
27
+ // a Cord during its lifetime. Chunks may also be shared between Cords. Unlike a
28
+ // `std::string`, a Cord can therefore accomodate data that changes over its
29
+ // lifetime, though it's not quite "mutable"; it can change only in the
30
+ // attachment, detachment, or rearrangement of chunks of its constituent data.
31
+ //
32
+ // A Cord provides some benefit over `std::string` under the following (albeit
33
+ // narrow) circumstances:
34
+ //
35
+ // * Cord data is designed to grow and shrink over a Cord's lifetime. Cord
36
+ // provides efficient insertions and deletions at the start and end of the
37
+ // character sequences, avoiding copies in those cases. Static data should
38
+ // generally be stored as strings.
39
+ // * External memory consisting of string-like data can be directly added to
40
+ // a Cord without requiring copies or allocations.
41
+ // * Cord data may be shared and copied cheaply. Cord provides a copy-on-write
42
+ // implementation and cheap sub-Cord operations. Copying a Cord is an O(1)
43
+ // operation.
44
+ //
45
+ // As a consequence to the above, Cord data is generally large. Small data
46
+ // should generally use strings, as construction of a Cord requires some
47
+ // overhead. Small Cords (<= 15 bytes) are represented inline, but most small
48
+ // Cords are expected to grow over their lifetimes.
49
+ //
50
+ // Note that because a Cord is made up of separate chunked data, random access
51
+ // to character data within a Cord is slower than within a `std::string`.
52
+ //
53
+ // Thread Safety
54
+ //
23
55
  // Cord has the same thread-safety properties as many other types like
24
56
  // std::string, std::vector<>, int, etc -- it is thread-compatible. In
25
- // particular, if no thread may call a non-const method, then it is safe to
26
- // concurrently call const methods. Copying a Cord produces a new instance that
27
- // can be used concurrently with the original in arbitrary ways.
28
- //
29
- // Implementation is similar to the "Ropes" described in:
30
- // Ropes: An alternative to strings
31
- // Hans J. Boehm, Russ Atkinson, Michael Plass
32
- // Software Practice and Experience, December 1995
57
+ // particular, if threads do not call non-const methods, then it is safe to call
58
+ // const methods without synchronization. Copying a Cord produces a new instance
59
+ // that can be used concurrently with the original in arbitrary ways.
33
60
 
34
61
  #ifndef ABSL_STRINGS_CORD_H_
35
62
  #define ABSL_STRINGS_CORD_H_
@@ -38,12 +65,12 @@
38
65
  #include <cstddef>
39
66
  #include <cstdint>
40
67
  #include <cstring>
41
- #include <iostream>
68
+ #include <iosfwd>
42
69
  #include <iterator>
43
70
  #include <string>
71
+ #include <type_traits>
44
72
 
45
73
  #include "absl/base/internal/endian.h"
46
- #include "absl/base/internal/invoke.h"
47
74
  #include "absl/base/internal/per_thread_tls.h"
48
75
  #include "absl/base/macros.h"
49
76
  #include "absl/base/port.h"
@@ -53,6 +80,7 @@
53
80
  #include "absl/strings/internal/cord_internal.h"
54
81
  #include "absl/strings/internal/resize_uninitialized.h"
55
82
  #include "absl/strings/string_view.h"
83
+ #include "absl/types/optional.h"
56
84
 
57
85
  namespace absl {
58
86
  ABSL_NAMESPACE_BEGIN
@@ -61,12 +89,35 @@ class CordTestPeer;
61
89
  template <typename Releaser>
62
90
  Cord MakeCordFromExternal(absl::string_view, Releaser&&);
63
91
  void CopyCordToString(const Cord& src, std::string* dst);
64
- namespace hash_internal {
65
- template <typename H>
66
- H HashFragmentedCord(H, const Cord&);
67
- }
68
92
 
69
- // A Cord is a sequence of characters.
93
+ // Cord
94
+ //
95
+ // A Cord is a sequence of characters, designed to be more efficient than a
96
+ // `std::string` in certain circumstances: namely, large string data that needs
97
+ // to change over its lifetime or shared, especially when such data is shared
98
+ // across API boundaries.
99
+ //
100
+ // A Cord stores its character data in a structure that allows efficient prepend
101
+ // and append operations. This makes a Cord useful for large string data sent
102
+ // over in a wire format that may need to be prepended or appended at some point
103
+ // during the data exchange (e.g. HTTP, protocol buffers). For example, a
104
+ // Cord is useful for storing an HTTP request, and prepending an HTTP header to
105
+ // such a request.
106
+ //
107
+ // Cords should not be used for storing general string data, however. They
108
+ // require overhead to construct and are slower than strings for random access.
109
+ //
110
+ // The Cord API provides the following common API operations:
111
+ //
112
+ // * Create or assign Cords out of existing string data, memory, or other Cords
113
+ // * Append and prepend data to an existing Cord
114
+ // * Create new Sub-Cords from existing Cord data
115
+ // * Swap Cord data and compare Cord equality
116
+ // * Write out Cord data by constructing a `std::string`
117
+ //
118
+ // Additionally, the API provides iterator utilities to iterate through Cord
119
+ // data via chunks or character bytes.
120
+ //
70
121
  class Cord {
71
122
  private:
72
123
  template <typename T>
@@ -74,51 +125,53 @@ class Cord {
74
125
  absl::enable_if_t<std::is_same<T, std::string>::value, int>;
75
126
 
76
127
  public:
77
- // --------------------------------------------------------------------
78
- // Constructors, destructors and helper factories
128
+ // Cord::Cord() Constructors.
79
129
 
80
- // Create an empty cord
130
+ // Creates an empty Cord.
81
131
  constexpr Cord() noexcept;
82
132
 
83
- // Cord is copyable and efficiently movable.
84
- // The moved-from state is valid but unspecified.
133
+ // Creates a Cord from an existing Cord. Cord is copyable and efficiently
134
+ // movable. The moved-from state is valid but unspecified.
85
135
  Cord(const Cord& src);
86
136
  Cord(Cord&& src) noexcept;
87
137
  Cord& operator=(const Cord& x);
88
138
  Cord& operator=(Cord&& x) noexcept;
89
139
 
90
- // Create a cord out of "src". This constructor is explicit on
91
- // purpose so that people do not get automatic type conversions.
140
+ // Creates a Cord from a `src` string. This constructor is marked explicit to
141
+ // prevent implicit Cord constructions from arguments convertible to an
142
+ // `absl::string_view`.
92
143
  explicit Cord(absl::string_view src);
93
144
  Cord& operator=(absl::string_view src);
94
145
 
95
- // These are templated to avoid ambiguities for types that are convertible to
96
- // both `absl::string_view` and `std::string`, such as `const char*`.
97
- //
98
- // Note that these functions reserve the right to reuse the `string&&`'s
99
- // memory and that they will do so in the future.
146
+ // Creates a Cord from a `std::string&&` rvalue. These constructors are
147
+ // templated to avoid ambiguities for types that are convertible to both
148
+ // `absl::string_view` and `std::string`, such as `const char*`.
100
149
  template <typename T, EnableIfString<T> = 0>
101
- explicit Cord(T&& src) : Cord(absl::string_view(src)) {}
150
+ explicit Cord(T&& src);
102
151
  template <typename T, EnableIfString<T> = 0>
103
152
  Cord& operator=(T&& src);
104
153
 
105
- // Destroy the cord
154
+ // Cord::~Cord()
155
+ //
156
+ // Destructs the Cord.
106
157
  ~Cord() {
107
158
  if (contents_.is_tree()) DestroyCordSlow();
108
159
  }
109
160
 
110
- // Creates a Cord that takes ownership of external memory. The contents of
111
- // `data` are not copied.
161
+ // MakeCordFromExternal()
112
162
  //
113
- // This function takes a callable that is invoked when all Cords are
114
- // finished with `data`. The data must remain live and unchanging until the
115
- // releaser is called. The requirements for the releaser are that it:
116
- // * is move constructible,
117
- // * supports `void operator()(absl::string_view) const`,
118
- // * does not have alignment requirement greater than what is guaranteed by
119
- // ::operator new. This is dictated by alignof(std::max_align_t) before
120
- // C++17 and __STDCPP_DEFAULT_NEW_ALIGNMENT__ if compiling with C++17 or
121
- // it is supported by the implementation.
163
+ // Creates a Cord that takes ownership of external string memory. The
164
+ // contents of `data` are not copied to the Cord; instead, the external
165
+ // memory is added to the Cord and reference-counted. This data may not be
166
+ // changed for the life of the Cord, though it may be prepended or appended
167
+ // to.
168
+ //
169
+ // `MakeCordFromExternal()` takes a callable "releaser" that is invoked when
170
+ // the reference count for `data` reaches zero. As noted above, this data must
171
+ // remain live until the releaser is invoked. The callable releaser also must:
172
+ //
173
+ // * be move constructible
174
+ // * support `void operator()(absl::string_view) const` or `void operator()`
122
175
  //
123
176
  // Example:
124
177
  //
@@ -127,13 +180,13 @@ class Cord {
127
180
  // FillBlock(block);
128
181
  // return absl::MakeCordFromExternal(
129
182
  // block->ToStringView(),
130
- // [pool, block](absl::string_view /*ignored*/) {
131
- // pool->FreeBlock(block);
183
+ // [pool, block](absl::string_view v) {
184
+ // pool->FreeBlock(block, v);
132
185
  // });
133
186
  // }
134
187
  //
135
- // WARNING: It's likely a bug if your releaser doesn't do anything.
136
- // For example, consider the following:
188
+ // WARNING: Because a Cord can be reference-counted, it's likely a bug if your
189
+ // releaser doesn't do anything. For example, consider the following:
137
190
  //
138
191
  // void Foo(const char* buffer, int len) {
139
192
  // auto c = absl::MakeCordFromExternal(absl::string_view(buffer, len),
@@ -147,97 +200,143 @@ class Cord {
147
200
  template <typename Releaser>
148
201
  friend Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser);
149
202
 
150
- // --------------------------------------------------------------------
151
- // Mutations
152
-
203
+ // Cord::Clear()
204
+ //
205
+ // Releases the Cord data. Any nodes that share data with other Cords, if
206
+ // applicable, will have their reference counts reduced by 1.
153
207
  void Clear();
154
208
 
209
+ // Cord::Append()
210
+ //
211
+ // Appends data to the Cord, which may come from another Cord or other string
212
+ // data.
155
213
  void Append(const Cord& src);
156
214
  void Append(Cord&& src);
157
215
  void Append(absl::string_view src);
158
216
  template <typename T, EnableIfString<T> = 0>
159
217
  void Append(T&& src);
160
218
 
219
+ // Cord::Prepend()
220
+ //
221
+ // Prepends data to the Cord, which may come from another Cord or other string
222
+ // data.
161
223
  void Prepend(const Cord& src);
162
224
  void Prepend(absl::string_view src);
163
225
  template <typename T, EnableIfString<T> = 0>
164
226
  void Prepend(T&& src);
165
227
 
228
+ // Cord::RemovePrefix()
229
+ //
230
+ // Removes the first `n` bytes of a Cord.
166
231
  void RemovePrefix(size_t n);
167
232
  void RemoveSuffix(size_t n);
168
233
 
169
- // Returns a new cord representing the subrange [pos, pos + new_size) of
234
+ // Cord::Subcord()
235
+ //
236
+ // Returns a new Cord representing the subrange [pos, pos + new_size) of
170
237
  // *this. If pos >= size(), the result is empty(). If
171
238
  // (pos + new_size) >= size(), the result is the subrange [pos, size()).
172
239
  Cord Subcord(size_t pos, size_t new_size) const;
173
240
 
174
- friend void swap(Cord& x, Cord& y) noexcept;
241
+ // Cord::swap()
242
+ //
243
+ // Swaps the contents of the Cord with `other`.
244
+ void swap(Cord& other) noexcept;
175
245
 
176
- // --------------------------------------------------------------------
177
- // Accessors
246
+ // swap()
247
+ //
248
+ // Swaps the contents of two Cords.
249
+ friend void swap(Cord& x, Cord& y) noexcept {
250
+ x.swap(y);
251
+ }
178
252
 
253
+ // Cord::size()
254
+ //
255
+ // Returns the size of the Cord.
179
256
  size_t size() const;
257
+
258
+ // Cord::empty()
259
+ //
260
+ // Determines whether the given Cord is empty, returning `true` is so.
180
261
  bool empty() const;
181
262
 
182
- // Returns the approximate number of bytes pinned by this Cord. Note that
183
- // Cords that share memory could each be "charged" independently for the same
184
- // shared memory.
263
+ // Cord::EstimatedMemoryUsage()
264
+ //
265
+ // Returns the *approximate* number of bytes held in full or in part by this
266
+ // Cord (which may not remain the same between invocations). Note that Cords
267
+ // that share memory could each be "charged" independently for the same shared
268
+ // memory.
185
269
  size_t EstimatedMemoryUsage() const;
186
270
 
187
- // --------------------------------------------------------------------
188
- // Comparators
189
-
190
- // Compares 'this' Cord with rhs. This function and its relatives
191
- // treat Cords as sequences of unsigned bytes. The comparison is a
192
- // straightforward lexicographic comparison. Return value:
271
+ // Cord::Compare()
272
+ //
273
+ // Compares 'this' Cord with rhs. This function and its relatives treat Cords
274
+ // as sequences of unsigned bytes. The comparison is a straightforward
275
+ // lexicographic comparison. `Cord::Compare()` returns values as follows:
276
+ //
193
277
  // -1 'this' Cord is smaller
194
278
  // 0 two Cords are equal
195
279
  // 1 'this' Cord is larger
196
280
  int Compare(absl::string_view rhs) const;
197
281
  int Compare(const Cord& rhs) const;
198
282
 
199
- // Does 'this' cord start/end with rhs
283
+ // Cord::StartsWith()
284
+ //
285
+ // Determines whether the Cord starts with the passed string data `rhs`.
200
286
  bool StartsWith(const Cord& rhs) const;
201
287
  bool StartsWith(absl::string_view rhs) const;
288
+
289
+ // Cord::EndsWidth()
290
+ //
291
+ // Determines whether the Cord ends with the passed string data `rhs`.
202
292
  bool EndsWith(absl::string_view rhs) const;
203
293
  bool EndsWith(const Cord& rhs) const;
204
294
 
205
- // --------------------------------------------------------------------
206
- // Conversion to other types
207
-
295
+ // Cord::operator std::string()
296
+ //
297
+ // Converts a Cord into a `std::string()`. This operator is marked explicit to
298
+ // prevent unintended Cord usage in functions that take a string.
208
299
  explicit operator std::string() const;
209
300
 
210
- // Copies the contents from `src` to `*dst`.
301
+ // CopyCordToString()
302
+ //
303
+ // Copies the contents of a `src` Cord into a `*dst` string.
211
304
  //
212
- // This function optimizes the case of reusing the destination std::string since it
305
+ // This function optimizes the case of reusing the destination string since it
213
306
  // can reuse previously allocated capacity. However, this function does not
214
307
  // guarantee that pointers previously returned by `dst->data()` remain valid
215
308
  // even if `*dst` had enough capacity to hold `src`. If `*dst` is a new
216
309
  // object, prefer to simply use the conversion operator to `std::string`.
217
310
  friend void CopyCordToString(const Cord& src, std::string* dst);
218
311
 
219
- // --------------------------------------------------------------------
220
- // Iteration
221
-
222
312
  class CharIterator;
223
313
 
224
- // Type for iterating over the chunks of a `Cord`. See comments for
225
- // `Cord::chunk_begin()`, `Cord::chunk_end()` and `Cord::Chunks()` below for
226
- // preferred usage.
314
+ //----------------------------------------------------------------------------
315
+ // Cord::ChunkIterator
316
+ //----------------------------------------------------------------------------
227
317
  //
228
- // Additional notes:
318
+ // A `Cord::ChunkIterator` allows iteration over the constituent chunks of its
319
+ // Cord. Such iteration allows you to perform non-const operatons on the data
320
+ // of a Cord without modifying it.
321
+ //
322
+ // Generally, you do not instantiate a `Cord::ChunkIterator` directly;
323
+ // instead, you create one implicitly through use of the `Cord::Chunks()`
324
+ // member function.
325
+ //
326
+ // The `Cord::ChunkIterator` has the following properties:
327
+ //
328
+ // * The iterator is invalidated after any non-const operation on the
329
+ // Cord object over which it iterates.
229
330
  // * The `string_view` returned by dereferencing a valid, non-`end()`
230
331
  // iterator is guaranteed to be non-empty.
231
- // * A `ChunkIterator` object is invalidated after any non-const
232
- // operation on the `Cord` object over which it iterates.
233
- // * Two `ChunkIterator` objects can be equality compared if and only if
234
- // they remain valid and iterate over the same `Cord`.
235
- // * This is a proxy iterator. This means the `string_view` returned by the
236
- // iterator does not live inside the Cord, and its lifetime is limited to
237
- // the lifetime of the iterator itself. To help prevent issues,
238
- // `ChunkIterator::reference` is not a true reference type and is
239
- // equivalent to `value_type`.
240
- // * The iterator keeps state that can grow for `Cord`s that contain many
332
+ // * Two `ChunkIterator` objects can be compared equal if and only if they
333
+ // remain valid and iterate over the same Cord.
334
+ // * The iterator in this case is a proxy iterator; the `string_view`
335
+ // returned by the iterator does not live inside the Cord, and its
336
+ // lifetime is limited to the lifetime of the iterator itself. To help
337
+ // prevent lifetime issues, `ChunkIterator::reference` is not a true
338
+ // reference type and is equivalent to `value_type`.
339
+ // * The iterator keeps state that can grow for Cords that contain many
241
340
  // nodes and are imbalanced due to sharing. Prefer to pass this type by
242
341
  // const reference instead of by value.
243
342
  class ChunkIterator {
@@ -286,10 +385,13 @@ class Cord {
286
385
  stack_of_right_children_;
287
386
  };
288
387
 
388
+ // Cord::ChunkIterator::chunk_begin()
389
+ //
289
390
  // Returns an iterator to the first chunk of the `Cord`.
290
391
  //
291
- // This is useful for getting a `ChunkIterator` outside the context of a
292
- // range-based for-loop (in which case see `Cord::Chunks()` below).
392
+ // Generally, prefer using `Cord::Chunks()` within a range-based for loop for
393
+ // iterating over the chunks of a Cord. This method may be useful for getting
394
+ // a `ChunkIterator` where range-based for-loops are not useful.
293
395
  //
294
396
  // Example:
295
397
  //
@@ -298,13 +400,28 @@ class Cord {
298
400
  // return std::find(c.chunk_begin(), c.chunk_end(), s);
299
401
  // }
300
402
  ChunkIterator chunk_begin() const;
403
+
404
+ // Cord::ChunkItertator::chunk_end()
405
+ //
301
406
  // Returns an iterator one increment past the last chunk of the `Cord`.
407
+ //
408
+ // Generally, prefer using `Cord::Chunks()` within a range-based for loop for
409
+ // iterating over the chunks of a Cord. This method may be useful for getting
410
+ // a `ChunkIterator` where range-based for-loops may not be available.
302
411
  ChunkIterator chunk_end() const;
303
412
 
304
- // Convenience wrapper over `Cord::chunk_begin()` and `Cord::chunk_end()` to
305
- // enable range-based for-loop iteration over `Cord` chunks.
413
+ //----------------------------------------------------------------------------
414
+ // Cord::ChunkIterator::ChunkRange
415
+ //----------------------------------------------------------------------------
416
+ //
417
+ // `ChunkRange` is a helper class for iterating over the chunks of the `Cord`,
418
+ // producing an iterator which can be used within a range-based for loop.
419
+ // Construction of a `ChunkRange` will return an iterator pointing to the
420
+ // first chunk of the Cord. Generally, do not construct a `ChunkRange`
421
+ // directly; instead, prefer to use the `Cord::Chunks()` method.
306
422
  //
307
- // Prefer to use `Cord::Chunks()` below instead of constructing this directly.
423
+ // Implementation note: `ChunkRange` is simply a convenience wrapper over
424
+ // `Cord::chunk_begin()` and `Cord::chunk_end()`.
308
425
  class ChunkRange {
309
426
  public:
310
427
  explicit ChunkRange(const Cord* cord) : cord_(cord) {}
@@ -316,8 +433,11 @@ class Cord {
316
433
  const Cord* cord_;
317
434
  };
318
435
 
319
- // Returns a range for iterating over the chunks of a `Cord` with a
320
- // range-based for-loop.
436
+ // Cord::Chunks()
437
+ //
438
+ // Returns a `Cord::ChunkIterator::ChunkRange` for iterating over the chunks
439
+ // of a `Cord` with a range-based for-loop. For most iteration tasks on a
440
+ // Cord, use `Cord::Chunks()` to retrieve this iterator.
321
441
  //
322
442
  // Example:
323
443
  //
@@ -334,22 +454,30 @@ class Cord {
334
454
  // }
335
455
  ChunkRange Chunks() const;
336
456
 
337
- // Type for iterating over the characters of a `Cord`. See comments for
338
- // `Cord::char_begin()`, `Cord::char_end()` and `Cord::Chars()` below for
339
- // preferred usage.
457
+ //----------------------------------------------------------------------------
458
+ // Cord::CharIterator
459
+ //----------------------------------------------------------------------------
460
+ //
461
+ // A `Cord::CharIterator` allows iteration over the constituent characters of
462
+ // a `Cord`.
340
463
  //
341
- // Additional notes:
342
- // * A `CharIterator` object is invalidated after any non-const
343
- // operation on the `Cord` object over which it iterates.
344
- // * Two `CharIterator` objects can be equality compared if and only if
345
- // they remain valid and iterate over the same `Cord`.
346
- // * The iterator keeps state that can grow for `Cord`s that contain many
464
+ // Generally, you do not instantiate a `Cord::CharIterator` directly; instead,
465
+ // you create one implicitly through use of the `Cord::Chars()` member
466
+ // function.
467
+ //
468
+ // A `Cord::CharIterator` has the following properties:
469
+ //
470
+ // * The iterator is invalidated after any non-const operation on the
471
+ // Cord object over which it iterates.
472
+ // * Two `CharIterator` objects can be compared equal if and only if they
473
+ // remain valid and iterate over the same Cord.
474
+ // * The iterator keeps state that can grow for Cords that contain many
347
475
  // nodes and are imbalanced due to sharing. Prefer to pass this type by
348
476
  // const reference instead of by value.
349
- // * This type cannot be a forward iterator because a `Cord` can reuse
350
- // sections of memory. This violates the requirement that if dereferencing
351
- // two iterators returns the same object, the iterators must compare
352
- // equal.
477
+ // * This type cannot act as a forward iterator because a `Cord` can reuse
478
+ // sections of memory. This fact violates the requirement for forward
479
+ // iterators to compare equal if dereferencing them returns the same
480
+ // object.
353
481
  class CharIterator {
354
482
  public:
355
483
  using iterator_category = std::input_iterator_tag;
@@ -375,34 +503,56 @@ class Cord {
375
503
  ChunkIterator chunk_iterator_;
376
504
  };
377
505
 
378
- // Advances `*it` by `n_bytes` and returns the bytes passed as a `Cord`.
506
+ // Cord::CharIterator::AdvanceAndRead()
379
507
  //
380
- // `n_bytes` must be less than or equal to the number of bytes remaining for
381
- // iteration. Otherwise the behavior is undefined. It is valid to pass
382
- // `char_end()` and 0.
508
+ // Advances the `Cord::CharIterator` by `n_bytes` and returns the bytes
509
+ // advanced as a separate `Cord`. `n_bytes` must be less than or equal to the
510
+ // number of bytes within the Cord; otherwise, behavior is undefined. It is
511
+ // valid to pass `char_end()` and `0`.
383
512
  static Cord AdvanceAndRead(CharIterator* it, size_t n_bytes);
384
513
 
385
- // Advances `*it` by `n_bytes`.
514
+ // Cord::CharIterator::Advance()
386
515
  //
387
- // `n_bytes` must be less than or equal to the number of bytes remaining for
388
- // iteration. Otherwise the behavior is undefined. It is valid to pass
389
- // `char_end()` and 0.
516
+ // Advances the `Cord::CharIterator` by `n_bytes`. `n_bytes` must be less than
517
+ // or equal to the number of bytes remaining within the Cord; otherwise,
518
+ // behavior is undefined. It is valid to pass `char_end()` and `0`.
390
519
  static void Advance(CharIterator* it, size_t n_bytes);
391
520
 
521
+ // Cord::CharIterator::ChunkRemaining()
522
+ //
392
523
  // Returns the longest contiguous view starting at the iterator's position.
393
524
  //
394
525
  // `it` must be dereferenceable.
395
526
  static absl::string_view ChunkRemaining(const CharIterator& it);
396
527
 
528
+ // Cord::CharIterator::char_begin()
529
+ //
397
530
  // Returns an iterator to the first character of the `Cord`.
531
+ //
532
+ // Generally, prefer using `Cord::Chars()` within a range-based for loop for
533
+ // iterating over the chunks of a Cord. This method may be useful for getting
534
+ // a `CharIterator` where range-based for-loops may not be available.
398
535
  CharIterator char_begin() const;
536
+
537
+ // Cord::CharIterator::char_end()
538
+ //
399
539
  // Returns an iterator to one past the last character of the `Cord`.
540
+ //
541
+ // Generally, prefer using `Cord::Chars()` within a range-based for loop for
542
+ // iterating over the chunks of a Cord. This method may be useful for getting
543
+ // a `CharIterator` where range-based for-loops are not useful.
400
544
  CharIterator char_end() const;
401
545
 
402
- // Convenience wrapper over `Cord::char_begin()` and `Cord::char_end()` to
403
- // enable range-based for-loop iterator over the characters of a `Cord`.
546
+ // Cord::CharIterator::CharRange
547
+ //
548
+ // `CharRange` is a helper class for iterating over the characters of a
549
+ // producing an iterator which can be used within a range-based for loop.
550
+ // Construction of a `CharRange` will return an iterator pointing to the first
551
+ // character of the Cord. Generally, do not construct a `CharRange` directly;
552
+ // instead, prefer to use the `Cord::Chars()` method show below.
404
553
  //
405
- // Prefer to use `Cord::Chars()` below instead of constructing this directly.
554
+ // Implementation note: `CharRange` is simply a convenience wrapper over
555
+ // `Cord::char_begin()` and `Cord::char_end()`.
406
556
  class CharRange {
407
557
  public:
408
558
  explicit CharRange(const Cord* cord) : cord_(cord) {}
@@ -414,8 +564,11 @@ class Cord {
414
564
  const Cord* cord_;
415
565
  };
416
566
 
417
- // Returns a range for iterating over the characters of a `Cord` with a
418
- // range-based for-loop.
567
+ // Cord::CharIterator::Chars()
568
+ //
569
+ // Returns a `Cord::CharIterator` for iterating over the characters of a
570
+ // `Cord` with a range-based for-loop. For most character-based iteration
571
+ // tasks on a Cord, use `Cord::Chars()` to retrieve this iterator.
419
572
  //
420
573
  // Example:
421
574
  //
@@ -432,32 +585,51 @@ class Cord {
432
585
  // }
433
586
  CharRange Chars() const;
434
587
 
435
- // --------------------------------------------------------------------
436
- // Miscellaneous
437
-
438
- // Get the "i"th character of 'this' and return it.
439
- // NOTE: This routine is reasonably efficient. It is roughly
440
- // logarithmic in the number of nodes that make up the cord. Still,
441
- // if you need to iterate over the contents of a cord, you should
442
- // use a CharIterator/CordIterator rather than call operator[] or Get()
443
- // repeatedly in a loop.
588
+ // Cord::operator[]
589
+ //
590
+ // Gets the "i"th character of the Cord and returns it, provided that
591
+ // 0 <= i < Cord.size().
444
592
  //
445
- // REQUIRES: 0 <= i < size()
593
+ // NOTE: This routine is reasonably efficient. It is roughly
594
+ // logarithmic based on the number of chunks that make up the cord. Still,
595
+ // if you need to iterate over the contents of a cord, you should
596
+ // use a CharIterator/ChunkIterator rather than call operator[] or Get()
597
+ // repeatedly in a loop.
446
598
  char operator[](size_t i) const;
447
599
 
600
+ // Cord::TryFlat()
601
+ //
602
+ // If this cord's representation is a single flat array, returns a
603
+ // string_view referencing that array. Otherwise returns nullopt.
604
+ absl::optional<absl::string_view> TryFlat() const;
605
+
606
+ // Cord::Flatten()
607
+ //
448
608
  // Flattens the cord into a single array and returns a view of the data.
449
609
  //
450
610
  // If the cord was already flat, the contents are not modified.
451
611
  absl::string_view Flatten();
452
612
 
613
+ // Supports absl::Cord as a sink object for absl::Format().
614
+ friend void AbslFormatFlush(absl::Cord* cord, absl::string_view part) {
615
+ cord->Append(part);
616
+ }
617
+
618
+ template <typename H>
619
+ friend H AbslHashValue(H hash_state, const absl::Cord& c) {
620
+ absl::optional<absl::string_view> maybe_flat = c.TryFlat();
621
+ if (maybe_flat.has_value()) {
622
+ return H::combine(std::move(hash_state), *maybe_flat);
623
+ }
624
+ return c.HashFragmented(std::move(hash_state));
625
+ }
626
+
453
627
  private:
454
628
  friend class CordTestPeer;
455
- template <typename H>
456
- friend H absl::hash_internal::HashFragmentedCord(H, const Cord&);
457
629
  friend bool operator==(const Cord& lhs, const Cord& rhs);
458
630
  friend bool operator==(const Cord& lhs, absl::string_view rhs);
459
631
 
460
- // Call the provided function once for each cord chunk, in order. Unlike
632
+ // Calls the provided function once for each cord chunk, in order. Unlike
461
633
  // Chunks(), this API will not allocate memory.
462
634
  void ForEachChunk(absl::FunctionRef<void(absl::string_view)>) const;
463
635
 
@@ -469,16 +641,15 @@ class Cord {
469
641
  // class so that we can isolate the bulk of cord.cc from changes
470
642
  // to the representation.
471
643
  //
472
- // InlineRep holds either either a tree pointer, or an array of kMaxInline
473
- // bytes.
644
+ // InlineRep holds either a tree pointer, or an array of kMaxInline bytes.
474
645
  class InlineRep {
475
646
  public:
476
- static const unsigned char kMaxInline = 15;
647
+ static constexpr unsigned char kMaxInline = 15;
477
648
  static_assert(kMaxInline >= sizeof(absl::cord_internal::CordRep*), "");
478
649
  // Tag byte & kMaxInline means we are storing a pointer.
479
- static const unsigned char kTreeFlag = 1 << 4;
650
+ static constexpr unsigned char kTreeFlag = 1 << 4;
480
651
  // Tag byte & kProfiledFlag means we are profiling the Cord.
481
- static const unsigned char kProfiledFlag = 1 << 5;
652
+ static constexpr unsigned char kProfiledFlag = 1 << 5;
482
653
 
483
654
  constexpr InlineRep() : data_{} {}
484
655
  InlineRep(const InlineRep& src);
@@ -502,7 +673,7 @@ class Cord {
502
673
  void replace_tree(absl::cord_internal::CordRep* rep);
503
674
  // Returns non-null iff was holding a pointer
504
675
  absl::cord_internal::CordRep* clear();
505
- // Convert to pointer if necessary
676
+ // Converts to pointer if necessary.
506
677
  absl::cord_internal::CordRep* force_tree(size_t extra_hint);
507
678
  void reduce_size(size_t n); // REQUIRES: holding data
508
679
  void remove_prefix(size_t n); // REQUIRES: holding data
@@ -531,7 +702,7 @@ class Cord {
531
702
  }
532
703
  void CopyTo(std::string* dst) const {
533
704
  // memcpy is much faster when operating on a known size. On most supported
534
- // platforms, the small std::string optimization is large enough that resizing
705
+ // platforms, the small string optimization is large enough that resizing
535
706
  // to 15 bytes does not cause a memory allocation.
536
707
  absl::strings_internal::STLStringResizeUninitialized(dst,
537
708
  sizeof(data_) - 1);
@@ -560,14 +731,14 @@ class Cord {
560
731
  };
561
732
  InlineRep contents_;
562
733
 
563
- // Helper for MemoryUsage()
734
+ // Helper for MemoryUsage().
564
735
  static size_t MemoryUsageAux(const absl::cord_internal::CordRep* rep);
565
736
 
566
- // Helper for GetFlat()
737
+ // Helper for GetFlat() and TryFlat().
567
738
  static bool GetFlatAux(absl::cord_internal::CordRep* rep,
568
739
  absl::string_view* fragment);
569
740
 
570
- // Helper for ForEachChunk()
741
+ // Helper for ForEachChunk().
571
742
  static void ForEachChunkAux(
572
743
  absl::cord_internal::CordRep* rep,
573
744
  absl::FunctionRef<void(absl::string_view)> callback);
@@ -596,9 +767,20 @@ class Cord {
596
767
  absl::cord_internal::CordRep* TakeRep() const&;
597
768
  absl::cord_internal::CordRep* TakeRep() &&;
598
769
 
599
- // Helper for Append()
770
+ // Helper for Append().
600
771
  template <typename C>
601
772
  void AppendImpl(C&& src);
773
+
774
+ // Helper for AbslHashValue().
775
+ template <typename H>
776
+ H HashFragmented(H hash_state) const {
777
+ typename H::AbslInternalPiecewiseCombiner combiner;
778
+ ForEachChunk([&combiner, &hash_state](absl::string_view chunk) {
779
+ hash_state = combiner.add_buffer(std::move(hash_state), chunk.data(),
780
+ chunk.size());
781
+ });
782
+ return H::combine(combiner.finalize(std::move(hash_state)), size());
783
+ }
602
784
  };
603
785
 
604
786
  ABSL_NAMESPACE_END
@@ -655,52 +837,27 @@ inline void SmallMemmove(char* dst, const char* src, size_t n,
655
837
  }
656
838
  }
657
839
 
658
- struct ExternalRepReleaserPair {
659
- CordRep* rep;
660
- void* releaser_address;
661
- };
662
-
663
- // Allocates a new external `CordRep` and returns a pointer to it and a pointer
664
- // to `releaser_size` bytes where the desired releaser can be constructed.
840
+ // Does non-template-specific `CordRepExternal` initialization.
665
841
  // Expects `data` to be non-empty.
666
- ExternalRepReleaserPair NewExternalWithUninitializedReleaser(
667
- absl::string_view data, ExternalReleaserInvoker invoker,
668
- size_t releaser_size);
842
+ void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep);
669
843
 
670
844
  // Creates a new `CordRep` that owns `data` and `releaser` and returns a pointer
671
845
  // to it, or `nullptr` if `data` was empty.
672
846
  template <typename Releaser>
673
847
  // NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
674
848
  CordRep* NewExternalRep(absl::string_view data, Releaser&& releaser) {
675
- static_assert(
676
- #if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
677
- alignof(Releaser) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__,
678
- #else
679
- alignof(Releaser) <= alignof(max_align_t),
680
- #endif
681
- "Releasers with alignment requirement greater than what is returned by "
682
- "default `::operator new()` are not supported.");
683
-
684
849
  using ReleaserType = absl::decay_t<Releaser>;
685
850
  if (data.empty()) {
686
851
  // Never create empty external nodes.
687
- ::absl::base_internal::Invoke(
688
- ReleaserType(std::forward<Releaser>(releaser)), data);
852
+ InvokeReleaser(Rank0{}, ReleaserType(std::forward<Releaser>(releaser)),
853
+ data);
689
854
  return nullptr;
690
855
  }
691
856
 
692
- auto releaser_invoker = [](void* type_erased_releaser, absl::string_view d) {
693
- auto* my_releaser = static_cast<ReleaserType*>(type_erased_releaser);
694
- ::absl::base_internal::Invoke(std::move(*my_releaser), d);
695
- my_releaser->~ReleaserType();
696
- return sizeof(Releaser);
697
- };
698
-
699
- ExternalRepReleaserPair external = NewExternalWithUninitializedReleaser(
700
- data, releaser_invoker, sizeof(releaser));
701
- ::new (external.releaser_address)
702
- ReleaserType(std::forward<Releaser>(releaser));
703
- return external.rep;
857
+ CordRepExternal* rep = new CordRepExternalImpl<ReleaserType>(
858
+ std::forward<Releaser>(releaser), 0);
859
+ InitializeCordRepExternal(data, rep);
860
+ return rep;
704
861
  }
705
862
 
706
863
  // Overload for function reference types that dispatches using a function
@@ -834,16 +991,17 @@ inline Cord& Cord::operator=(const Cord& x) {
834
991
 
835
992
  inline Cord::Cord(Cord&& src) noexcept : contents_(std::move(src.contents_)) {}
836
993
 
994
+ inline void Cord::swap(Cord& other) noexcept {
995
+ contents_.Swap(&other.contents_);
996
+ }
997
+
837
998
  inline Cord& Cord::operator=(Cord&& x) noexcept {
838
999
  contents_ = std::move(x.contents_);
839
1000
  return *this;
840
1001
  }
841
1002
 
842
- template <typename T, Cord::EnableIfString<T>>
843
- inline Cord& Cord::operator=(T&& src) {
844
- *this = absl::string_view(src);
845
- return *this;
846
- }
1003
+ extern template Cord::Cord(std::string&& src);
1004
+ extern template Cord& Cord::operator=(std::string&& src);
847
1005
 
848
1006
  inline size_t Cord::size() const {
849
1007
  // Length is 1st field in str.rep_
@@ -860,6 +1018,18 @@ inline size_t Cord::EstimatedMemoryUsage() const {
860
1018
  return result;
861
1019
  }
862
1020
 
1021
+ inline absl::optional<absl::string_view> Cord::TryFlat() const {
1022
+ absl::cord_internal::CordRep* rep = contents_.tree();
1023
+ if (rep == nullptr) {
1024
+ return absl::string_view(contents_.data(), contents_.size());
1025
+ }
1026
+ absl::string_view fragment;
1027
+ if (GetFlatAux(rep, &fragment)) {
1028
+ return fragment;
1029
+ }
1030
+ return absl::nullopt;
1031
+ }
1032
+
863
1033
  inline absl::string_view Cord::Flatten() {
864
1034
  absl::cord_internal::CordRep* rep = contents_.tree();
865
1035
  if (rep == nullptr) {
@@ -877,19 +1047,8 @@ inline void Cord::Append(absl::string_view src) {
877
1047
  contents_.AppendArray(src.data(), src.size());
878
1048
  }
879
1049
 
880
- template <typename T, Cord::EnableIfString<T>>
881
- inline void Cord::Append(T&& src) {
882
- // Note that this function reserves the right to reuse the `string&&`'s
883
- // memory and that it will do so in the future.
884
- Append(absl::string_view(src));
885
- }
886
-
887
- template <typename T, Cord::EnableIfString<T>>
888
- inline void Cord::Prepend(T&& src) {
889
- // Note that this function reserves the right to reuse the `string&&`'s
890
- // memory and that it will do so in the future.
891
- Prepend(absl::string_view(src));
892
- }
1050
+ extern template void Cord::Append(std::string&& src);
1051
+ extern template void Cord::Prepend(std::string&& src);
893
1052
 
894
1053
  inline int Cord::Compare(const Cord& rhs) const {
895
1054
  if (!contents_.is_tree() && !rhs.contents_.is_tree()) {
@@ -939,12 +1098,12 @@ inline bool Cord::ChunkIterator::operator!=(const ChunkIterator& other) const {
939
1098
  }
940
1099
 
941
1100
  inline Cord::ChunkIterator::reference Cord::ChunkIterator::operator*() const {
942
- assert(bytes_remaining_ != 0);
1101
+ ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
943
1102
  return current_chunk_;
944
1103
  }
945
1104
 
946
1105
  inline Cord::ChunkIterator::pointer Cord::ChunkIterator::operator->() const {
947
- assert(bytes_remaining_ != 0);
1106
+ ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
948
1107
  return &current_chunk_;
949
1108
  }
950
1109
 
@@ -1098,10 +1257,6 @@ inline bool operator<=(absl::string_view x, const Cord& y) { return !(y < x); }
1098
1257
  inline bool operator>=(const Cord& x, absl::string_view y) { return !(x < y); }
1099
1258
  inline bool operator>=(absl::string_view x, const Cord& y) { return !(x < y); }
1100
1259
 
1101
- // Overload of swap for Cord. The use of non-const references is
1102
- // required. :(
1103
- inline void swap(Cord& x, Cord& y) noexcept { y.contents_.Swap(&x.contents_); }
1104
-
1105
1260
  // Some internals exposed to test code.
1106
1261
  namespace strings_internal {
1107
1262
  class CordTestAccess {