grpc 1.34.0 → 1.35.0.pre1

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

Potentially problematic release.


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

Files changed (458) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +808 -2787
  3. data/etc/roots.pem +257 -573
  4. data/include/grpc/compression.h +1 -1
  5. data/include/grpc/grpc.h +14 -0
  6. data/include/grpc/grpc_security.h +61 -3
  7. data/include/grpc/impl/codegen/atm_windows.h +4 -0
  8. data/include/grpc/impl/codegen/byte_buffer.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/log.h +0 -2
  11. data/include/grpc/impl/codegen/sync_windows.h +4 -0
  12. data/include/grpc/slice_buffer.h +3 -3
  13. data/include/grpc/support/sync.h +3 -3
  14. data/include/grpc/support/time.h +7 -7
  15. data/src/core/ext/filters/client_channel/backend_metric.cc +2 -4
  16. data/src/core/ext/filters/client_channel/client_channel.cc +2734 -1498
  17. data/src/core/ext/filters/client_channel/client_channel.h +0 -4
  18. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  19. data/src/core/ext/filters/client_channel/config_selector.h +4 -0
  20. data/src/core/ext/filters/client_channel/dynamic_filters.cc +186 -0
  21. data/src/core/ext/filters/client_channel/dynamic_filters.h +99 -0
  22. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -6
  23. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -2
  24. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +4 -5
  25. data/src/core/ext/filters/client_channel/http_proxy.cc +21 -20
  26. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy.h +2 -3
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +32 -30
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +162 -20
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +0 -8
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +24 -0
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +5 -2
  35. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +1 -1
  36. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +1262 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +7 -14
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -32
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +454 -16
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -0
  42. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -9
  43. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -2
  44. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +18 -31
  45. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +3 -5
  46. data/src/core/ext/filters/client_channel/resolver_factory.h +6 -6
  47. data/src/core/ext/filters/client_channel/resolver_registry.cc +40 -39
  48. data/src/core/ext/filters/client_channel/resolver_registry.h +2 -2
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +11 -13
  50. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +8 -8
  51. data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -3
  52. data/src/core/ext/filters/client_channel/retry_throttle.h +3 -1
  53. data/src/core/ext/filters/client_channel/service_config_call_data.h +19 -1
  54. data/src/core/ext/filters/client_channel/subchannel.cc +34 -50
  55. data/src/core/ext/filters/client_channel/subchannel.h +12 -18
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +4 -2
  57. data/src/core/ext/filters/http/client_authority_filter.cc +6 -6
  58. data/src/core/ext/filters/http/http_filters_plugin.cc +6 -3
  59. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
  60. data/src/core/ext/filters/workarounds/workaround_utils.cc +1 -1
  61. data/src/core/ext/transport/chttp2/client/authority.cc +3 -3
  62. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +20 -8
  63. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +21 -10
  64. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +26 -14
  65. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +178 -86
  66. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +12 -5
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +7 -8
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  70. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +6 -6
  71. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -1
  72. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -8
  73. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +1 -0
  74. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +1 -1
  75. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +7 -0
  76. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +27 -27
  77. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +139 -40
  78. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +13 -13
  79. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +44 -17
  80. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +111 -111
  81. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +424 -241
  82. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +3 -3
  83. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +13 -5
  84. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +22 -22
  85. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +47 -21
  86. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +21 -21
  87. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +88 -39
  88. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +4 -4
  89. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +15 -6
  90. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +44 -44
  91. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +200 -78
  92. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +17 -17
  93. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +72 -35
  94. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +1 -1
  95. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +7 -0
  96. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +7 -7
  97. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +27 -11
  98. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +30 -30
  99. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +136 -49
  100. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +39 -39
  101. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +157 -89
  102. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +4 -4
  103. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +17 -9
  104. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +47 -47
  105. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +163 -78
  106. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +1 -1
  107. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +7 -0
  108. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.c +2 -2
  109. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +9 -2
  110. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -1
  111. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +7 -0
  112. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +13 -13
  113. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +59 -36
  114. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +16 -16
  115. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +61 -29
  116. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +26 -26
  117. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +101 -66
  118. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +2 -2
  119. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +11 -3
  120. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +28 -28
  121. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +122 -77
  122. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +23 -23
  123. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +106 -54
  124. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +2 -2
  125. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +13 -0
  126. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +16 -16
  127. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +81 -35
  128. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +7 -7
  129. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +38 -22
  130. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +203 -203
  131. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +845 -495
  132. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +5 -5
  133. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +26 -6
  134. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +3 -3
  135. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +17 -3
  136. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +87 -87
  137. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +343 -204
  138. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +1 -0
  139. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +20 -20
  140. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +85 -46
  141. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +7 -7
  142. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +33 -11
  143. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +32 -32
  144. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +118 -67
  145. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.c +1 -1
  146. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +7 -0
  147. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.c +1 -1
  148. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +7 -0
  149. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +29 -29
  150. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +120 -82
  151. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.c +1 -1
  152. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +7 -0
  153. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.c +1 -1
  154. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +7 -0
  155. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +7 -7
  156. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +31 -16
  157. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c +1 -1
  158. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +7 -0
  159. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.c +1 -1
  160. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +7 -0
  161. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +5 -5
  162. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +25 -11
  163. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +1 -1
  164. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +7 -0
  165. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +1 -1
  166. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +7 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +6 -6
  168. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +29 -8
  169. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +2 -2
  170. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +16 -3
  171. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +3 -3
  172. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +19 -0
  173. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +7 -7
  174. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +46 -3
  175. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +8 -8
  176. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +41 -8
  177. data/src/core/ext/upb-generated/envoy/type/v3/http.upb.h +1 -0
  178. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +3 -3
  179. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +15 -2
  180. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +3 -3
  181. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +19 -0
  182. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c +1 -1
  183. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +7 -0
  184. data/src/core/ext/upb-generated/google/api/annotations.upb.h +1 -0
  185. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +34 -34
  186. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +149 -72
  187. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +34 -34
  188. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +142 -59
  189. data/src/core/ext/upb-generated/google/api/http.upb.c +3 -3
  190. data/src/core/ext/upb-generated/google/api/http.upb.h +25 -6
  191. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +1 -1
  192. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +7 -0
  193. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +90 -90
  194. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +455 -292
  195. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +1 -1
  196. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +7 -0
  197. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +1 -1
  198. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +7 -0
  199. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +4 -4
  200. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +22 -3
  201. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +1 -1
  202. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +7 -0
  203. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +9 -9
  204. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +55 -0
  205. data/src/core/ext/upb-generated/google/rpc/status.upb.c +1 -1
  206. data/src/core/ext/upb-generated/google/rpc/status.upb.h +10 -3
  207. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +4 -4
  208. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +11 -3
  209. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +41 -41
  210. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +149 -76
  211. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +5 -5
  212. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +21 -6
  213. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +2 -2
  214. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +13 -0
  215. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +17 -17
  216. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +82 -25
  217. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +3 -3
  218. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +19 -0
  219. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +1 -1
  220. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +7 -0
  221. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +1 -0
  222. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +2 -2
  223. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +9 -2
  224. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +1 -1
  225. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +7 -0
  226. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +1 -1
  227. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +7 -0
  228. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +5 -5
  229. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +21 -7
  230. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +2 -2
  231. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +7 -0
  232. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +4 -4
  233. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +17 -8
  234. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +7 -7
  235. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +31 -18
  236. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +5 -5
  237. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +19 -11
  238. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +3 -3
  239. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +7 -0
  240. data/src/core/ext/upb-generated/validate/validate.upb.c +64 -64
  241. data/src/core/ext/upb-generated/validate/validate.upb.h +296 -157
  242. data/src/core/ext/xds/certificate_provider_store.cc +10 -7
  243. data/src/core/ext/xds/certificate_provider_store.h +12 -7
  244. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +25 -0
  245. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -4
  246. data/src/core/ext/xds/xds_api.cc +220 -31
  247. data/src/core/ext/xds/xds_api.h +41 -10
  248. data/src/core/ext/xds/xds_bootstrap.h +0 -1
  249. data/src/core/ext/xds/xds_certificate_provider.cc +61 -2
  250. data/src/core/ext/xds/xds_certificate_provider.h +40 -2
  251. data/src/core/ext/xds/xds_client.cc +31 -29
  252. data/src/core/ext/xds/xds_client.h +6 -1
  253. data/src/core/ext/xds/xds_client_stats.cc +2 -2
  254. data/src/core/ext/xds/xds_server_config_fetcher.cc +131 -0
  255. data/src/core/lib/channel/channel_args.cc +8 -8
  256. data/src/core/lib/channel/channel_trace.h +1 -1
  257. data/src/core/lib/channel/channelz.cc +13 -14
  258. data/src/core/lib/channel/channelz.h +0 -1
  259. data/src/core/lib/channel/channelz_registry.h +0 -1
  260. data/src/core/lib/channel/handshaker.cc +2 -2
  261. data/src/core/lib/compression/compression_args.cc +3 -2
  262. data/src/core/lib/debug/stats.h +2 -2
  263. data/src/core/lib/debug/stats_data.h +13 -13
  264. data/src/core/lib/gpr/alloc.cc +3 -2
  265. data/src/core/lib/gpr/log.cc +53 -16
  266. data/src/core/lib/gpr/log_linux.cc +3 -1
  267. data/src/core/lib/gpr/log_posix.cc +3 -1
  268. data/src/core/lib/gpr/log_windows.cc +3 -1
  269. data/src/core/lib/gpr/spinlock.h +10 -2
  270. data/src/core/lib/gpr/string.cc +22 -21
  271. data/src/core/lib/gpr/string.h +5 -6
  272. data/src/core/lib/gpr/sync.cc +4 -4
  273. data/src/core/lib/gpr/time.cc +12 -12
  274. data/src/core/lib/gprpp/arena.h +3 -2
  275. data/src/core/lib/gprpp/ref_counted.h +2 -2
  276. data/src/core/lib/gprpp/ref_counted_ptr.h +9 -1
  277. data/src/core/lib/gprpp/thd_posix.cc +6 -1
  278. data/src/core/lib/gprpp/thd_windows.cc +3 -1
  279. data/src/core/lib/http/httpcli.cc +1 -1
  280. data/src/core/lib/http/httpcli.h +2 -3
  281. data/src/core/lib/http/httpcli_security_connector.cc +1 -1
  282. data/src/core/lib/http/parser.cc +1 -2
  283. data/src/core/lib/iomgr/call_combiner.cc +8 -5
  284. data/src/core/lib/iomgr/combiner.cc +2 -1
  285. data/src/core/lib/iomgr/endpoint.h +1 -1
  286. data/src/core/lib/iomgr/error.cc +15 -11
  287. data/src/core/lib/iomgr/error_internal.h +1 -1
  288. data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -13
  289. data/src/core/lib/iomgr/ev_epollex_linux.cc +17 -13
  290. data/src/core/lib/iomgr/ev_poll_posix.cc +9 -7
  291. data/src/core/lib/iomgr/exec_ctx.h +6 -4
  292. data/src/core/lib/iomgr/executor.cc +2 -1
  293. data/src/core/lib/iomgr/executor.h +1 -1
  294. data/src/core/lib/iomgr/executor/threadpool.h +1 -1
  295. data/src/core/lib/iomgr/iomgr.cc +1 -1
  296. data/src/core/lib/iomgr/load_file.h +1 -1
  297. data/src/core/lib/iomgr/lockfree_event.cc +19 -14
  298. data/src/core/lib/iomgr/lockfree_event.h +2 -2
  299. data/src/core/lib/iomgr/parse_address.cc +52 -46
  300. data/src/core/lib/iomgr/parse_address.h +13 -9
  301. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +1 -1
  302. data/src/core/lib/iomgr/pollset_set_custom.cc +1 -1
  303. data/src/core/lib/iomgr/python_util.h +1 -1
  304. data/src/core/lib/iomgr/resolve_address.cc +4 -4
  305. data/src/core/lib/iomgr/resource_quota.cc +4 -4
  306. data/src/core/lib/iomgr/sockaddr_utils.cc +10 -10
  307. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  308. data/src/core/lib/iomgr/socket_factory_posix.cc +3 -2
  309. data/src/core/lib/iomgr/socket_mutator.cc +3 -2
  310. data/src/core/lib/iomgr/tcp_client.cc +3 -3
  311. data/src/core/lib/iomgr/tcp_client_custom.cc +7 -6
  312. data/src/core/lib/iomgr/tcp_custom.cc +22 -17
  313. data/src/core/lib/iomgr/tcp_posix.cc +9 -6
  314. data/src/core/lib/iomgr/tcp_server_custom.cc +28 -22
  315. data/src/core/lib/iomgr/timer_custom.cc +3 -3
  316. data/src/core/lib/iomgr/timer_generic.cc +3 -3
  317. data/src/core/lib/iomgr/timer_manager.cc +2 -2
  318. data/src/core/lib/iomgr/udp_server.cc +1 -2
  319. data/src/core/lib/iomgr/udp_server.h +1 -2
  320. data/src/core/lib/iomgr/unix_sockets_posix.cc +17 -18
  321. data/src/core/lib/json/json.h +10 -0
  322. data/src/core/lib/security/authorization/evaluate_args.cc +5 -10
  323. data/src/core/lib/security/authorization/evaluate_args.h +1 -1
  324. data/src/core/lib/security/context/security_context.cc +4 -3
  325. data/src/core/lib/security/credentials/alts/check_gcp_environment.cc +1 -1
  326. data/src/core/lib/security/credentials/credentials.cc +6 -6
  327. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +413 -0
  328. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +80 -0
  329. data/src/core/lib/security/credentials/external/aws_request_signer.cc +15 -10
  330. data/src/core/lib/security/credentials/external/aws_request_signer.h +1 -2
  331. data/src/core/lib/security/credentials/external/external_account_credentials.cc +217 -31
  332. data/src/core/lib/security/credentials/external/external_account_credentials.h +7 -5
  333. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -6
  334. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +3 -4
  335. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +20 -18
  336. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +5 -6
  337. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -1
  338. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +18 -12
  339. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +18 -5
  340. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  341. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -3
  342. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +37 -44
  343. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -4
  344. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  345. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +5 -5
  346. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +1 -1
  347. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +1 -6
  348. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +1 -6
  349. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +326 -5
  350. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +64 -0
  351. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +1 -1
  352. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +0 -1
  353. data/src/core/lib/security/credentials/tls/tls_credentials.cc +1 -1
  354. data/src/core/lib/security/credentials/tls/tls_utils.cc +91 -0
  355. data/src/core/lib/security/credentials/tls/tls_utils.h +38 -0
  356. data/src/core/lib/security/credentials/xds/xds_credentials.cc +140 -10
  357. data/src/core/lib/security/credentials/xds/xds_credentials.h +27 -9
  358. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -1
  359. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -1
  360. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +46 -13
  361. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +23 -6
  362. data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
  363. data/src/core/lib/security/security_connector/security_connector.cc +3 -2
  364. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -4
  365. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
  366. data/src/core/lib/security/security_connector/ssl_utils.h +12 -19
  367. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +57 -12
  368. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +2 -3
  369. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  370. data/src/core/lib/security/transport/security_handshaker.cc +2 -2
  371. data/src/core/lib/slice/slice_intern.cc +4 -5
  372. data/src/core/lib/slice/slice_internal.h +2 -2
  373. data/src/core/lib/surface/call.cc +32 -24
  374. data/src/core/lib/surface/call_details.cc +8 -8
  375. data/src/core/lib/surface/channel.cc +16 -10
  376. data/src/core/lib/surface/channel.h +3 -2
  377. data/src/core/lib/surface/channel_init.cc +1 -1
  378. data/src/core/lib/surface/completion_queue.cc +23 -18
  379. data/src/core/lib/surface/completion_queue.h +16 -16
  380. data/src/core/lib/surface/init.cc +6 -5
  381. data/src/core/lib/surface/lame_client.cc +20 -46
  382. data/src/core/lib/surface/lame_client.h +4 -0
  383. data/src/core/lib/surface/server.cc +59 -15
  384. data/src/core/lib/surface/server.h +37 -5
  385. data/src/core/lib/surface/version.cc +1 -1
  386. data/src/core/lib/transport/authority_override.cc +6 -4
  387. data/src/core/lib/transport/authority_override.h +5 -2
  388. data/src/core/lib/transport/connectivity_state.h +6 -4
  389. data/src/core/lib/transport/error_utils.h +1 -1
  390. data/src/core/lib/transport/metadata_batch.h +4 -4
  391. data/src/core/lib/transport/static_metadata.cc +1 -1
  392. data/src/core/lib/transport/status_metadata.cc +4 -3
  393. data/src/core/lib/transport/transport.h +7 -7
  394. data/src/core/lib/uri/uri_parser.cc +131 -249
  395. data/src/core/lib/uri/uri_parser.h +57 -21
  396. data/src/core/plugin_registry/grpc_plugin_registry.cc +10 -4
  397. data/src/core/tsi/alts/crypt/gsec.cc +5 -4
  398. data/src/core/tsi/alts/frame_protector/frame_handler.cc +8 -6
  399. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  400. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +23 -23
  401. data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +8 -6
  402. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +4 -4
  403. data/src/core/tsi/fake_transport_security.cc +5 -3
  404. data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -1
  405. data/src/core/tsi/ssl_transport_security.cc +62 -49
  406. data/src/core/tsi/ssl_transport_security.h +6 -6
  407. data/src/core/tsi/transport_security.cc +6 -6
  408. data/src/core/tsi/transport_security_interface.h +1 -1
  409. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  410. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -0
  411. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +31 -13
  412. data/src/ruby/lib/grpc/version.rb +1 -1
  413. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +28 -0
  414. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +18 -0
  415. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -6
  416. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +606 -0
  417. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +197 -0
  418. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +399 -0
  419. data/third_party/abseil-cpp/absl/status/statusor.cc +71 -0
  420. data/third_party/abseil-cpp/absl/status/statusor.h +760 -0
  421. data/third_party/upb/third_party/wyhash/wyhash.h +145 -0
  422. data/third_party/upb/upb/decode.c +248 -167
  423. data/third_party/upb/upb/decode.h +20 -1
  424. data/third_party/upb/upb/decode.int.h +163 -0
  425. data/third_party/upb/upb/decode_fast.c +1040 -0
  426. data/third_party/upb/upb/decode_fast.h +126 -0
  427. data/third_party/upb/upb/def.c +525 -516
  428. data/third_party/upb/upb/def.h +16 -31
  429. data/third_party/upb/upb/def.hpp +37 -123
  430. data/third_party/upb/upb/encode.c +227 -169
  431. data/third_party/upb/upb/encode.h +27 -2
  432. data/third_party/upb/upb/json_decode.c +1443 -0
  433. data/third_party/upb/upb/json_decode.h +23 -0
  434. data/third_party/upb/upb/json_encode.c +713 -0
  435. data/third_party/upb/upb/json_encode.h +36 -0
  436. data/third_party/upb/upb/msg.c +167 -88
  437. data/third_party/upb/upb/msg.h +174 -34
  438. data/third_party/upb/upb/port_def.inc +74 -61
  439. data/third_party/upb/upb/port_undef.inc +3 -7
  440. data/third_party/upb/upb/reflection.c +36 -19
  441. data/third_party/upb/upb/table.c +34 -197
  442. data/third_party/upb/upb/table.int.h +14 -5
  443. data/third_party/upb/upb/text_encode.c +45 -22
  444. data/third_party/upb/upb/text_encode.h +4 -1
  445. data/third_party/upb/upb/upb.c +18 -41
  446. data/third_party/upb/upb/upb.h +36 -7
  447. data/third_party/upb/upb/upb.hpp +4 -4
  448. data/third_party/upb/upb/upb.int.h +29 -0
  449. metadata +60 -46
  450. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +0 -909
  451. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +0 -485
  452. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +0 -68
  453. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +0 -355
  454. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +0 -138
  455. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +0 -265
  456. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +0 -104
  457. data/src/core/lib/gprpp/map.h +0 -53
  458. data/third_party/upb/upb/port.c +0 -26
