grpc 1.45.0 → 1.46.3
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.
- checksums.yaml +4 -4
- data/Makefile +36 -29
- data/include/grpc/impl/codegen/grpc_types.h +7 -13
- data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +309 -0
- data/src/core/ext/filters/channel_idle/channel_idle_filter.h +122 -0
- data/src/core/ext/filters/{client_idle → channel_idle}/idle_filter_state.cc +1 -1
- data/src/core/ext/filters/{client_idle → channel_idle}/idle_filter_state.h +3 -3
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -96
- data/src/core/ext/filters/client_channel/client_channel.h +2 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +124 -581
- data/src/core/ext/filters/client_channel/health/health_check_client.h +24 -160
- data/src/core/ext/filters/client_channel/http_proxy.cc +88 -110
- data/src/core/ext/filters/client_channel/http_proxy.h +17 -0
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +182 -142
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +2 -6
- data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +1 -10
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +87 -58
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +51 -48
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +14 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +229 -284
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +92 -257
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +51 -221
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +201 -0
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +106 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +102 -55
- data/src/core/ext/filters/client_channel/retry_filter.cc +18 -3
- data/src/core/ext/filters/client_channel/subchannel.cc +5 -5
- data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +544 -0
- data/src/core/ext/filters/client_channel/subchannel_stream_client.h +214 -0
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +127 -367
- data/src/core/ext/filters/fault_injection/fault_injection_filter.h +24 -1
- data/src/core/ext/filters/http/client/http_client_filter.cc +78 -458
- data/src/core/ext/filters/http/client/http_client_filter.h +21 -4
- data/src/core/ext/filters/http/client_authority_filter.cc +17 -22
- data/src/core/ext/filters/http/client_authority_filter.h +6 -5
- data/src/core/ext/filters/http/http_filters_plugin.cc +9 -6
- data/src/core/ext/filters/http/server/http_server_filter.cc +2 -116
- data/src/core/ext/filters/server_config_selector/server_config_selector.cc +2 -8
- data/src/core/ext/filters/server_config_selector/server_config_selector.h +2 -2
- data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +73 -201
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +5 -4
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +139 -28
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -6
- data/src/core/ext/transport/chttp2/transport/internal.h +4 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +8 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +24 -13
- data/src/core/ext/upb-generated/envoy/admin/v3/certs.upb.c +27 -24
- data/src/core/ext/upb-generated/envoy/admin/v3/certs.upb.h +143 -63
- data/src/core/ext/upb-generated/envoy/admin/v3/clusters.upb.c +37 -35
- data/src/core/ext/upb-generated/envoy/admin/v3/clusters.upb.h +177 -77
- data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.c +115 -111
- data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.h +547 -207
- data/src/core/ext/upb-generated/envoy/admin/v3/init_dump.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/admin/v3/init_dump.upb.h +26 -13
- data/src/core/ext/upb-generated/envoy/admin/v3/listeners.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/admin/v3/listeners.upb.h +23 -9
- data/src/core/ext/upb-generated/envoy/admin/v3/memory.upb.c +7 -7
- data/src/core/ext/upb-generated/envoy/admin/v3/memory.upb.h +18 -0
- data/src/core/ext/upb-generated/envoy/admin/v3/metrics.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/admin/v3/metrics.upb.h +13 -4
- data/src/core/ext/upb-generated/envoy/admin/v3/mutex_stats.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/admin/v3/mutex_stats.upb.h +9 -0
- data/src/core/ext/upb-generated/envoy/admin/v3/server_info.upb.c +49 -46
- data/src/core/ext/upb-generated/envoy/admin/v3/server_info.upb.h +217 -78
- data/src/core/ext/upb-generated/envoy/admin/v3/tap.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/admin/v3/tap.upb.h +10 -2
- data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.c +12 -12
- data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +40 -8
- data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +20 -2
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +55 -55
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +289 -110
- data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +133 -125
- data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +656 -267
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +24 -18
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +96 -23
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +185 -173
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +860 -309
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +10 -2
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +44 -24
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +165 -40
- data/src/core/ext/upb-generated/envoy/config/common/matcher/v3/matcher.upb.c +72 -63
- data/src/core/ext/upb-generated/envoy/config/common/matcher/v3/matcher.upb.h +433 -174
- data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +33 -31
- data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +154 -52
- data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +5 -4
- data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +14 -4
- data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +89 -89
- data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +460 -166
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +76 -33
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +379 -69
- data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +14 -6
- data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +5 -25
- data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +10 -91
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_method_list.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_method_list.upb.h +26 -13
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +70 -68
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +369 -131
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +94 -65
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +447 -161
- data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +27 -11
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +104 -85
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +378 -113
- data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +3 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +6 -6
- data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +30 -13
- data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.c +7 -7
- data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +43 -16
- data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +58 -24
- data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +14 -4
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +18 -18
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +100 -43
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +31 -30
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +171 -71
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +32 -32
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +196 -95
- data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +7 -2
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +53 -46
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +284 -129
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +56 -50
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +337 -146
- data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +13 -11
- data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +49 -14
- data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +14 -4
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.h +20 -4
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.c +33 -32
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.h +205 -86
- data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c +34 -34
- data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.h +175 -74
- data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +56 -52
- data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +370 -146
- data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +27 -23
- data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +173 -74
- data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +362 -341
- data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +2056 -845
- data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +11 -11
- data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +49 -16
- data/src/core/ext/upb-generated/envoy/config/tap/v3/common.upb.c +56 -50
- data/src/core/ext/upb-generated/envoy/config/tap/v3/common.upb.h +293 -111
- data/src/core/ext/upb-generated/envoy/config/trace/v3/datadog.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/config/trace/v3/datadog.upb.h +6 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v3/dynamic_ot.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/config/trace/v3/dynamic_ot.upb.h +10 -2
- data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +26 -10
- data/src/core/ext/upb-generated/envoy/config/trace/v3/lightstep.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/config/trace/v3/lightstep.upb.h +27 -12
- data/src/core/ext/upb-generated/envoy/config/trace/v3/opencensus.upb.c +17 -16
- data/src/core/ext/upb-generated/envoy/config/trace/v3/opencensus.upb.h +83 -36
- data/src/core/ext/upb-generated/envoy/config/trace/v3/service.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/config/trace/v3/service.upb.h +7 -2
- data/src/core/ext/upb-generated/envoy/config/trace/v3/skywalking.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/trace/v3/skywalking.upb.h +46 -17
- data/src/core/ext/upb-generated/envoy/config/trace/v3/xray.upb.c +9 -9
- data/src/core/ext/upb-generated/envoy/config/trace/v3/xray.upb.h +38 -12
- data/src/core/ext/upb-generated/envoy/config/trace/v3/zipkin.upb.c +7 -7
- data/src/core/ext/upb-generated/envoy/config/trace/v3/zipkin.upb.h +30 -10
- data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.h +10 -6
- data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.c +15 -15
- data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.h +71 -28
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +25 -25
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +149 -65
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.c +8 -7
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +30 -12
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +9 -9
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +42 -15
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +173 -144
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +898 -323
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +51 -45
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +261 -116
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +13 -13
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +70 -25
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +80 -55
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +410 -124
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upb.h +23 -9
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.c +1 -1
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +44 -44
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +261 -122
- data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +47 -21
- data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +32 -32
- data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +175 -66
- data/src/core/ext/upb-generated/envoy/type/http/v3/cookie.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/type/http/v3/cookie.upb.h +17 -6
- data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +38 -17
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/http_inputs.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/http_inputs.upb.h +12 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +7 -7
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +43 -18
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.h +20 -9
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +3 -3
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +24 -9
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +14 -6
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +40 -16
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +9 -9
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +70 -25
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.h +37 -18
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +12 -12
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +81 -30
- data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +16 -16
- data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +76 -30
- data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +20 -20
- data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +90 -30
- data/src/core/ext/upb-generated/envoy/type/v3/hash_policy.upb.c +7 -7
- data/src/core/ext/upb-generated/envoy/type/v3/hash_policy.upb.h +28 -10
- data/src/core/ext/upb-generated/envoy/type/v3/http_status.upb.c +2 -2
- data/src/core/ext/upb-generated/envoy/type/v3/http_status.upb.h +3 -0
- data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +13 -4
- data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +9 -9
- data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +18 -0
- data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c +4 -4
- data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +9 -0
- data/src/core/ext/upb-generated/envoy/type/v3/token_bucket.upb.c +5 -5
- data/src/core/ext/upb-generated/envoy/type/v3/token_bucket.upb.h +17 -4
- data/src/core/ext/upb-generated/google/api/annotations.upb.c +3 -3
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +17 -2
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +70 -66
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +410 -162
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +80 -74
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +440 -158
- data/src/core/ext/upb-generated/google/api/http.upb.c +17 -17
- data/src/core/ext/upb-generated/google/api/http.upb.h +116 -43
- data/src/core/ext/upb-generated/google/api/httpbody.upb.c +4 -4
- data/src/core/ext/upb-generated/google/api/httpbody.upb.h +19 -7
- data/src/core/ext/upb-generated/google/protobuf/any.upb.c +3 -3
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +6 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +163 -162
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1157 -435
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +3 -3
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +10 -4
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +1 -1
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +15 -15
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +108 -40
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +3 -3
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +10 -4
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +18 -18
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.c +4 -4
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +19 -7
- data/src/core/ext/upb-generated/opencensus/proto/trace/v1/trace_config.upb.c +15 -15
- data/src/core/ext/upb-generated/opencensus/proto/trace/v1/trace_config.upb.h +65 -22
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +12 -12
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +49 -12
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +69 -65
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +364 -149
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +8 -7
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +20 -4
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +4 -4
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +31 -31
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +150 -58
- data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls.upb.c +11 -11
- data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls.upb.h +51 -18
- data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls_config.upb.c +175 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lookup/v1/rls_config.upb.h +764 -0
- data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +22 -22
- data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +97 -10
- data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +6 -6
- data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +23 -2
- data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.c +3 -3
- data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +10 -2
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +6 -6
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +27 -6
- data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +5 -5
- data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +20 -2
- data/src/core/ext/upb-generated/validate/validate.upb.c +261 -250
- data/src/core/ext/upb-generated/validate/validate.upb.h +1836 -663
- data/src/core/ext/upb-generated/xds/annotations/v3/migrate.upb.c +22 -22
- data/src/core/ext/upb-generated/xds/annotations/v3/migrate.upb.h +97 -10
- data/src/core/ext/upb-generated/xds/annotations/v3/security.upb.c +6 -6
- data/src/core/ext/upb-generated/xds/annotations/v3/security.upb.h +23 -2
- data/src/core/ext/upb-generated/xds/annotations/v3/sensitive.upb.c +3 -3
- data/src/core/ext/upb-generated/xds/annotations/v3/sensitive.upb.h +10 -2
- data/src/core/ext/upb-generated/xds/annotations/v3/status.upb.c +18 -18
- data/src/core/ext/upb-generated/xds/annotations/v3/status.upb.h +70 -10
- data/src/core/ext/upb-generated/xds/annotations/v3/versioning.upb.c +5 -5
- data/src/core/ext/upb-generated/xds/annotations/v3/versioning.upb.h +20 -2
- data/src/core/ext/upb-generated/xds/core/v3/authority.upb.c +2 -2
- data/src/core/ext/upb-generated/xds/core/v3/authority.upb.h +3 -0
- data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.c +8 -8
- data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.h +38 -12
- data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.c +5 -5
- data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.h +27 -10
- data/src/core/ext/upb-generated/xds/core/v3/extension.upb.c +3 -3
- data/src/core/ext/upb-generated/xds/core/v3/extension.upb.h +10 -2
- data/src/core/ext/upb-generated/xds/core/v3/resource.upb.c +5 -5
- data/src/core/ext/upb-generated/xds/core/v3/resource.upb.h +21 -8
- data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.c +10 -10
- data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.h +71 -30
- data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.c +5 -5
- data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.h +16 -2
- data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.c +12 -12
- data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.h +69 -26
- data/src/core/ext/upb-generated/xds/type/matcher/v3/matcher.upb.c +43 -39
- data/src/core/ext/upb-generated/xds/type/matcher/v3/matcher.upb.h +255 -103
- data/src/core/ext/upb-generated/xds/type/matcher/v3/regex.upb.c +4 -4
- data/src/core/ext/upb-generated/xds/type/matcher/v3/regex.upb.h +19 -8
- data/src/core/ext/upb-generated/xds/type/matcher/v3/string.upb.c +9 -9
- data/src/core/ext/upb-generated/xds/type/matcher/v3/string.upb.h +70 -25
- data/src/core/ext/upb-generated/xds/type/v3/typed_struct.upb.c +3 -3
- data/src/core/ext/upb-generated/xds/type/v3/typed_struct.upb.h +10 -2
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +50 -46
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +195 -185
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +16 -12
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +129 -94
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +10 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +18 -33
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +0 -5
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +163 -155
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +141 -138
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +26 -20
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +738 -730
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +271 -251
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +207 -193
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/src/proto/grpc/lookup/v1/rls_config.upbdefs.c +99 -0
- data/src/core/ext/upbdefs-generated/src/proto/grpc/lookup/v1/rls_config.upbdefs.h +75 -0
- data/src/core/ext/xds/certificate_provider_store.cc +8 -0
- data/src/core/ext/xds/certificate_provider_store.h +9 -0
- data/src/core/ext/xds/xds_api.cc +20 -0
- data/src/core/ext/xds/xds_bootstrap.cc +2 -2
- data/src/core/ext/xds/xds_bootstrap.h +2 -0
- data/src/core/ext/xds/xds_certificate_provider.cc +2 -0
- data/src/core/ext/xds/xds_certificate_provider.h +8 -0
- data/src/core/ext/xds/xds_client.cc +87 -95
- data/src/core/ext/xds/xds_client.h +13 -5
- data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +142 -0
- data/src/core/ext/xds/xds_cluster_specifier_plugin.h +79 -0
- data/src/core/ext/xds/xds_common_types.cc +9 -9
- data/src/core/ext/xds/xds_common_types.h +3 -3
- data/src/core/ext/xds/xds_endpoint.cc +12 -5
- data/src/core/ext/xds/xds_http_fault_filter.cc +1 -1
- data/src/core/ext/xds/xds_listener.cc +1 -1
- data/src/core/ext/xds/xds_route_config.cc +162 -25
- data/src/core/ext/xds/xds_route_config.h +13 -10
- data/src/core/ext/xds/xds_server_config_fetcher.cc +17 -22
- data/src/core/lib/avl/avl.h +68 -5
- data/src/core/lib/channel/call_tracer.h +4 -1
- data/src/core/lib/channel/channel_args.cc +138 -59
- data/src/core/lib/channel/channel_args.h +210 -9
- data/src/core/lib/channel/channel_args_preconditioning.cc +3 -9
- data/src/core/lib/channel/channel_args_preconditioning.h +1 -2
- data/src/core/lib/channel/channel_stack.h +2 -5
- data/src/core/lib/channel/channel_stack_builder.cc +0 -65
- data/src/core/lib/channel/channel_stack_builder.h +27 -6
- data/src/core/lib/channel/channel_stack_builder_impl.cc +102 -0
- data/src/core/lib/channel/channel_stack_builder_impl.h +48 -0
- data/src/core/lib/channel/connected_channel.h +1 -0
- data/src/core/lib/channel/promise_based_filter.cc +495 -162
- data/src/core/lib/channel/promise_based_filter.h +55 -41
- data/src/core/lib/compression/compression_internal.cc +1 -7
- data/src/core/lib/debug/stats_data.cc +2 -6
- data/src/core/lib/debug/stats_data.h +18 -21
- data/src/core/lib/gpr/tls.h +1 -0
- data/src/core/lib/gprpp/bitset.h +12 -0
- data/src/core/lib/gprpp/cpp_impl_of.h +4 -0
- data/src/core/lib/gprpp/match.h +73 -0
- data/src/core/lib/gprpp/overload.h +59 -0
- data/src/core/lib/gprpp/ref_counted.h +2 -0
- data/src/core/lib/gprpp/single_set_ptr.h +87 -0
- data/src/core/lib/gprpp/status_helper.cc +18 -2
- data/src/core/lib/gprpp/time.cc +12 -0
- data/src/core/lib/gprpp/time.h +1 -1
- data/src/core/lib/http/format_request.cc +1 -2
- data/src/core/lib/http/httpcli_security_connector.cc +5 -5
- data/src/core/lib/http/parser.cc +80 -9
- data/src/core/lib/http/parser.h +14 -1
- data/src/core/lib/iomgr/ev_posix.cc +6 -7
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/port.h +0 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +2 -2
- data/src/core/lib/iomgr/tcp_posix.cc +93 -35
- data/src/core/lib/iomgr/tcp_server_posix.cc +26 -17
- data/src/core/lib/json/json_util.h +3 -3
- data/src/core/lib/promise/call_push_pull.h +144 -0
- data/src/core/lib/promise/detail/status.h +2 -1
- data/src/core/lib/promise/intra_activity_waiter.h +49 -0
- data/src/core/lib/promise/latch.h +104 -0
- data/src/core/lib/resource_quota/api.cc +5 -30
- data/src/core/lib/resource_quota/api.h +1 -1
- data/src/core/lib/resource_quota/resource_quota.h +8 -0
- data/src/core/lib/security/authorization/authorization_policy_provider.h +7 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +9 -12
- data/src/core/lib/security/authorization/grpc_server_authz_filter.h +5 -6
- data/src/core/lib/security/context/security_context.h +8 -1
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +6 -5
- data/src/core/lib/security/credentials/alts/alts_credentials.h +4 -0
- data/src/core/lib/security/credentials/call_creds_util.cc +3 -3
- data/src/core/lib/security/credentials/call_creds_util.h +2 -2
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +15 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.h +9 -8
- data/src/core/lib/security/credentials/credentials.h +16 -33
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +8 -12
- data/src/core/lib/security/credentials/fake/fake_credentials.h +8 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +4 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +3 -3
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +5 -4
- data/src/core/lib/security/credentials/iam/iam_credentials.h +6 -2
- data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +22 -29
- data/src/core/lib/security/credentials/insecure/insecure_credentials.h +57 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -3
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +6 -2
- data/src/core/lib/security/credentials/local/local_credentials.cc +6 -6
- data/src/core/lib/security/credentials/local/local_credentials.h +4 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +17 -9
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +14 -6
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +8 -6
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +8 -6
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +6 -4
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +8 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +49 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc +8 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h +42 -3
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +66 -95
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +9 -6
- data/src/core/lib/security/credentials/tls/tls_credentials.h +5 -5
- data/src/core/lib/security/credentials/xds/xds_credentials.cc +48 -50
- data/src/core/lib/security/credentials/xds/xds_credentials.h +31 -5
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +2 -2
- data/src/core/lib/security/security_connector/security_connector.h +9 -0
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -2
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +4 -2
- data/src/core/lib/security/transport/auth_filters.h +7 -7
- data/src/core/lib/security/transport/client_auth_filter.cc +28 -20
- data/src/core/lib/security/transport/secure_endpoint.cc +198 -129
- data/src/core/lib/security/transport/secure_endpoint.h +1 -1
- data/src/core/lib/security/transport/security_handshaker.cc +6 -4
- data/src/core/lib/surface/call.cc +1023 -903
- data/src/core/lib/surface/call.h +0 -14
- data/src/core/lib/surface/channel.cc +4 -3
- data/src/core/lib/surface/channel_init.cc +2 -3
- data/src/core/lib/surface/channel_init.h +2 -6
- data/src/core/lib/surface/init.cc +1 -1
- data/src/core/lib/surface/server.cc +3 -14
- data/src/core/lib/surface/server.h +1 -2
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/byte_stream.cc +2 -0
- data/src/core/lib/transport/metadata_batch.h +12 -8
- data/src/core/lib/transport/transport.h +20 -5
- data/src/core/lib/transport/transport_impl.h +4 -3
- data/src/core/plugin_registry/grpc_plugin_registry.cc +2 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -2
- data/src/core/tsi/ssl_transport_security.cc +75 -38
- data/src/core/tsi/ssl_transport_security.h +8 -2
- data/src/core/tsi/transport_security_interface.h +2 -0
- data/src/ruby/ext/grpc/extconf.rb +1 -1
- data/src/ruby/lib/grpc/generic/active_call.rb +7 -1
- data/src/ruby/lib/grpc/grpc.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/generate_proto_ruby.sh +1 -0
- data/src/ruby/pb/test/client.rb +769 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/third_party/upb/third_party/utf8_range/utf8_range.h +1 -1
- data/third_party/upb/upb/decode.c +32 -16
- data/third_party/upb/upb/def.c +118 -55
- data/third_party/upb/upb/def.h +12 -3
- data/third_party/upb/upb/encode.c +14 -8
- data/third_party/upb/upb/json_encode.c +776 -0
- data/third_party/upb/upb/json_encode.h +62 -0
- data/third_party/upb/upb/msg.c +5 -7
- data/third_party/upb/upb/msg.h +1 -2
- data/third_party/upb/upb/msg_internal.h +49 -36
- data/third_party/upb/upb/port_def.inc +8 -0
- data/third_party/upb/upb/port_undef.inc +1 -0
- data/third_party/upb/upb/table.c +10 -6
- data/third_party/upb/upb/table_internal.h +2 -0
- data/third_party/upb/upb/upb.h +41 -11
- data/third_party/zlib/crc32.c +966 -292
- data/third_party/zlib/crc32.h +9441 -436
- data/third_party/zlib/deflate.c +78 -30
- data/third_party/zlib/deflate.h +12 -15
- data/third_party/zlib/gzguts.h +3 -2
- data/third_party/zlib/gzlib.c +5 -3
- data/third_party/zlib/gzread.c +5 -7
- data/third_party/zlib/gzwrite.c +25 -13
- data/third_party/zlib/infback.c +2 -1
- data/third_party/zlib/inffast.c +14 -14
- data/third_party/zlib/inflate.c +39 -8
- data/third_party/zlib/inflate.h +3 -2
- data/third_party/zlib/inftrees.c +3 -3
- data/third_party/zlib/trees.c +27 -48
- data/third_party/zlib/zlib.h +123 -100
- data/third_party/zlib/zutil.c +2 -2
- data/third_party/zlib/zutil.h +12 -9
- metadata +66 -45
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +0 -201
- data/src/core/ext/filters/max_age/max_age_filter.cc +0 -566
- data/src/core/ext/filters/max_age/max_age_filter.h +0 -26
- data/src/core/lib/iomgr/ev_epollex_linux.cc +0 -1657
- data/src/core/lib/iomgr/ev_epollex_linux.h +0 -30
- data/src/core/lib/iomgr/is_epollexclusive_available.cc +0 -119
- data/src/core/lib/iomgr/is_epollexclusive_available.h +0 -36
- data/src/core/lib/iomgr/sys_epoll_wrapper.h +0 -30
@@ -0,0 +1,776 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
12
|
+
* * Neither the name of Google LLC nor the
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
14
|
+
* derived from this software without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include "upb/json_encode.h"
|
29
|
+
|
30
|
+
#include <ctype.h>
|
31
|
+
#include <float.h>
|
32
|
+
#include <inttypes.h>
|
33
|
+
#include <math.h>
|
34
|
+
#include <setjmp.h>
|
35
|
+
#include <stdarg.h>
|
36
|
+
#include <stdio.h>
|
37
|
+
#include <string.h>
|
38
|
+
|
39
|
+
#include "upb/decode.h"
|
40
|
+
#include "upb/reflection.h"
|
41
|
+
#include "upb/upb_internal.h"
|
42
|
+
|
43
|
+
/* Must be last. */
|
44
|
+
#include "upb/port_def.inc"
|
45
|
+
|
46
|
+
typedef struct {
|
47
|
+
char *buf, *ptr, *end;
|
48
|
+
size_t overflow;
|
49
|
+
int indent_depth;
|
50
|
+
int options;
|
51
|
+
const upb_DefPool* ext_pool;
|
52
|
+
jmp_buf err;
|
53
|
+
upb_Status* status;
|
54
|
+
upb_Arena* arena;
|
55
|
+
} jsonenc;
|
56
|
+
|
57
|
+
static void jsonenc_msg(jsonenc* e, const upb_Message* msg,
|
58
|
+
const upb_MessageDef* m);
|
59
|
+
static void jsonenc_scalar(jsonenc* e, upb_MessageValue val,
|
60
|
+
const upb_FieldDef* f);
|
61
|
+
static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg,
|
62
|
+
const upb_MessageDef* m);
|
63
|
+
static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg,
|
64
|
+
const upb_MessageDef* m, bool first);
|
65
|
+
static void jsonenc_value(jsonenc* e, const upb_Message* msg,
|
66
|
+
const upb_MessageDef* m);
|
67
|
+
|
68
|
+
UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) {
|
69
|
+
upb_Status_SetErrorMessage(e->status, msg);
|
70
|
+
longjmp(e->err, 1);
|
71
|
+
}
|
72
|
+
|
73
|
+
UPB_PRINTF(2, 3)
|
74
|
+
UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) {
|
75
|
+
va_list argp;
|
76
|
+
va_start(argp, fmt);
|
77
|
+
upb_Status_VSetErrorFormat(e->status, fmt, argp);
|
78
|
+
va_end(argp);
|
79
|
+
longjmp(e->err, 1);
|
80
|
+
}
|
81
|
+
|
82
|
+
static upb_Arena* jsonenc_arena(jsonenc* e) {
|
83
|
+
/* Create lazily, since it's only needed for Any */
|
84
|
+
if (!e->arena) {
|
85
|
+
e->arena = upb_Arena_New();
|
86
|
+
}
|
87
|
+
return e->arena;
|
88
|
+
}
|
89
|
+
|
90
|
+
static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) {
|
91
|
+
size_t have = e->end - e->ptr;
|
92
|
+
if (UPB_LIKELY(have >= len)) {
|
93
|
+
memcpy(e->ptr, data, len);
|
94
|
+
e->ptr += len;
|
95
|
+
} else {
|
96
|
+
if (have) {
|
97
|
+
memcpy(e->ptr, data, have);
|
98
|
+
e->ptr += have;
|
99
|
+
}
|
100
|
+
e->overflow += (len - have);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
static void jsonenc_putstr(jsonenc* e, const char* str) {
|
105
|
+
jsonenc_putbytes(e, str, strlen(str));
|
106
|
+
}
|
107
|
+
|
108
|
+
UPB_PRINTF(2, 3)
|
109
|
+
static void jsonenc_printf(jsonenc* e, const char* fmt, ...) {
|
110
|
+
size_t n;
|
111
|
+
size_t have = e->end - e->ptr;
|
112
|
+
va_list args;
|
113
|
+
|
114
|
+
va_start(args, fmt);
|
115
|
+
n = vsnprintf(e->ptr, have, fmt, args);
|
116
|
+
va_end(args);
|
117
|
+
|
118
|
+
if (UPB_LIKELY(have > n)) {
|
119
|
+
e->ptr += n;
|
120
|
+
} else {
|
121
|
+
e->ptr = UPB_PTRADD(e->ptr, have);
|
122
|
+
e->overflow += (n - have);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
static void jsonenc_nanos(jsonenc* e, int32_t nanos) {
|
127
|
+
int digits = 9;
|
128
|
+
|
129
|
+
if (nanos == 0) return;
|
130
|
+
if (nanos < 0 || nanos >= 1000000000) {
|
131
|
+
jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos");
|
132
|
+
}
|
133
|
+
|
134
|
+
while (nanos % 1000 == 0) {
|
135
|
+
nanos /= 1000;
|
136
|
+
digits -= 3;
|
137
|
+
}
|
138
|
+
|
139
|
+
jsonenc_printf(e, ".%.*" PRId32, digits, nanos);
|
140
|
+
}
|
141
|
+
|
142
|
+
static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
|
143
|
+
const upb_MessageDef* m) {
|
144
|
+
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
145
|
+
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
|
146
|
+
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
|
147
|
+
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
|
148
|
+
int L, N, I, J, K, hour, min, sec;
|
149
|
+
|
150
|
+
if (seconds < -62135596800) {
|
151
|
+
jsonenc_err(e,
|
152
|
+
"error formatting timestamp as JSON: minimum acceptable value "
|
153
|
+
"is 0001-01-01T00:00:00Z");
|
154
|
+
} else if (seconds > 253402300799) {
|
155
|
+
jsonenc_err(e,
|
156
|
+
"error formatting timestamp as JSON: maximum acceptable value "
|
157
|
+
"is 9999-12-31T23:59:59Z");
|
158
|
+
}
|
159
|
+
|
160
|
+
/* Julian Day -> Y/M/D, Algorithm from:
|
161
|
+
* Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for
|
162
|
+
* Processing Calendar Dates," Communications of the Association of
|
163
|
+
* Computing Machines, vol. 11 (1968), p. 657. */
|
164
|
+
seconds += 62135596800; // Ensure seconds is positive.
|
165
|
+
L = (int)(seconds / 86400) - 719162 + 68569 + 2440588;
|
166
|
+
N = 4 * L / 146097;
|
167
|
+
L = L - (146097 * N + 3) / 4;
|
168
|
+
I = 4000 * (L + 1) / 1461001;
|
169
|
+
L = L - 1461 * I / 4 + 31;
|
170
|
+
J = 80 * L / 2447;
|
171
|
+
K = L - 2447 * J / 80;
|
172
|
+
L = J / 11;
|
173
|
+
J = J + 2 - 12 * L;
|
174
|
+
I = 100 * (N - 49) + I + L;
|
175
|
+
|
176
|
+
sec = seconds % 60;
|
177
|
+
min = (seconds / 60) % 60;
|
178
|
+
hour = (seconds / 3600) % 24;
|
179
|
+
|
180
|
+
jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec);
|
181
|
+
jsonenc_nanos(e, nanos);
|
182
|
+
jsonenc_putstr(e, "Z\"");
|
183
|
+
}
|
184
|
+
|
185
|
+
static void jsonenc_duration(jsonenc* e, const upb_Message* msg,
|
186
|
+
const upb_MessageDef* m) {
|
187
|
+
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
188
|
+
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
|
189
|
+
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
|
190
|
+
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
|
191
|
+
|
192
|
+
if (seconds > 315576000000 || seconds < -315576000000 ||
|
193
|
+
(seconds < 0) != (nanos < 0)) {
|
194
|
+
jsonenc_err(e, "bad duration");
|
195
|
+
}
|
196
|
+
|
197
|
+
if (nanos < 0) {
|
198
|
+
nanos = -nanos;
|
199
|
+
}
|
200
|
+
|
201
|
+
jsonenc_printf(e, "\"%" PRId64, seconds);
|
202
|
+
jsonenc_nanos(e, nanos);
|
203
|
+
jsonenc_putstr(e, "s\"");
|
204
|
+
}
|
205
|
+
|
206
|
+
static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) {
|
207
|
+
const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f);
|
208
|
+
|
209
|
+
if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) {
|
210
|
+
jsonenc_putstr(e, "null");
|
211
|
+
} else {
|
212
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val);
|
213
|
+
|
214
|
+
if (ev) {
|
215
|
+
jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev));
|
216
|
+
} else {
|
217
|
+
jsonenc_printf(e, "%" PRId32, val);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
static void jsonenc_bytes(jsonenc* e, upb_StringView str) {
|
223
|
+
/* This is the regular base64, not the "web-safe" version. */
|
224
|
+
static const char base64[] =
|
225
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
226
|
+
const unsigned char* ptr = (unsigned char*)str.data;
|
227
|
+
const unsigned char* end = UPB_PTRADD(ptr, str.size);
|
228
|
+
char buf[4];
|
229
|
+
|
230
|
+
jsonenc_putstr(e, "\"");
|
231
|
+
|
232
|
+
while (end - ptr >= 3) {
|
233
|
+
buf[0] = base64[ptr[0] >> 2];
|
234
|
+
buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)];
|
235
|
+
buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)];
|
236
|
+
buf[3] = base64[ptr[2] & 0x3f];
|
237
|
+
jsonenc_putbytes(e, buf, 4);
|
238
|
+
ptr += 3;
|
239
|
+
}
|
240
|
+
|
241
|
+
switch (end - ptr) {
|
242
|
+
case 2:
|
243
|
+
buf[0] = base64[ptr[0] >> 2];
|
244
|
+
buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)];
|
245
|
+
buf[2] = base64[(ptr[1] & 0xf) << 2];
|
246
|
+
buf[3] = '=';
|
247
|
+
jsonenc_putbytes(e, buf, 4);
|
248
|
+
break;
|
249
|
+
case 1:
|
250
|
+
buf[0] = base64[ptr[0] >> 2];
|
251
|
+
buf[1] = base64[((ptr[0] & 0x3) << 4)];
|
252
|
+
buf[2] = '=';
|
253
|
+
buf[3] = '=';
|
254
|
+
jsonenc_putbytes(e, buf, 4);
|
255
|
+
break;
|
256
|
+
}
|
257
|
+
|
258
|
+
jsonenc_putstr(e, "\"");
|
259
|
+
}
|
260
|
+
|
261
|
+
static void jsonenc_stringbody(jsonenc* e, upb_StringView str) {
|
262
|
+
const char* ptr = str.data;
|
263
|
+
const char* end = UPB_PTRADD(ptr, str.size);
|
264
|
+
|
265
|
+
while (ptr < end) {
|
266
|
+
switch (*ptr) {
|
267
|
+
case '\n':
|
268
|
+
jsonenc_putstr(e, "\\n");
|
269
|
+
break;
|
270
|
+
case '\r':
|
271
|
+
jsonenc_putstr(e, "\\r");
|
272
|
+
break;
|
273
|
+
case '\t':
|
274
|
+
jsonenc_putstr(e, "\\t");
|
275
|
+
break;
|
276
|
+
case '\"':
|
277
|
+
jsonenc_putstr(e, "\\\"");
|
278
|
+
break;
|
279
|
+
case '\f':
|
280
|
+
jsonenc_putstr(e, "\\f");
|
281
|
+
break;
|
282
|
+
case '\b':
|
283
|
+
jsonenc_putstr(e, "\\b");
|
284
|
+
break;
|
285
|
+
case '\\':
|
286
|
+
jsonenc_putstr(e, "\\\\");
|
287
|
+
break;
|
288
|
+
default:
|
289
|
+
if ((uint8_t)*ptr < 0x20) {
|
290
|
+
jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr);
|
291
|
+
} else {
|
292
|
+
/* This could be a non-ASCII byte. We rely on the string being valid
|
293
|
+
* UTF-8. */
|
294
|
+
jsonenc_putbytes(e, ptr, 1);
|
295
|
+
}
|
296
|
+
break;
|
297
|
+
}
|
298
|
+
ptr++;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
static void jsonenc_string(jsonenc* e, upb_StringView str) {
|
303
|
+
jsonenc_putstr(e, "\"");
|
304
|
+
jsonenc_stringbody(e, str);
|
305
|
+
jsonenc_putstr(e, "\"");
|
306
|
+
}
|
307
|
+
|
308
|
+
static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) {
|
309
|
+
if (val == INFINITY) {
|
310
|
+
jsonenc_putstr(e, "\"Infinity\"");
|
311
|
+
} else if (val == -INFINITY) {
|
312
|
+
jsonenc_putstr(e, "\"-Infinity\"");
|
313
|
+
} else if (val != val) {
|
314
|
+
jsonenc_putstr(e, "\"NaN\"");
|
315
|
+
} else {
|
316
|
+
return false;
|
317
|
+
}
|
318
|
+
return true;
|
319
|
+
}
|
320
|
+
|
321
|
+
static void upb_JsonEncode_Double(jsonenc* e, double val) {
|
322
|
+
if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return;
|
323
|
+
char buf[32];
|
324
|
+
_upb_EncodeRoundTripDouble(val, buf, sizeof(buf));
|
325
|
+
jsonenc_putstr(e, buf);
|
326
|
+
}
|
327
|
+
|
328
|
+
static void upb_JsonEncode_Float(jsonenc* e, float val) {
|
329
|
+
if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return;
|
330
|
+
char buf[32];
|
331
|
+
_upb_EncodeRoundTripFloat(val, buf, sizeof(buf));
|
332
|
+
jsonenc_putstr(e, buf);
|
333
|
+
}
|
334
|
+
|
335
|
+
static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg,
|
336
|
+
const upb_MessageDef* m) {
|
337
|
+
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
338
|
+
upb_MessageValue val = upb_Message_Get(msg, val_f);
|
339
|
+
jsonenc_scalar(e, val, val_f);
|
340
|
+
}
|
341
|
+
|
342
|
+
static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e,
|
343
|
+
upb_StringView type_url) {
|
344
|
+
/* Find last '/', if any. */
|
345
|
+
const char* end = type_url.data + type_url.size;
|
346
|
+
const char* ptr = end;
|
347
|
+
const upb_MessageDef* ret;
|
348
|
+
|
349
|
+
if (!e->ext_pool) {
|
350
|
+
jsonenc_err(e, "Tried to encode Any, but no symtab was provided");
|
351
|
+
}
|
352
|
+
|
353
|
+
if (type_url.size == 0) goto badurl;
|
354
|
+
|
355
|
+
while (true) {
|
356
|
+
if (--ptr == type_url.data) {
|
357
|
+
/* Type URL must contain at least one '/', with host before. */
|
358
|
+
goto badurl;
|
359
|
+
}
|
360
|
+
if (*ptr == '/') {
|
361
|
+
ptr++;
|
362
|
+
break;
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr);
|
367
|
+
|
368
|
+
if (!ret) {
|
369
|
+
jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr);
|
370
|
+
}
|
371
|
+
|
372
|
+
return ret;
|
373
|
+
|
374
|
+
badurl:
|
375
|
+
jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT,
|
376
|
+
UPB_STRINGVIEW_ARGS(type_url));
|
377
|
+
}
|
378
|
+
|
379
|
+
static void jsonenc_any(jsonenc* e, const upb_Message* msg,
|
380
|
+
const upb_MessageDef* m) {
|
381
|
+
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
382
|
+
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2);
|
383
|
+
upb_StringView type_url = upb_Message_Get(msg, type_url_f).str_val;
|
384
|
+
upb_StringView value = upb_Message_Get(msg, value_f).str_val;
|
385
|
+
const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url);
|
386
|
+
const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m);
|
387
|
+
upb_Arena* arena = jsonenc_arena(e);
|
388
|
+
upb_Message* any = upb_Message_New(any_m, arena);
|
389
|
+
|
390
|
+
if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) !=
|
391
|
+
kUpb_DecodeStatus_Ok) {
|
392
|
+
jsonenc_err(e, "Error decoding message in Any");
|
393
|
+
}
|
394
|
+
|
395
|
+
jsonenc_putstr(e, "{\"@type\":");
|
396
|
+
jsonenc_string(e, type_url);
|
397
|
+
|
398
|
+
if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) {
|
399
|
+
/* Regular messages: {"@type": "...","foo": 1, "bar": 2} */
|
400
|
+
jsonenc_msgfields(e, any, any_m, false);
|
401
|
+
} else {
|
402
|
+
/* Well-known type: {"@type": "...","value": <well-known encoding>} */
|
403
|
+
jsonenc_putstr(e, ",\"value\":");
|
404
|
+
jsonenc_msgfield(e, any, any_m);
|
405
|
+
}
|
406
|
+
|
407
|
+
jsonenc_putstr(e, "}");
|
408
|
+
}
|
409
|
+
|
410
|
+
static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) {
|
411
|
+
if (*first) {
|
412
|
+
*first = false;
|
413
|
+
} else {
|
414
|
+
jsonenc_putstr(e, str);
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) {
|
419
|
+
const char* ptr = path.data;
|
420
|
+
const char* end = ptr + path.size;
|
421
|
+
|
422
|
+
while (ptr < end) {
|
423
|
+
char ch = *ptr;
|
424
|
+
|
425
|
+
if (ch >= 'A' && ch <= 'Z') {
|
426
|
+
jsonenc_err(e, "Field mask element may not have upper-case letter.");
|
427
|
+
} else if (ch == '_') {
|
428
|
+
if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') {
|
429
|
+
jsonenc_err(e, "Underscore must be followed by a lowercase letter.");
|
430
|
+
}
|
431
|
+
ch = *++ptr - 32;
|
432
|
+
}
|
433
|
+
|
434
|
+
jsonenc_putbytes(e, &ch, 1);
|
435
|
+
ptr++;
|
436
|
+
}
|
437
|
+
}
|
438
|
+
|
439
|
+
static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg,
|
440
|
+
const upb_MessageDef* m) {
|
441
|
+
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
442
|
+
const upb_Array* paths = upb_Message_Get(msg, paths_f).array_val;
|
443
|
+
bool first = true;
|
444
|
+
size_t i, n = 0;
|
445
|
+
|
446
|
+
if (paths) n = upb_Array_Size(paths);
|
447
|
+
|
448
|
+
jsonenc_putstr(e, "\"");
|
449
|
+
|
450
|
+
for (i = 0; i < n; i++) {
|
451
|
+
jsonenc_putsep(e, ",", &first);
|
452
|
+
jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val);
|
453
|
+
}
|
454
|
+
|
455
|
+
jsonenc_putstr(e, "\"");
|
456
|
+
}
|
457
|
+
|
458
|
+
static void jsonenc_struct(jsonenc* e, const upb_Message* msg,
|
459
|
+
const upb_MessageDef* m) {
|
460
|
+
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
461
|
+
const upb_Map* fields = upb_Message_Get(msg, fields_f).map_val;
|
462
|
+
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f);
|
463
|
+
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
|
464
|
+
size_t iter = kUpb_Map_Begin;
|
465
|
+
bool first = true;
|
466
|
+
|
467
|
+
jsonenc_putstr(e, "{");
|
468
|
+
|
469
|
+
if (fields) {
|
470
|
+
while (upb_MapIterator_Next(fields, &iter)) {
|
471
|
+
upb_MessageValue key = upb_MapIterator_Key(fields, iter);
|
472
|
+
upb_MessageValue val = upb_MapIterator_Value(fields, iter);
|
473
|
+
|
474
|
+
jsonenc_putsep(e, ",", &first);
|
475
|
+
jsonenc_string(e, key.str_val);
|
476
|
+
jsonenc_putstr(e, ":");
|
477
|
+
jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f));
|
478
|
+
}
|
479
|
+
}
|
480
|
+
|
481
|
+
jsonenc_putstr(e, "}");
|
482
|
+
}
|
483
|
+
|
484
|
+
static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg,
|
485
|
+
const upb_MessageDef* m) {
|
486
|
+
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
487
|
+
const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f);
|
488
|
+
const upb_Array* values = upb_Message_Get(msg, values_f).array_val;
|
489
|
+
size_t i;
|
490
|
+
bool first = true;
|
491
|
+
|
492
|
+
jsonenc_putstr(e, "[");
|
493
|
+
|
494
|
+
if (values) {
|
495
|
+
const size_t size = upb_Array_Size(values);
|
496
|
+
for (i = 0; i < size; i++) {
|
497
|
+
upb_MessageValue elem = upb_Array_Get(values, i);
|
498
|
+
|
499
|
+
jsonenc_putsep(e, ",", &first);
|
500
|
+
jsonenc_value(e, elem.msg_val, values_m);
|
501
|
+
}
|
502
|
+
}
|
503
|
+
|
504
|
+
jsonenc_putstr(e, "]");
|
505
|
+
}
|
506
|
+
|
507
|
+
static void jsonenc_value(jsonenc* e, const upb_Message* msg,
|
508
|
+
const upb_MessageDef* m) {
|
509
|
+
/* TODO(haberman): do we want a reflection method to get oneof case? */
|
510
|
+
size_t iter = kUpb_Message_Begin;
|
511
|
+
const upb_FieldDef* f;
|
512
|
+
upb_MessageValue val;
|
513
|
+
|
514
|
+
if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) {
|
515
|
+
jsonenc_err(e, "No value set in Value proto");
|
516
|
+
}
|
517
|
+
|
518
|
+
switch (upb_FieldDef_Number(f)) {
|
519
|
+
case 1:
|
520
|
+
jsonenc_putstr(e, "null");
|
521
|
+
break;
|
522
|
+
case 2:
|
523
|
+
upb_JsonEncode_Double(e, val.double_val);
|
524
|
+
break;
|
525
|
+
case 3:
|
526
|
+
jsonenc_string(e, val.str_val);
|
527
|
+
break;
|
528
|
+
case 4:
|
529
|
+
jsonenc_putstr(e, val.bool_val ? "true" : "false");
|
530
|
+
break;
|
531
|
+
case 5:
|
532
|
+
jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f));
|
533
|
+
break;
|
534
|
+
case 6:
|
535
|
+
jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f));
|
536
|
+
break;
|
537
|
+
}
|
538
|
+
}
|
539
|
+
|
540
|
+
static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg,
|
541
|
+
const upb_MessageDef* m) {
|
542
|
+
switch (upb_MessageDef_WellKnownType(m)) {
|
543
|
+
case kUpb_WellKnown_Unspecified:
|
544
|
+
jsonenc_msg(e, msg, m);
|
545
|
+
break;
|
546
|
+
case kUpb_WellKnown_Any:
|
547
|
+
jsonenc_any(e, msg, m);
|
548
|
+
break;
|
549
|
+
case kUpb_WellKnown_FieldMask:
|
550
|
+
jsonenc_fieldmask(e, msg, m);
|
551
|
+
break;
|
552
|
+
case kUpb_WellKnown_Duration:
|
553
|
+
jsonenc_duration(e, msg, m);
|
554
|
+
break;
|
555
|
+
case kUpb_WellKnown_Timestamp:
|
556
|
+
jsonenc_timestamp(e, msg, m);
|
557
|
+
break;
|
558
|
+
case kUpb_WellKnown_DoubleValue:
|
559
|
+
case kUpb_WellKnown_FloatValue:
|
560
|
+
case kUpb_WellKnown_Int64Value:
|
561
|
+
case kUpb_WellKnown_UInt64Value:
|
562
|
+
case kUpb_WellKnown_Int32Value:
|
563
|
+
case kUpb_WellKnown_UInt32Value:
|
564
|
+
case kUpb_WellKnown_StringValue:
|
565
|
+
case kUpb_WellKnown_BytesValue:
|
566
|
+
case kUpb_WellKnown_BoolValue:
|
567
|
+
jsonenc_wrapper(e, msg, m);
|
568
|
+
break;
|
569
|
+
case kUpb_WellKnown_Value:
|
570
|
+
jsonenc_value(e, msg, m);
|
571
|
+
break;
|
572
|
+
case kUpb_WellKnown_ListValue:
|
573
|
+
jsonenc_listvalue(e, msg, m);
|
574
|
+
break;
|
575
|
+
case kUpb_WellKnown_Struct:
|
576
|
+
jsonenc_struct(e, msg, m);
|
577
|
+
break;
|
578
|
+
}
|
579
|
+
}
|
580
|
+
|
581
|
+
static void jsonenc_scalar(jsonenc* e, upb_MessageValue val,
|
582
|
+
const upb_FieldDef* f) {
|
583
|
+
switch (upb_FieldDef_CType(f)) {
|
584
|
+
case kUpb_CType_Bool:
|
585
|
+
jsonenc_putstr(e, val.bool_val ? "true" : "false");
|
586
|
+
break;
|
587
|
+
case kUpb_CType_Float:
|
588
|
+
upb_JsonEncode_Float(e, val.float_val);
|
589
|
+
break;
|
590
|
+
case kUpb_CType_Double:
|
591
|
+
upb_JsonEncode_Double(e, val.double_val);
|
592
|
+
break;
|
593
|
+
case kUpb_CType_Int32:
|
594
|
+
jsonenc_printf(e, "%" PRId32, val.int32_val);
|
595
|
+
break;
|
596
|
+
case kUpb_CType_UInt32:
|
597
|
+
jsonenc_printf(e, "%" PRIu32, val.uint32_val);
|
598
|
+
break;
|
599
|
+
case kUpb_CType_Int64:
|
600
|
+
jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val);
|
601
|
+
break;
|
602
|
+
case kUpb_CType_UInt64:
|
603
|
+
jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val);
|
604
|
+
break;
|
605
|
+
case kUpb_CType_String:
|
606
|
+
jsonenc_string(e, val.str_val);
|
607
|
+
break;
|
608
|
+
case kUpb_CType_Bytes:
|
609
|
+
jsonenc_bytes(e, val.str_val);
|
610
|
+
break;
|
611
|
+
case kUpb_CType_Enum:
|
612
|
+
jsonenc_enum(val.int32_val, f, e);
|
613
|
+
break;
|
614
|
+
case kUpb_CType_Message:
|
615
|
+
jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f));
|
616
|
+
break;
|
617
|
+
}
|
618
|
+
}
|
619
|
+
|
620
|
+
static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val,
|
621
|
+
const upb_FieldDef* f) {
|
622
|
+
jsonenc_putstr(e, "\"");
|
623
|
+
|
624
|
+
switch (upb_FieldDef_CType(f)) {
|
625
|
+
case kUpb_CType_Bool:
|
626
|
+
jsonenc_putstr(e, val.bool_val ? "true" : "false");
|
627
|
+
break;
|
628
|
+
case kUpb_CType_Int32:
|
629
|
+
jsonenc_printf(e, "%" PRId32, val.int32_val);
|
630
|
+
break;
|
631
|
+
case kUpb_CType_UInt32:
|
632
|
+
jsonenc_printf(e, "%" PRIu32, val.uint32_val);
|
633
|
+
break;
|
634
|
+
case kUpb_CType_Int64:
|
635
|
+
jsonenc_printf(e, "%" PRId64, val.int64_val);
|
636
|
+
break;
|
637
|
+
case kUpb_CType_UInt64:
|
638
|
+
jsonenc_printf(e, "%" PRIu64, val.uint64_val);
|
639
|
+
break;
|
640
|
+
case kUpb_CType_String:
|
641
|
+
jsonenc_stringbody(e, val.str_val);
|
642
|
+
break;
|
643
|
+
default:
|
644
|
+
UPB_UNREACHABLE();
|
645
|
+
}
|
646
|
+
|
647
|
+
jsonenc_putstr(e, "\":");
|
648
|
+
}
|
649
|
+
|
650
|
+
static void jsonenc_array(jsonenc* e, const upb_Array* arr,
|
651
|
+
const upb_FieldDef* f) {
|
652
|
+
size_t i;
|
653
|
+
size_t size = arr ? upb_Array_Size(arr) : 0;
|
654
|
+
bool first = true;
|
655
|
+
|
656
|
+
jsonenc_putstr(e, "[");
|
657
|
+
|
658
|
+
for (i = 0; i < size; i++) {
|
659
|
+
jsonenc_putsep(e, ",", &first);
|
660
|
+
jsonenc_scalar(e, upb_Array_Get(arr, i), f);
|
661
|
+
}
|
662
|
+
|
663
|
+
jsonenc_putstr(e, "]");
|
664
|
+
}
|
665
|
+
|
666
|
+
static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) {
|
667
|
+
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
|
668
|
+
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1);
|
669
|
+
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2);
|
670
|
+
size_t iter = kUpb_Map_Begin;
|
671
|
+
bool first = true;
|
672
|
+
|
673
|
+
jsonenc_putstr(e, "{");
|
674
|
+
|
675
|
+
if (map) {
|
676
|
+
while (upb_MapIterator_Next(map, &iter)) {
|
677
|
+
jsonenc_putsep(e, ",", &first);
|
678
|
+
jsonenc_mapkey(e, upb_MapIterator_Key(map, iter), key_f);
|
679
|
+
jsonenc_scalar(e, upb_MapIterator_Value(map, iter), val_f);
|
680
|
+
}
|
681
|
+
}
|
682
|
+
|
683
|
+
jsonenc_putstr(e, "}");
|
684
|
+
}
|
685
|
+
|
686
|
+
static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f,
|
687
|
+
upb_MessageValue val, bool* first) {
|
688
|
+
const char* name;
|
689
|
+
|
690
|
+
jsonenc_putsep(e, ",", first);
|
691
|
+
|
692
|
+
if (upb_FieldDef_IsExtension(f)) {
|
693
|
+
// TODO: For MessageSet, I would have expected this to print the message
|
694
|
+
// name here, but Python doesn't appear to do this. We should do more
|
695
|
+
// research here about what various implementations do.
|
696
|
+
jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f));
|
697
|
+
} else {
|
698
|
+
if (e->options & upb_JsonEncode_UseProtoNames) {
|
699
|
+
name = upb_FieldDef_Name(f);
|
700
|
+
} else {
|
701
|
+
name = upb_FieldDef_JsonName(f);
|
702
|
+
}
|
703
|
+
jsonenc_printf(e, "\"%s\":", name);
|
704
|
+
}
|
705
|
+
|
706
|
+
if (upb_FieldDef_IsMap(f)) {
|
707
|
+
jsonenc_map(e, val.map_val, f);
|
708
|
+
} else if (upb_FieldDef_IsRepeated(f)) {
|
709
|
+
jsonenc_array(e, val.array_val, f);
|
710
|
+
} else {
|
711
|
+
jsonenc_scalar(e, val, f);
|
712
|
+
}
|
713
|
+
}
|
714
|
+
|
715
|
+
static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg,
|
716
|
+
const upb_MessageDef* m, bool first) {
|
717
|
+
upb_MessageValue val;
|
718
|
+
const upb_FieldDef* f;
|
719
|
+
|
720
|
+
if (e->options & upb_JsonEncode_EmitDefaults) {
|
721
|
+
/* Iterate over all fields. */
|
722
|
+
int i = 0;
|
723
|
+
int n = upb_MessageDef_FieldCount(m);
|
724
|
+
for (i = 0; i < n; i++) {
|
725
|
+
f = upb_MessageDef_Field(m, i);
|
726
|
+
if (!upb_FieldDef_HasPresence(f) || upb_Message_Has(msg, f)) {
|
727
|
+
jsonenc_fieldval(e, f, upb_Message_Get(msg, f), &first);
|
728
|
+
}
|
729
|
+
}
|
730
|
+
} else {
|
731
|
+
/* Iterate over non-empty fields. */
|
732
|
+
size_t iter = kUpb_Message_Begin;
|
733
|
+
while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) {
|
734
|
+
jsonenc_fieldval(e, f, val, &first);
|
735
|
+
}
|
736
|
+
}
|
737
|
+
}
|
738
|
+
|
739
|
+
static void jsonenc_msg(jsonenc* e, const upb_Message* msg,
|
740
|
+
const upb_MessageDef* m) {
|
741
|
+
jsonenc_putstr(e, "{");
|
742
|
+
jsonenc_msgfields(e, msg, m, true);
|
743
|
+
jsonenc_putstr(e, "}");
|
744
|
+
}
|
745
|
+
|
746
|
+
static size_t jsonenc_nullz(jsonenc* e, size_t size) {
|
747
|
+
size_t ret = e->ptr - e->buf + e->overflow;
|
748
|
+
|
749
|
+
if (size > 0) {
|
750
|
+
if (e->ptr == e->end) e->ptr--;
|
751
|
+
*e->ptr = '\0';
|
752
|
+
}
|
753
|
+
|
754
|
+
return ret;
|
755
|
+
}
|
756
|
+
|
757
|
+
size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m,
|
758
|
+
const upb_DefPool* ext_pool, int options, char* buf,
|
759
|
+
size_t size, upb_Status* status) {
|
760
|
+
jsonenc e;
|
761
|
+
|
762
|
+
e.buf = buf;
|
763
|
+
e.ptr = buf;
|
764
|
+
e.end = UPB_PTRADD(buf, size);
|
765
|
+
e.overflow = 0;
|
766
|
+
e.options = options;
|
767
|
+
e.ext_pool = ext_pool;
|
768
|
+
e.status = status;
|
769
|
+
e.arena = NULL;
|
770
|
+
|
771
|
+
if (setjmp(e.err)) return -1;
|
772
|
+
|
773
|
+
jsonenc_msgfield(&e, msg, m);
|
774
|
+
if (e.arena) upb_Arena_Free(e.arena);
|
775
|
+
return jsonenc_nullz(&e, size);
|
776
|
+
}
|