@@ -117,9 +117,10 @@ typedef upb_inttable_iter upb_oneof_iter;
117
117
 
118
118
  const char *upb_oneofdef_name(const upb_oneofdef *o);
119
119
  const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
120
- int upb_oneofdef_numfields(const upb_oneofdef *o);
121
120
  uint32_t upb_oneofdef_index(const upb_oneofdef *o);
122
121
  bool upb_oneofdef_issynthetic(const upb_oneofdef *o);
122
+ int upb_oneofdef_fieldcount(const upb_oneofdef *o);
123
+ const upb_fielddef *upb_oneofdef_field(const upb_oneofdef *o, int i);
123
124
 
124
125
  /* Oneof lookups:
125
126
  * - ntof: look up a field by name.
@@ -133,11 +134,8 @@ UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
133
134
  }
134
135
  const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
135
136
 
136
- /* upb_oneof_iter i;
137
- * for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
138
- * // ...
139
- * }
140
- */
137
+ /* DEPRECATED, slated for removal. */
138
+ int upb_oneofdef_numfields(const upb_oneofdef *o);
141
139
  void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
142
140
  void upb_oneof_next(upb_oneof_iter *iter);
143
141
  bool upb_oneof_done(upb_oneof_iter *iter);
@@ -145,6 +143,7 @@ upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
145
143
  void upb_oneof_iter_setdone(upb_oneof_iter *iter);
146
144
  bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1,
147
145
  const upb_oneof_iter *iter2);
146
+ /* END DEPRECATED */
148
147
 
149
148
  /* upb_msgdef *****************************************************************/
150
149
 
@@ -170,21 +169,21 @@ typedef upb_strtable_iter upb_msg_oneof_iter;
170
169
  const char *upb_msgdef_fullname(const upb_msgdef *m);
171
170
  const upb_filedef *upb_msgdef_file(const upb_msgdef *m);
172
171
  const char *upb_msgdef_name(const upb_msgdef *m);
173
- int upb_msgdef_numfields(const upb_msgdef *m);
174
- int upb_msgdef_numoneofs(const upb_msgdef *m);
175
- int upb_msgdef_numrealoneofs(const upb_msgdef *m);
176
172
  upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
177
173
  bool upb_msgdef_mapentry(const upb_msgdef *m);
178
174
  upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m);
179
175
  bool upb_msgdef_iswrapper(const upb_msgdef *m);
180
176
  bool upb_msgdef_isnumberwrapper(const upb_msgdef *m);
177
+ int upb_msgdef_fieldcount(const upb_msgdef *m);
178
+ int upb_msgdef_oneofcount(const upb_msgdef *m);
179
+ const upb_fielddef *upb_msgdef_field(const upb_msgdef *m, int i);
180
+ const upb_oneofdef *upb_msgdef_oneof(const upb_msgdef *m, int i);
181
181
  const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
182
182
  const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
183
183
  size_t len);
184
184
  const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
185
185
  size_t len);
186
186
  const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m);
187
- const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i);
188
187
 
189
188
  UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
190
189
  const char *name) {
@@ -216,19 +215,10 @@ UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
216
215
  const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m,
217
216
  const char *name, size_t len);
218
217
 
219
- /* Iteration over fields and oneofs. For example:
220
- *
221
- * upb_msg_field_iter i;
222
- * for(upb_msg_field_begin(&i, m);
223
- * !upb_msg_field_done(&i);
224
- * upb_msg_field_next(&i)) {
225
- * upb_fielddef *f = upb_msg_iter_field(&i);
226
- * // ...
227
- * }
228
- *
229
- * For C we don't have separate iterators for const and non-const.
230
- * It is the caller's responsibility to cast the upb_fielddef* to
231
- * const if the upb_msgdef* is const. */
218
+ /* DEPRECATED, slated for removal */
219
+ int upb_msgdef_numfields(const upb_msgdef *m);
220
+ int upb_msgdef_numoneofs(const upb_msgdef *m);
221
+ int upb_msgdef_numrealoneofs(const upb_msgdef *m);
232
222
  void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
233
223
  void upb_msg_field_next(upb_msg_field_iter *iter);
234
224
  bool upb_msg_field_done(const upb_msg_field_iter *iter);
@@ -236,9 +226,6 @@ upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
236
226
  void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
237
227
  bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1,
238
228
  const upb_msg_field_iter * iter2);
239
-
240
- /* Similar to above, we also support iterating through the oneofs in a
241
- * msgdef. */
242
229
  void upb_msg_oneof_begin(upb_msg_oneof_iter * iter, const upb_msgdef *m);
243
230
  void upb_msg_oneof_next(upb_msg_oneof_iter * iter);
244
231
  bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
@@ -246,6 +233,7 @@ const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
246
233
  void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter * iter);
247
234
  bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1,
248
235
  const upb_msg_oneof_iter *iter2);
236
+ /* END DEPRECATED */
249
237
 
250
238
  /* upb_enumdef ****************************************************************/
251
239
 
@@ -270,11 +258,6 @@ UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
270
258
  }
271
259
  const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
272
260
 
273
- /* upb_enum_iter i;
274
- * for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
275
- * // ...
276
- * }
277
- */
278
261
  void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
279
262
  void upb_enum_next(upb_enum_iter *iter);
280
263
  bool upb_enum_done(upb_enum_iter *iter);
@@ -294,6 +277,7 @@ int upb_filedef_enumcount(const upb_filedef *f);
294
277
  const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
295
278
  const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
296
279
  const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
280
+ const upb_symtab *upb_filedef_symtab(const upb_filedef *f);
297
281
 
298
282
  /* upb_symtab *****************************************************************/
299
283
 
@@ -310,6 +294,7 @@ int upb_symtab_filecount(const upb_symtab *s);
310
294
  const upb_filedef *upb_symtab_addfile(
311
295
  upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
312
296
  upb_status *status);
297
+ size_t _upb_symtab_bytesloaded(const upb_symtab *s);
313
298
 
314
299
  /* For generated code only: loads a generated descriptor. */
315
300
  typedef struct upb_def_init {
@@ -129,17 +129,17 @@ class OneofDefPtr {
129
129
  explicit OneofDefPtr(const upb_oneofdef* ptr) : ptr_(ptr) {}
130
130
 
131
131
  const upb_oneofdef* ptr() const { return ptr_; }
132
- explicit operator bool() { return ptr_ != nullptr; }
132
+ explicit operator bool() const { return ptr_ != nullptr; }
133
133
 
134
- // Returns the MessageDef that owns this OneofDef.
134
+ // Returns the MessageDef that contains this OneofDef.
135
135
  MessageDefPtr containing_type() const;
136
136
 
137
- // Returns the name of this oneof. This is the name used to look up the oneof
138
- // by name once added to a message def.
137
+ // Returns the name of this oneof.
139
138
  const char* name() const { return upb_oneofdef_name(ptr_); }
140
139
 
141
- // Returns the number of fields currently defined in the oneof.
140
+ // Returns the number of fields in the oneof.
142
141
  int field_count() const { return upb_oneofdef_numfields(ptr_); }
142
+ FieldDefPtr field(int i) const { return FieldDefPtr(upb_oneofdef_field(ptr_, i)); }
143
143
 
144
144
  // Looks up by name.
145
145
  FieldDefPtr FindFieldByName(const char* name, size_t len) const {
@@ -159,40 +159,6 @@ class OneofDefPtr {
159
159
  return FieldDefPtr(upb_oneofdef_itof(ptr_, num));
160
160
  }
161
161
 
162
- class const_iterator
163
- : public std::iterator<std::forward_iterator_tag, FieldDefPtr> {
164
- public:
165
- void operator++() { upb_oneof_next(&iter_); }
166
-
167
- FieldDefPtr operator*() const {
168
- return FieldDefPtr(upb_oneof_iter_field(&iter_));
169
- }
170
-
171
- bool operator!=(const const_iterator& other) const {
172
- return !upb_oneof_iter_isequal(&iter_, &other.iter_);
173
- }
174
-
175
- bool operator==(const const_iterator& other) const {
176
- return upb_oneof_iter_isequal(&iter_, &other.iter_);
177
- }
178
-
179
- private:
180
- friend class OneofDefPtr;
181
-
182
- const_iterator() {}
183
- explicit const_iterator(OneofDefPtr o) { upb_oneof_begin(&iter_, o.ptr()); }
184
- static const_iterator end() {
185
- const_iterator iter;
186
- upb_oneof_iter_setdone(&iter.iter_);
187
- return iter;
188
- }
189
-
190
- upb_oneof_iter iter_;
191
- };
192
-
193
- const_iterator begin() const { return const_iterator(*this); }
194
- const_iterator end() const { return const_iterator::end(); }
195
-
196
162
  private:
197
163
  const upb_oneofdef* ptr_;
198
164
  };
@@ -211,9 +177,11 @@ class MessageDefPtr {
211
177
 
212
178
  // The number of fields that belong to the MessageDef.
213
179
  int field_count() const { return upb_msgdef_numfields(ptr_); }
180
+ FieldDefPtr field(int i) const { return FieldDefPtr(upb_msgdef_field(ptr_, i)); }
214
181
 
215
182
  // The number of oneofs that belong to the MessageDef.
216
183
  int oneof_count() const { return upb_msgdef_numoneofs(ptr_); }
184
+ OneofDefPtr oneof(int i) const { return OneofDefPtr(upb_msgdef_oneof(ptr_, i)); }
217
185
 
218
186
  upb_syntax_t syntax() const { return upb_msgdef_syntax(ptr_); }
219
187
 
@@ -258,112 +226,58 @@ class MessageDefPtr {
258
226
  // Whether is a number wrapper.
259
227
  bool isnumberwrapper() const { return upb_msgdef_isnumberwrapper(ptr_); }
260
228
 
261
- // Iteration over fields. The order is undefined.
262
- class const_field_iterator
263
- : public std::iterator<std::forward_iterator_tag, FieldDefPtr> {
229
+ private:
230
+ class FieldIter {
264
231
  public:
265
- void operator++() { upb_msg_field_next(&iter_); }
266
-
267
- FieldDefPtr operator*() const {
268
- return FieldDefPtr(upb_msg_iter_field(&iter_));
269
- }
232
+ explicit FieldIter(const upb_msgdef *m, int i) : m_(m), i_(i) {}
233
+ void operator++() { i_++; }
270
234
 
271
- bool operator!=(const const_field_iterator& other) const {
272
- return !upb_msg_field_iter_isequal(&iter_, &other.iter_);
273
- }
274
-
275
- bool operator==(const const_field_iterator& other) const {
276
- return upb_msg_field_iter_isequal(&iter_, &other.iter_);
277
- }
235
+ FieldDefPtr operator*() { return FieldDefPtr(upb_msgdef_field(m_, i_)); }
236
+ bool operator!=(const FieldIter& other) { return i_ != other.i_; }
237
+ bool operator==(const FieldIter& other) { return i_ == other.i_; }
278
238
 
279
239
  private:
280
- friend class MessageDefPtr;
281
-
282
- explicit const_field_iterator() {}
283
-
284
- explicit const_field_iterator(MessageDefPtr msg) {
285
- upb_msg_field_begin(&iter_, msg.ptr());
286
- }
287
-
288
- static const_field_iterator end() {
289
- const_field_iterator iter;
290
- upb_msg_field_iter_setdone(&iter.iter_);
291
- return iter;
292
- }
293
-
294
- upb_msg_field_iter iter_;
240
+ const upb_msgdef *m_;
241
+ int i_;
295
242
  };
296
243
 
297
- // Iteration over oneofs. The order is undefined.
298
- class const_oneof_iterator
299
- : public std::iterator<std::forward_iterator_tag, OneofDefPtr> {
244
+ class FieldAccessor {
300
245
  public:
301
- void operator++() { upb_msg_oneof_next(&iter_); }
302
-
303
- OneofDefPtr operator*() const {
304
- return OneofDefPtr(upb_msg_iter_oneof(&iter_));
305
- }
306
-
307
- bool operator!=(const const_oneof_iterator& other) const {
308
- return !upb_msg_oneof_iter_isequal(&iter_, &other.iter_);
309
- }
310
-
311
- bool operator==(const const_oneof_iterator& other) const {
312
- return upb_msg_oneof_iter_isequal(&iter_, &other.iter_);
313
- }
246
+ explicit FieldAccessor(const upb_msgdef* md) : md_(md) {}
247
+ FieldIter begin() { return FieldIter(md_, 0); }
248
+ FieldIter end() { return FieldIter(md_, upb_msgdef_fieldcount(md_)); }
314
249
 
315
250
  private:
316
- friend class MessageDefPtr;
317
-
318
- const_oneof_iterator() {}
319
-
320
- explicit const_oneof_iterator(MessageDefPtr msg) {
321
- upb_msg_oneof_begin(&iter_, msg.ptr());
322
- }
323
-
324
- static const_oneof_iterator end() {
325
- const_oneof_iterator iter;
326
- upb_msg_oneof_iter_setdone(&iter.iter_);
327
- return iter;
328
- }
329
-
330
- upb_msg_oneof_iter iter_;
251
+ const upb_msgdef* md_;
331
252
  };
332
253
 
333
- class ConstFieldAccessor {
254
+ class OneofIter {
334
255
  public:
335
- explicit ConstFieldAccessor(const upb_msgdef* md) : md_(md) {}
336
- const_field_iterator begin() { return MessageDefPtr(md_).field_begin(); }
337
- const_field_iterator end() { return MessageDefPtr(md_).field_end(); }
256
+ explicit OneofIter(const upb_msgdef *m, int i) : m_(m), i_(i) {}
257
+ void operator++() { i_++; }
258
+
259
+ OneofDefPtr operator*() { return OneofDefPtr(upb_msgdef_oneof(m_, i_)); }
260
+ bool operator!=(const OneofIter& other) { return i_ != other.i_; }
261
+ bool operator==(const OneofIter& other) { return i_ == other.i_; }
338
262
 
339
263
  private:
340
- const upb_msgdef* md_;
264
+ const upb_msgdef *m_;
265
+ int i_;
341
266
  };
342
267
 
343
- class ConstOneofAccessor {
268
+ class OneofAccessor {
344
269
  public:
345
- explicit ConstOneofAccessor(const upb_msgdef* md) : md_(md) {}
346
- const_oneof_iterator begin() { return MessageDefPtr(md_).oneof_begin(); }
347
- const_oneof_iterator end() { return MessageDefPtr(md_).oneof_end(); }
270
+ explicit OneofAccessor(const upb_msgdef* md) : md_(md) {}
271
+ OneofIter begin() { return OneofIter(md_, 0); }
272
+ OneofIter end() { return OneofIter(md_, upb_msgdef_oneofcount(md_)); }
348
273
 
349
274
  private:
350
275
  const upb_msgdef* md_;
351
276
  };
352
277
 
353
- const_field_iterator field_begin() const {
354
- return const_field_iterator(*this);
355
- }
356
-
357
- const_field_iterator field_end() const { return const_field_iterator::end(); }
358
-
359
- const_oneof_iterator oneof_begin() const {
360
- return const_oneof_iterator(*this);
361
- }
362
-
363
- const_oneof_iterator oneof_end() const { return const_oneof_iterator::end(); }
364
-
365
- ConstFieldAccessor fields() const { return ConstFieldAccessor(ptr()); }
366
- ConstOneofAccessor oneofs() const { return ConstOneofAccessor(ptr()); }
278
+ public:
279
+ FieldAccessor fields() const { return FieldAccessor(ptr()); }
280
+ OneofAccessor oneofs() const { return OneofAccessor(ptr()); }
367
281
 
368
282
  private:
369
283
  const upb_msgdef* ptr_;
@@ -2,35 +2,39 @@
2
2
 
3
3
  #include "upb/encode.h"
4
4
 
5
+ #include <setjmp.h>
5
6
  #include <string.h>
6
7
 
7
8
  #include "upb/msg.h"
8
9
  #include "upb/upb.h"
9
10
 
11
+ /* Must be last. */
10
12
  #include "upb/port_def.inc"
11
13
 
12
14
  #define UPB_PB_VARINT_MAX_LEN 10
13
- #define CHK(x) do { if (!(x)) { return false; } } while(0)
14
15
 
15
- static size_t upb_encode_varint(uint64_t val, char *buf) {
16
- size_t i;
17
- if (val < 128) { buf[0] = val; return 1; }
18
- i = 0;
19
- while (val) {
16
+ UPB_NOINLINE
17
+ static size_t encode_varint64(uint64_t val, char *buf) {
18
+ size_t i = 0;
19
+ do {
20
20
  uint8_t byte = val & 0x7fU;
21
21
  val >>= 7;
22
22
  if (val) byte |= 0x80U;
23
23
  buf[i++] = byte;
24
- }
24
+ } while (val);
25
25
  return i;
26
26
  }
27
27
 
28
- static uint32_t upb_zzencode_32(int32_t n) { return ((uint32_t)n << 1) ^ (n >> 31); }
29
- static uint64_t upb_zzencode_64(int64_t n) { return ((uint64_t)n << 1) ^ (n >> 63); }
28
+ static uint32_t encode_zz32(int32_t n) { return ((uint32_t)n << 1) ^ (n >> 31); }
29
+ static uint64_t encode_zz64(int64_t n) { return ((uint64_t)n << 1) ^ (n >> 63); }
30
30
 
31
31
  typedef struct {
32
+ jmp_buf err;
32
33
  upb_alloc *alloc;
33
34
  char *buf, *ptr, *limit;
35
+ int options;
36
+ int depth;
37
+ _upb_mapsorter sorter;
34
38
  } upb_encstate;
35
39
 
36
40
  static size_t upb_roundup_pow2(size_t bytes) {
@@ -41,11 +45,17 @@ static size_t upb_roundup_pow2(size_t bytes) {
41
45
  return ret;
42
46
  }
43
47
 
44
- static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
48
+ UPB_NORETURN static void encode_err(upb_encstate *e) {
49
+ UPB_LONGJMP(e->err, 1);
50
+ }
51
+
52
+ UPB_NOINLINE
53
+ static void encode_growbuffer(upb_encstate *e, size_t bytes) {
45
54
  size_t old_size = e->limit - e->buf;
46
55
  size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
47
56
  char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
48
- CHK(new_buf);
57
+
58
+ if (!new_buf) encode_err(e);
49
59
 
50
60
  /* We want previous data at the end, realloc() put it at the beginning. */
51
61
  if (old_size > 0) {
@@ -55,99 +65,116 @@ static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
55
65
  e->ptr = new_buf + new_size - (e->limit - e->ptr);
56
66
  e->limit = new_buf + new_size;
57
67
  e->buf = new_buf;
58
- return true;
68
+
69
+ e->ptr -= bytes;
59
70
  }
60
71
 
61
72
  /* Call to ensure that at least "bytes" bytes are available for writing at
62
73
  * e->ptr. Returns false if the bytes could not be allocated. */
63
- static bool upb_encode_reserve(upb_encstate *e, size_t bytes) {
64
- CHK(UPB_LIKELY((size_t)(e->ptr - e->buf) >= bytes) ||
65
- upb_encode_growbuffer(e, bytes));
74
+ UPB_FORCEINLINE
75
+ static void encode_reserve(upb_encstate *e, size_t bytes) {
76
+ if ((size_t)(e->ptr - e->buf) < bytes) {
77
+ encode_growbuffer(e, bytes);
78
+ return;
79
+ }
66
80
 
67
81
  e->ptr -= bytes;
68
- return true;
69
82
  }
70
83
 
71
84
  /* Writes the given bytes to the buffer, handling reserve/advance. */
72
- static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) {
73
- if (len == 0) return true;
74
- CHK(upb_encode_reserve(e, len));
85
+ static void encode_bytes(upb_encstate *e, const void *data, size_t len) {
86
+ if (len == 0) return; /* memcpy() with zero size is UB */
87
+ encode_reserve(e, len);
75
88
  memcpy(e->ptr, data, len);
76
- return true;
77
89
  }
78
90
 
79
- static bool upb_put_fixed64(upb_encstate *e, uint64_t val) {
91
+ static void encode_fixed64(upb_encstate *e, uint64_t val) {
80
92
  val = _upb_be_swap64(val);
81
- return upb_put_bytes(e, &val, sizeof(uint64_t));
93
+ encode_bytes(e, &val, sizeof(uint64_t));
82
94
  }
83
95
 
84
- static bool upb_put_fixed32(upb_encstate *e, uint32_t val) {
96
+ static void encode_fixed32(upb_encstate *e, uint32_t val) {
85
97
  val = _upb_be_swap32(val);
86
- return upb_put_bytes(e, &val, sizeof(uint32_t));
98
+ encode_bytes(e, &val, sizeof(uint32_t));
87
99
  }
88
100
 
89
- static bool upb_put_varint(upb_encstate *e, uint64_t val) {
101
+ UPB_NOINLINE
102
+ static void encode_longvarint(upb_encstate *e, uint64_t val) {
90
103
  size_t len;
91
104
  char *start;
92
- CHK(upb_encode_reserve(e, UPB_PB_VARINT_MAX_LEN));
93
- len = upb_encode_varint(val, e->ptr);
105
+
106
+ encode_reserve(e, UPB_PB_VARINT_MAX_LEN);
107
+ len = encode_varint64(val, e->ptr);
94
108
  start = e->ptr + UPB_PB_VARINT_MAX_LEN - len;
95
109
  memmove(start, e->ptr, len);
96
110
  e->ptr = start;
97
- return true;
98
111
  }
99
112
 
100
- static bool upb_put_double(upb_encstate *e, double d) {
113
+ UPB_FORCEINLINE
114
+ static void encode_varint(upb_encstate *e, uint64_t val) {
115
+ if (val < 128 && e->ptr != e->buf) {
116
+ --e->ptr;
117
+ *e->ptr = val;
118
+ } else {
119
+ encode_longvarint(e, val);
120
+ }
121
+ }
122
+
123
+ static void encode_double(upb_encstate *e, double d) {
101
124
  uint64_t u64;
102
125
  UPB_ASSERT(sizeof(double) == sizeof(uint64_t));
103
126
  memcpy(&u64, &d, sizeof(uint64_t));
104
- return upb_put_fixed64(e, u64);
127
+ encode_fixed64(e, u64);
105
128
  }
106
129
 
107
- static bool upb_put_float(upb_encstate *e, float d) {
130
+ static void encode_float(upb_encstate *e, float d) {
108
131
  uint32_t u32;
109
132
  UPB_ASSERT(sizeof(float) == sizeof(uint32_t));
110
133
  memcpy(&u32, &d, sizeof(uint32_t));
111
- return upb_put_fixed32(e, u32);
134
+ encode_fixed32(e, u32);
112
135
  }
113
136
 
114
- static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) {
115
- return upb_put_varint(e, (field_number << 3) | wire_type);
137
+ static void encode_tag(upb_encstate *e, uint32_t field_number,
138
+ uint8_t wire_type) {
139
+ encode_varint(e, (field_number << 3) | wire_type);
116
140
  }
117
141
 
118
- static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr,
142
+ static void encode_fixedarray(upb_encstate *e, const upb_array *arr,
119
143
  size_t elem_size, uint32_t tag) {
120
144
  size_t bytes = arr->len * elem_size;
121
145
  const char* data = _upb_array_constptr(arr);
122
146
  const char* ptr = data + bytes - elem_size;
123
147
  if (tag) {
124
148
  while (true) {
125
- CHK(upb_put_bytes(e, ptr, elem_size) && upb_put_varint(e, tag));
149
+ encode_bytes(e, ptr, elem_size);
150
+ encode_varint(e, tag);
126
151
  if (ptr == data) break;
127
152
  ptr -= elem_size;
128
153
  }
129
- return true;
130
154
  } else {
131
- return upb_put_bytes(e, data, bytes) && upb_put_varint(e, bytes);
155
+ encode_bytes(e, data, bytes);
132
156
  }
133
157
  }
134
158
 
135
- bool upb_encode_message(upb_encstate *e, const char *msg,
136
- const upb_msglayout *m, size_t *size);
159
+ static void encode_message(upb_encstate *e, const char *msg,
160
+ const upb_msglayout *m, size_t *size);
137
161
 
138
- static bool upb_encode_scalarfield(upb_encstate *e, const void *_field_mem,
139
- const upb_msglayout *m,
140
- const upb_msglayout_field *f,
141
- bool skip_zero_value) {
162
+ static void encode_scalar(upb_encstate *e, const void *_field_mem,
163
+ const upb_msglayout *m, const upb_msglayout_field *f,
164
+ bool skip_zero_value) {
142
165
  const char *field_mem = _field_mem;
143
- #define CASE(ctype, type, wire_type, encodeval) do { \
144
- ctype val = *(ctype*)field_mem; \
145
- if (skip_zero_value && val == 0) { \
146
- return true; \
147
- } \
148
- return upb_put_ ## type(e, encodeval) && \
149
- upb_put_tag(e, f->number, wire_type); \
150
- } while(0)
166
+ int wire_type;
167
+
168
+ #define CASE(ctype, type, wtype, encodeval) \
169
+ { \
170
+ ctype val = *(ctype *)field_mem; \
171
+ if (skip_zero_value && val == 0) { \
172
+ return; \
173
+ } \
174
+ encode_##type(e, encodeval); \
175
+ wire_type = wtype; \
176
+ break; \
177
+ }
151
178
 
152
179
  switch (f->descriptortype) {
153
180
  case UPB_DESCRIPTOR_TYPE_DOUBLE:
@@ -171,90 +198,95 @@ static bool upb_encode_scalarfield(upb_encstate *e, const void *_field_mem,
171
198
  case UPB_DESCRIPTOR_TYPE_BOOL:
172
199
  CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val);
173
200
  case UPB_DESCRIPTOR_TYPE_SINT32:
174
- CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_32(val));
201
+ CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, encode_zz32(val));
175
202
  case UPB_DESCRIPTOR_TYPE_SINT64:
176
- CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_64(val));
203
+ CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, encode_zz64(val));
177
204
  case UPB_DESCRIPTOR_TYPE_STRING:
178
205
  case UPB_DESCRIPTOR_TYPE_BYTES: {
179
206
  upb_strview view = *(upb_strview*)field_mem;
180
207
  if (skip_zero_value && view.size == 0) {
181
- return true;
208
+ return;
182
209
  }
183
- return upb_put_bytes(e, view.data, view.size) &&
184
- upb_put_varint(e, view.size) &&
185
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
210
+ encode_bytes(e, view.data, view.size);
211
+ encode_varint(e, view.size);
212
+ wire_type = UPB_WIRE_TYPE_DELIMITED;
213
+ break;
186
214
  }
187
215
  case UPB_DESCRIPTOR_TYPE_GROUP: {
188
216
  size_t size;
189
217
  void *submsg = *(void **)field_mem;
190
218
  const upb_msglayout *subm = m->submsgs[f->submsg_index];
191
219
  if (submsg == NULL) {
192
- return true;
220
+ return;
193
221
  }
194
- return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
195
- upb_encode_message(e, submsg, subm, &size) &&
196
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP);
222
+ if (--e->depth == 0) encode_err(e);
223
+ encode_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP);
224
+ encode_message(e, submsg, subm, &size);
225
+ wire_type = UPB_WIRE_TYPE_START_GROUP;
226
+ e->depth++;
227
+ break;
197
228
  }
198
229
  case UPB_DESCRIPTOR_TYPE_MESSAGE: {
199
230
  size_t size;
200
231
  void *submsg = *(void **)field_mem;
201
232
  const upb_msglayout *subm = m->submsgs[f->submsg_index];
202
233
  if (submsg == NULL) {
203
- return true;
234
+ return;
204
235
  }
205
- return upb_encode_message(e, submsg, subm, &size) &&
206
- upb_put_varint(e, size) &&
207
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
236
+ if (--e->depth == 0) encode_err(e);
237
+ encode_message(e, submsg, subm, &size);
238
+ encode_varint(e, size);
239
+ wire_type = UPB_WIRE_TYPE_DELIMITED;
240
+ e->depth++;
241
+ break;
208
242
  }
243
+ default:
244
+ UPB_UNREACHABLE();
209
245
  }
210
246
  #undef CASE
211
- UPB_UNREACHABLE();
247
+
248
+ encode_tag(e, f->number, wire_type);
212
249
  }
213
250
 
214
- static bool upb_encode_array(upb_encstate *e, const char *field_mem,
215
- const upb_msglayout *m,
216
- const upb_msglayout_field *f) {
251
+ static void encode_array(upb_encstate *e, const char *field_mem,
252
+ const upb_msglayout *m, const upb_msglayout_field *f) {
217
253
  const upb_array *arr = *(const upb_array**)field_mem;
218
254
  bool packed = f->label == _UPB_LABEL_PACKED;
255
+ size_t pre_len = e->limit - e->ptr;
219
256
 
220
257
  if (arr == NULL || arr->len == 0) {
221
- return true;
258
+ return;
222
259
  }
223
260
 
224
261
  #define VARINT_CASE(ctype, encode) \
225
262
  { \
226
263
  const ctype *start = _upb_array_constptr(arr); \
227
264
  const ctype *ptr = start + arr->len; \
228
- size_t pre_len = e->limit - e->ptr; \
229
265
  uint32_t tag = packed ? 0 : (f->number << 3) | UPB_WIRE_TYPE_VARINT; \
230
266
  do { \
231
267
  ptr--; \
232
- CHK(upb_put_varint(e, encode)); \
233
- if (tag) CHK(upb_put_varint(e, tag)); \
268
+ encode_varint(e, encode); \
269
+ if (tag) encode_varint(e, tag); \
234
270
  } while (ptr != start); \
235
- if (!tag) CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \
236
271
  } \
237
- break; \
238
- do { \
239
- ; \
240
- } while (0)
272
+ break;
241
273
 
242
274
  #define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type))
243
275
 
244
276
  switch (f->descriptortype) {
245
277
  case UPB_DESCRIPTOR_TYPE_DOUBLE:
246
- CHK(upb_put_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT)));
278
+ encode_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT));
247
279
  break;
248
280
  case UPB_DESCRIPTOR_TYPE_FLOAT:
249
- CHK(upb_put_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT)));
281
+ encode_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT));
250
282
  break;
251
283
  case UPB_DESCRIPTOR_TYPE_SFIXED64:
252
284
  case UPB_DESCRIPTOR_TYPE_FIXED64:
253
- CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT)));
285
+ encode_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT));
254
286
  break;
255
287
  case UPB_DESCRIPTOR_TYPE_FIXED32:
256
288
  case UPB_DESCRIPTOR_TYPE_SFIXED32:
257
- CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT)));
289
+ encode_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT));
258
290
  break;
259
291
  case UPB_DESCRIPTOR_TYPE_INT64:
260
292
  case UPB_DESCRIPTOR_TYPE_UINT64:
@@ -267,154 +299,180 @@ static bool upb_encode_array(upb_encstate *e, const char *field_mem,
267
299
  case UPB_DESCRIPTOR_TYPE_BOOL:
268
300
  VARINT_CASE(bool, *ptr);
269
301
  case UPB_DESCRIPTOR_TYPE_SINT32:
270
- VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
302
+ VARINT_CASE(int32_t, encode_zz32(*ptr));
271
303
  case UPB_DESCRIPTOR_TYPE_SINT64:
272
- VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
304
+ VARINT_CASE(int64_t, encode_zz64(*ptr));
273
305
  case UPB_DESCRIPTOR_TYPE_STRING:
274
306
  case UPB_DESCRIPTOR_TYPE_BYTES: {
275
307
  const upb_strview *start = _upb_array_constptr(arr);
276
308
  const upb_strview *ptr = start + arr->len;
277
309
  do {
278
310
  ptr--;
279
- CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
280
- upb_put_varint(e, ptr->size) &&
281
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
311
+ encode_bytes(e, ptr->data, ptr->size);
312
+ encode_varint(e, ptr->size);
313
+ encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
282
314
  } while (ptr != start);
283
- return true;
315
+ return;
284
316
  }
285
317
  case UPB_DESCRIPTOR_TYPE_GROUP: {
286
318
  const void *const*start = _upb_array_constptr(arr);
287
319
  const void *const*ptr = start + arr->len;
288
320
  const upb_msglayout *subm = m->submsgs[f->submsg_index];
321
+ if (--e->depth == 0) encode_err(e);
289
322
  do {
290
323
  size_t size;
291
324
  ptr--;
292
- CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
293
- upb_encode_message(e, *ptr, subm, &size) &&
294
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP));
325
+ encode_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP);
326
+ encode_message(e, *ptr, subm, &size);
327
+ encode_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP);
295
328
  } while (ptr != start);
296
- return true;
329
+ e->depth++;
330
+ return;
297
331
  }
298
332
  case UPB_DESCRIPTOR_TYPE_MESSAGE: {
299
333
  const void *const*start = _upb_array_constptr(arr);
300
334
  const void *const*ptr = start + arr->len;
301
335
  const upb_msglayout *subm = m->submsgs[f->submsg_index];
336
+ if (--e->depth == 0) encode_err(e);
302
337
  do {
303
338
  size_t size;
304
339
  ptr--;
305
- CHK(upb_encode_message(e, *ptr, subm, &size) &&
306
- upb_put_varint(e, size) &&
307
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
340
+ encode_message(e, *ptr, subm, &size);
341
+ encode_varint(e, size);
342
+ encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
308
343
  } while (ptr != start);
309
- return true;
344
+ e->depth++;
345
+ return;
310
346
  }
311
347
  }
312
348
  #undef VARINT_CASE
313
349
 
314
350
  if (packed) {
315
- CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
351
+ encode_varint(e, e->limit - e->ptr - pre_len);
352
+ encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
316
353
  }
317
- return true;
318
354
  }
319
355
 
320
- static bool upb_encode_map(upb_encstate *e, const char *field_mem,
321
- const upb_msglayout *m,
322
- const upb_msglayout_field *f) {
356
+ static void encode_mapentry(upb_encstate *e, uint32_t number,
357
+ const upb_msglayout *layout,
358
+ const upb_map_entry *ent) {
359
+ const upb_msglayout_field *key_field = &layout->fields[0];
360
+ const upb_msglayout_field *val_field = &layout->fields[1];
361
+ size_t pre_len = e->limit - e->ptr;
362
+ size_t size;
363
+ encode_scalar(e, &ent->v, layout, val_field, false);
364
+ encode_scalar(e, &ent->k, layout, key_field, false);
365
+ size = (e->limit - e->ptr) - pre_len;
366
+ encode_varint(e, size);
367
+ encode_tag(e, number, UPB_WIRE_TYPE_DELIMITED);
368
+ }
369
+
370
+ static void encode_map(upb_encstate *e, const char *field_mem,
371
+ const upb_msglayout *m, const upb_msglayout_field *f) {
323
372
  const upb_map *map = *(const upb_map**)field_mem;
324
- const upb_msglayout *entry = m->submsgs[f->submsg_index];
325
- const upb_msglayout_field *key_field = &entry->fields[0];
326
- const upb_msglayout_field *val_field = &entry->fields[1];
327
- upb_strtable_iter i;
328
- if (map == NULL) {
329
- return true;
330
- }
373
+ const upb_msglayout *layout = m->submsgs[f->submsg_index];
374
+ UPB_ASSERT(layout->field_count == 2);
375
+
376
+ if (map == NULL) return;
331
377
 
332
- upb_strtable_begin(&i, &map->table);
333
- for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
334
- size_t pre_len = e->limit - e->ptr;
335
- size_t size;
336
- upb_strview key = upb_strtable_iter_key(&i);
337
- const upb_value val = upb_strtable_iter_value(&i);
378
+ if (e->options & UPB_ENCODE_DETERMINISTIC) {
379
+ _upb_sortedmap sorted;
380
+ _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map,
381
+ &sorted);
338
382
  upb_map_entry ent;
339
- _upb_map_fromkey(key, &ent.k, map->key_size);
340
- _upb_map_fromvalue(val, &ent.v, map->val_size);
341
- CHK(upb_encode_scalarfield(e, &ent.v, entry, val_field, false));
342
- CHK(upb_encode_scalarfield(e, &ent.k, entry, key_field, false));
343
- size = (e->limit - e->ptr) - pre_len;
344
- CHK(upb_put_varint(e, size));
345
- CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
383
+ while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
384
+ encode_mapentry(e, f->number, layout, &ent);
385
+ }
386
+ _upb_mapsorter_popmap(&e->sorter, &sorted);
387
+ } else {
388
+ upb_strtable_iter i;
389
+ upb_strtable_begin(&i, &map->table);
390
+ for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
391
+ upb_strview key = upb_strtable_iter_key(&i);
392
+ const upb_value val = upb_strtable_iter_value(&i);
393
+ upb_map_entry ent;
394
+ _upb_map_fromkey(key, &ent.k, map->key_size);
395
+ _upb_map_fromvalue(val, &ent.v, map->val_size);
396
+ encode_mapentry(e, f->number, layout, &ent);
397
+ }
346
398
  }
347
-
348
- return true;
349
399
  }
350
400
 
401
+ static void encode_scalarfield(upb_encstate *e, const char *msg,
402
+ const upb_msglayout *m,
403
+ const upb_msglayout_field *f) {
404
+ bool skip_empty = false;
405
+ if (f->presence == 0) {
406
+ /* Proto3 presence. */
407
+ skip_empty = true;
408
+ } else if (f->presence > 0) {
409
+ /* Proto2 presence: hasbit. */
410
+ if (!_upb_hasbit_field(msg, f)) return;
411
+ } else {
412
+ /* Field is in a oneof. */
413
+ if (_upb_getoneofcase_field(msg, f) != f->number) return;
414
+ }
415
+ encode_scalar(e, msg + f->offset, m, f, skip_empty);
416
+ }
351
417
 
352
- bool upb_encode_message(upb_encstate *e, const char *msg,
353
- const upb_msglayout *m, size_t *size) {
354
- int i;
418
+ static void encode_message(upb_encstate *e, const char *msg,
419
+ const upb_msglayout *m, size_t *size) {
355
420
  size_t pre_len = e->limit - e->ptr;
356
- const char *unknown;
357
- size_t unknown_size;
421
+ const upb_msglayout_field *f = &m->fields[m->field_count];
422
+ const upb_msglayout_field *first = &m->fields[0];
358
423
 
359
- unknown = upb_msg_getunknown(msg, &unknown_size);
424
+ if ((e->options & UPB_ENCODE_SKIPUNKNOWN) == 0) {
425
+ size_t unknown_size;
426
+ const char *unknown = upb_msg_getunknown(msg, &unknown_size);
360
427
 
361
- if (unknown) {
362
- upb_put_bytes(e, unknown, unknown_size);
428
+ if (unknown) {
429
+ encode_bytes(e, unknown, unknown_size);
430
+ }
363
431
  }
364
432
 
365
- for (i = m->field_count - 1; i >= 0; i--) {
366
- const upb_msglayout_field *f = &m->fields[i];
367
-
433
+ while (f != first) {
434
+ f--;
368
435
  if (_upb_isrepeated(f)) {
369
- CHK(upb_encode_array(e, msg + f->offset, m, f));
436
+ encode_array(e, msg + f->offset, m, f);
370
437
  } else if (f->label == _UPB_LABEL_MAP) {
371
- CHK(upb_encode_map(e, msg + f->offset, m, f));
438
+ encode_map(e, msg + f->offset, m, f);
372
439
  } else {
373
- bool skip_empty = false;
374
- if (f->presence == 0) {
375
- /* Proto3 presence. */
376
- skip_empty = true;
377
- } else if (f->presence > 0) {
378
- /* Proto2 presence: hasbit. */
379
- if (!_upb_hasbit_field(msg, f)) {
380
- continue;
381
- }
382
- } else {
383
- /* Field is in a oneof. */
384
- if (_upb_getoneofcase_field(msg, f) != f->number) {
385
- continue;
386
- }
387
- }
388
- CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty));
440
+ encode_scalarfield(e, msg, m, f);
389
441
  }
390
442
  }
391
443
 
392
444
  *size = (e->limit - e->ptr) - pre_len;
393
- return true;
394
445
  }
395
446
 
396
- char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena,
397
- size_t *size) {
447
+ char *upb_encode_ex(const void *msg, const upb_msglayout *m, int options,
448
+ upb_arena *arena, size_t *size) {
398
449
  upb_encstate e;
450
+ unsigned depth = (unsigned)options >> 16;
451
+
399
452
  e.alloc = upb_arena_alloc(arena);
400
453
  e.buf = NULL;
401
454
  e.limit = NULL;
402
455
  e.ptr = NULL;
456
+ e.depth = depth ? depth : 64;
457
+ e.options = options;
458
+ _upb_mapsorter_init(&e.sorter);
459
+ char *ret = NULL;
403
460
 
404
- if (!upb_encode_message(&e, msg, m, size)) {
461
+ if (UPB_SETJMP(e.err)) {
405
462
  *size = 0;
406
- return NULL;
407
- }
408
-
409
- *size = e.limit - e.ptr;
410
-
411
- if (*size == 0) {
412
- static char ch;
413
- return &ch;
463
+ ret = NULL;
414
464
  } else {
415
- UPB_ASSERT(e.ptr);
416
- return e.ptr;
465
+ encode_message(&e, msg, m, size);
466
+ *size = e.limit - e.ptr;
467
+ if (*size == 0) {
468
+ static char ch;
469
+ ret = &ch;
470
+ } else {
471
+ UPB_ASSERT(e.ptr);
472
+ ret = e.ptr;
473
+ }
417
474
  }
418
- }
419
475
 
420
- #undef CHK
476
+ _upb_mapsorter_destroy(&e.sorter);
477
+ return ret;
478
+ }