grpc 1.23.1 → 1.24.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.
- checksums.yaml +4 -4
- data/Makefile +757 -477
- data/include/grpc/grpc.h +3 -1
- data/include/grpc/grpc_security.h +20 -4
- data/include/grpc/impl/codegen/grpc_types.h +6 -5
- data/include/grpc/impl/codegen/port_platform.h +25 -0
- data/src/core/ext/filters/client_channel/backend_metric.cc +78 -0
- data/src/core/ext/filters/client_channel/backend_metric.h +36 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +16 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +325 -267
- data/src/core/ext/filters/client_channel/client_channel_factory.h +0 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +23 -32
- data/src/core/ext/filters/client_channel/http_proxy.cc +7 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +58 -34
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -50
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +35 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +130 -215
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +34 -21
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1120 -802
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +8 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +33 -12
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +151 -40
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +184 -26
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +389 -245
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +98 -60
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -1
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +89 -0
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +3 -8
- data/src/core/ext/filters/client_channel/server_address.cc +1 -3
- data/src/core/ext/filters/client_channel/server_address.h +1 -1
- data/src/core/ext/filters/client_channel/subchannel.h +2 -1
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +207 -29
- data/src/core/ext/filters/http/client/http_client_filter.cc +10 -8
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +10 -7
- data/src/core/ext/filters/http/server/http_server_filter.cc +52 -26
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +23 -20
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +24 -21
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +237 -191
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +29 -27
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +19 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +13 -4
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +99 -71
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +222 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +818 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +314 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1142 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +53 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +158 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +69 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +49 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +240 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +110 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +235 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +661 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +84 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +274 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +175 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +572 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +150 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +596 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +80 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +95 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +308 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +128 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +392 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +91 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +236 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +88 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +258 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +111 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +23 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +50 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +52 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +130 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.h +87 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.h +85 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +17 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.c +18 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/http.upb.c +66 -0
- data/src/core/ext/upb-generated/google/api/http.upb.h +190 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +485 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1690 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +22 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +50 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +79 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +215 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +106 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +238 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.c +33 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +74 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +49 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +126 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +209 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +681 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +42 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +109 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +36 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +84 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +133 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +359 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +58 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +144 -0
- data/src/core/ext/upb-generated/validate/validate.upb.c +443 -0
- data/src/core/ext/upb-generated/validate/validate.upb.h +2037 -0
- data/src/core/lib/channel/channel_args.cc +21 -0
- data/src/core/lib/channel/channel_args.h +16 -2
- data/src/core/lib/channel/channel_stack.h +2 -1
- data/src/core/lib/channel/channelz.cc +54 -56
- data/src/core/lib/channel/channelz.h +29 -12
- data/src/core/lib/compression/compression.cc +2 -1
- data/src/core/lib/compression/compression_internal.h +8 -0
- data/src/core/lib/gpr/log_linux.cc +2 -2
- data/src/core/lib/gpr/log_posix.cc +2 -2
- data/src/core/lib/gpr/time_precise.cc +123 -36
- data/src/core/lib/gpr/time_precise.h +37 -0
- data/src/core/lib/gprpp/abstract.h +10 -0
- data/src/core/lib/gprpp/atomic.h +4 -0
- data/src/core/lib/gprpp/inlined_vector.h +20 -4
- data/src/core/lib/gprpp/map.h +109 -6
- data/src/core/lib/gprpp/memory.h +6 -0
- data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +29 -54
- data/src/core/lib/iomgr/exec_ctx.cc +27 -17
- data/src/core/lib/iomgr/exec_ctx.h +3 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -3
- data/src/core/lib/iomgr/tcp_posix.cc +16 -25
- data/src/core/lib/iomgr/tcp_server_custom.cc +1 -1
- data/src/core/lib/iomgr/timer_manager.cc +8 -1
- data/src/core/lib/iomgr/timer_manager.h +2 -0
- data/src/core/lib/security/credentials/credentials.h +8 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -0
- data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +3 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +1 -12
- data/src/core/lib/security/security_connector/ssl_utils.h +10 -6
- data/src/core/lib/security/security_connector/ssl_utils_config.cc +32 -0
- data/src/core/lib/security/security_connector/ssl_utils_config.h +30 -0
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +161 -49
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +34 -1
- data/src/core/lib/slice/slice_intern.cc +17 -9
- data/src/core/lib/slice/slice_internal.h +34 -7
- data/src/core/lib/slice/slice_utils.h +7 -3
- data/src/core/lib/surface/call.cc +97 -57
- data/src/core/lib/surface/channel.cc +2 -2
- data/src/core/lib/surface/completion_queue.cc +10 -16
- data/src/core/lib/surface/init.cc +3 -0
- data/src/core/lib/surface/server.cc +11 -14
- data/src/core/lib/surface/validate_metadata.cc +4 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +4 -4
- data/src/core/lib/transport/metadata_batch.cc +72 -16
- data/src/core/lib/transport/metadata_batch.h +38 -0
- data/src/core/lib/transport/static_metadata.cc +814 -1023
- data/src/core/lib/transport/static_metadata.h +271 -213
- data/src/core/lib/transport/transport.h +12 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +104 -76
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -16
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +10 -6
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +4 -3
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +74 -48
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +34 -26
- data/src/core/tsi/ssl_transport_security.cc +14 -6
- data/src/core/tsi/ssl_transport_security.h +4 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +5 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +1 -42
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
- data/src/ruby/lib/grpc.rb +2 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/errors.rb +4 -7
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +9 -4
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +1 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +34 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -29
- data/third_party/upb/upb/decode.c +604 -0
- data/third_party/upb/upb/decode.h +21 -0
- data/third_party/upb/upb/encode.c +378 -0
- data/third_party/upb/upb/encode.h +21 -0
- data/third_party/upb/upb/generated_util.h +105 -0
- data/third_party/upb/upb/msg.c +111 -0
- data/third_party/upb/upb/msg.h +69 -0
- data/third_party/upb/upb/port.c +27 -0
- data/third_party/upb/upb/port_def.inc +152 -0
- data/third_party/upb/upb/port_undef.inc +21 -0
- data/third_party/upb/upb/table.c +911 -0
- data/third_party/upb/upb/table.int.h +507 -0
- data/third_party/upb/upb/upb.c +261 -0
- data/third_party/upb/upb/upb.h +364 -0
- metadata +134 -55
- data/src/core/ext/filters/client_channel/health/health.pb.c +0 -23
- data/src/core/ext/filters/client_channel/health/health.pb.h +0 -73
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +0 -89
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -164
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +0 -520
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +0 -323
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +0 -145
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +0 -149
- data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -47
- data/src/core/tsi/alts/handshaker/altscontext.pb.h +0 -63
- data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -122
- data/src/core/tsi/alts/handshaker/handshaker.pb.h +0 -254
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -49
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +0 -78
- data/third_party/nanopb/pb.h +0 -579
- data/third_party/nanopb/pb_common.c +0 -97
- data/third_party/nanopb/pb_common.h +0 -42
- data/third_party/nanopb/pb_decode.c +0 -1347
- data/third_party/nanopb/pb_decode.h +0 -149
- data/third_party/nanopb/pb_encode.c +0 -696
- data/third_party/nanopb/pb_encode.h +0 -154
data/src/ruby/lib/grpc.rb
CHANGED
@@ -15,10 +15,12 @@
|
|
15
15
|
ssl_roots_path = File.expand_path('../../../../etc/roots.pem', __FILE__)
|
16
16
|
|
17
17
|
require_relative 'grpc/errors'
|
18
|
+
require_relative 'grpc/structs'
|
18
19
|
require_relative 'grpc/grpc'
|
19
20
|
require_relative 'grpc/logconfig'
|
20
21
|
require_relative 'grpc/notifier'
|
21
22
|
require_relative 'grpc/version'
|
23
|
+
require_relative 'grpc/core/status_codes'
|
22
24
|
require_relative 'grpc/core/time_consts'
|
23
25
|
require_relative 'grpc/generic/active_call'
|
24
26
|
require_relative 'grpc/generic/client_stub'
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# GRPC contains the General RPC module.
|
16
|
+
module GRPC
|
17
|
+
module Core
|
18
|
+
# StatusCodes defines the canonical error codes used by gRPC for the RPC
|
19
|
+
# API.
|
20
|
+
module StatusCodes
|
21
|
+
# OK is returned on success.
|
22
|
+
OK = 0
|
23
|
+
|
24
|
+
# Canceled indicates the operation was canceled (typically by the caller).
|
25
|
+
CANCELLED = 1
|
26
|
+
|
27
|
+
# Unknown error. An example of where this error may be returned is if a
|
28
|
+
# Status value received from another address space belongs to an
|
29
|
+
# error-space that is not known in this address space. Also errors raised
|
30
|
+
# by APIs that do not return enough error information may be converted to
|
31
|
+
# this error.
|
32
|
+
UNKNOWN = 2
|
33
|
+
|
34
|
+
# InvalidArgument indicates client specified an invalid argument. Note
|
35
|
+
# that this differs from FailedPrecondition. It indicates arguments that
|
36
|
+
# are problematic regardless of the state of the system (e.g., a malformed
|
37
|
+
# file name).
|
38
|
+
INVALID_ARGUMENT = 3
|
39
|
+
|
40
|
+
# DeadlineExceeded means operation expired before completion. For
|
41
|
+
# operations that change the state of the system, this error may be
|
42
|
+
# returned even if the operation has completed successfully. For example,
|
43
|
+
# a successful response from a server could have been delayed long enough
|
44
|
+
# for the deadline to expire.
|
45
|
+
DEADLINE_EXCEEDED = 4
|
46
|
+
|
47
|
+
# NotFound means some requested entity (e.g., file or directory) was not
|
48
|
+
# found.
|
49
|
+
NOT_FOUND = 5
|
50
|
+
|
51
|
+
# AlreadyExists means an attempt to create an entity failed because one
|
52
|
+
# already exists.
|
53
|
+
ALREADY_EXISTS = 6
|
54
|
+
|
55
|
+
# PermissionDenied indicates the caller does not have permission to
|
56
|
+
# execute the specified operation. It must not be used for rejections
|
57
|
+
# caused by exhausting some resource (use ResourceExhausted instead for
|
58
|
+
# those errors). It must not be used if the caller cannot be identified
|
59
|
+
# (use Unauthenticated instead for those errors).
|
60
|
+
PERMISSION_DENIED = 7
|
61
|
+
|
62
|
+
# ResourceExhausted indicates some resource has been exhausted, perhaps a
|
63
|
+
# per-user quota, or perhaps the entire file system is out of space.
|
64
|
+
RESOURCE_EXHAUSTED = 8
|
65
|
+
|
66
|
+
# FailedPrecondition indicates operation was rejected because the system
|
67
|
+
# is not in a state required for the operation's execution. For example,
|
68
|
+
# directory to be deleted may be non-empty, an rmdir operation is applied
|
69
|
+
# to a non-directory, etc.
|
70
|
+
#
|
71
|
+
# A litmus test that may help a service implementor in deciding between
|
72
|
+
# FailedPrecondition, Aborted, and Unavailable:
|
73
|
+
# (a) Use Unavailable if the client can retry just the failing call.
|
74
|
+
# (b) Use Aborted if the client should retry at a higher-level (e.g.,
|
75
|
+
# restarting a read-modify-write sequence).
|
76
|
+
# (c) Use FailedPrecondition if the client should not retry until the
|
77
|
+
# system state has been explicitly fixed. E.g., if an "rmdir" fails
|
78
|
+
# because the directory is non-empty, FailedPrecondition should be
|
79
|
+
# returned since the client should not retry unless they have first
|
80
|
+
# fixed up the directory by deleting files from it.
|
81
|
+
# (d) Use FailedPrecondition if the client performs conditional REST
|
82
|
+
# Get/Update/Delete on a resource and the resource on the server does
|
83
|
+
# not match the condition. E.g., conflicting read-modify-write on the
|
84
|
+
# same resource.
|
85
|
+
FAILED_PRECONDITION = 9
|
86
|
+
|
87
|
+
# Aborted indicates the operation was aborted, typically due to a
|
88
|
+
# concurrency issue like sequencer check failures, transaction aborts,
|
89
|
+
# etc.
|
90
|
+
#
|
91
|
+
# See litmus test above for deciding between FailedPrecondition, Aborted,
|
92
|
+
# and Unavailable.
|
93
|
+
ABORTED = 10
|
94
|
+
|
95
|
+
# OutOfRange means operation was attempted past the valid range. E.g.,
|
96
|
+
# seeking or reading past end of file.
|
97
|
+
#
|
98
|
+
# Unlike InvalidArgument, this error indicates a problem that may be fixed
|
99
|
+
# if the system state changes. For example, a 32-bit file system will
|
100
|
+
# generate InvalidArgument if asked to read at an offset that is not in
|
101
|
+
# the range [0,2^32-1], but it will generate OutOfRange if asked to read
|
102
|
+
# from an offset past the current file size.
|
103
|
+
#
|
104
|
+
# There is a fair bit of overlap between FailedPrecondition and
|
105
|
+
# OutOfRange. We recommend using OutOfRange (the more specific error) when
|
106
|
+
# it applies so that callers who are iterating through a space can easily
|
107
|
+
# look for an OutOfRange error to detect when they are done.
|
108
|
+
OUT_OF_RANGE = 11
|
109
|
+
|
110
|
+
# Unimplemented indicates operation is not implemented or not
|
111
|
+
# supported/enabled in this service.
|
112
|
+
UNIMPLEMENTED = 12
|
113
|
+
|
114
|
+
# Internal errors. Means some invariants expected by underlying system has
|
115
|
+
# been broken. If you see one of these errors, something is very broken.
|
116
|
+
INTERNAL = 13
|
117
|
+
|
118
|
+
# Unavailable indicates the service is currently unavailable. This is a
|
119
|
+
# most likely a transient condition and may be corrected by retrying with
|
120
|
+
# a backoff. Note that it is not always safe to retry non-idempotent
|
121
|
+
# operations.
|
122
|
+
#
|
123
|
+
# See litmus test above for deciding between FailedPrecondition, Aborted,
|
124
|
+
# and Unavailable.
|
125
|
+
UNAVAILABLE = 14
|
126
|
+
|
127
|
+
# DataLoss indicates unrecoverable data loss or corruption.
|
128
|
+
DATA_LOSS = 15
|
129
|
+
|
130
|
+
# Unauthenticated indicates the request does not have valid authentication
|
131
|
+
# credentials for the operation.
|
132
|
+
UNAUTHENTICATED = 16
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/src/ruby/lib/grpc/errors.rb
CHANGED
@@ -12,7 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require_relative './
|
15
|
+
require_relative './structs'
|
16
|
+
require_relative './core/status_codes'
|
17
|
+
require_relative './google_rpc_status_utils'
|
16
18
|
|
17
19
|
# GRPC contains the General RPC module.
|
18
20
|
module GRPC
|
@@ -57,12 +59,7 @@ module GRPC
|
|
57
59
|
#
|
58
60
|
# @return [Google::Rpc::Status, nil]
|
59
61
|
def to_rpc_status
|
60
|
-
|
61
|
-
# loading protobuf_c.so to the users of this method.
|
62
|
-
require_relative './google_rpc_status_utils'
|
63
|
-
status = to_status
|
64
|
-
return if status.nil?
|
65
|
-
GoogleRpcStatusUtils.extract_google_rpc_status(status)
|
62
|
+
GoogleRpcStatusUtils.extract_google_rpc_status(to_status)
|
66
63
|
rescue Google::Protobuf::ParseError => parse_error
|
67
64
|
GRPC.logger.warn('parse error: to_rpc_status failed')
|
68
65
|
GRPC.logger.warn(parse_error)
|
@@ -12,8 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require_relative './
|
16
|
-
require 'google/rpc/status_pb'
|
15
|
+
require_relative './structs'
|
17
16
|
|
18
17
|
# GRPC contains the General RPC module.
|
19
18
|
module GRPC
|
@@ -28,8 +27,14 @@ module GRPC
|
|
28
27
|
def self.extract_google_rpc_status(status)
|
29
28
|
fail ArgumentError, 'bad type' unless status.is_a? Struct::Status
|
30
29
|
grpc_status_details_bin_trailer = 'grpc-status-details-bin'
|
31
|
-
|
32
|
-
|
30
|
+
binstatus = status.metadata[grpc_status_details_bin_trailer]
|
31
|
+
return nil if binstatus.nil?
|
32
|
+
|
33
|
+
# Lazily load grpc_c and protobuf_c.so for users of this method.
|
34
|
+
require_relative './grpc'
|
35
|
+
require 'google/rpc/status_pb'
|
36
|
+
|
37
|
+
Google::Rpc::Status.decode(binstatus)
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
Struct.new('Status', :code, :details, :metadata)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Copyright 2019 gRPC authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.testing;
|
18
|
+
|
19
|
+
// For sanity checking package definitions
|
20
|
+
option ruby_package = "A::Other";
|
21
|
+
|
22
|
+
message Thing { }
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// Copyright 2019 gRPC authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
package grpc.testing;
|
18
|
+
|
19
|
+
import "grpc/testing/package_options_import.proto";
|
20
|
+
|
21
|
+
// For sanity checking package definitions
|
22
|
+
option ruby_package = "RPC::Test::New::Package::Options";
|
23
|
+
|
24
|
+
message AnotherTestRequest { }
|
25
|
+
|
26
|
+
message AnotherTestResponse { }
|
27
|
+
|
28
|
+
message Foo { }
|
29
|
+
|
30
|
+
service AnotherTestService {
|
31
|
+
rpc GetTest(AnotherTestRequest) returns (AnotherTestResponse) { }
|
32
|
+
rpc OtherTest(Thing) returns (Thing) { }
|
33
|
+
rpc FooTest(Foo) returns (Foo) { }
|
34
|
+
}
|
@@ -18,35 +18,59 @@ require 'tmpdir'
|
|
18
18
|
|
19
19
|
describe 'Code Generation Options' do
|
20
20
|
it 'should generate and respect package options' do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
expect(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
21
|
+
with_protos(%w[grpc/testing/package_options.proto]) do
|
22
|
+
expect { Grpc::Testing::Package::Options::TestService::Service }.to raise_error(NameError)
|
23
|
+
expect(require('grpc/testing/package_options_services_pb')).to be_truthy
|
24
|
+
expect { Grpc::Testing::Package::Options::TestService::Service }.to_not raise_error
|
25
|
+
expect { Grpc::Testing::TestService::Service }.to raise_error(NameError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should generate and respect Ruby style package options' do
|
30
|
+
with_protos(%w[grpc/testing/package_options_ruby_style.proto grpc/testing/package_options_import.proto]) do
|
31
|
+
expect { RPC::Test::New::Package::Options::AnotherTestService::Service }.to raise_error(NameError)
|
32
|
+
expect(require('grpc/testing/package_options_ruby_style_services_pb')).to be_truthy
|
33
|
+
expect { RPC::Test::New::Package::Options::AnotherTestService::Service }.to_not raise_error
|
34
|
+
expect { Grpc::Testing::AnotherTestService::Service }.to raise_error(NameError)
|
35
|
+
|
36
|
+
services = RPC::Test::New::Package::Options::AnotherTestService::Service.rpc_descs
|
37
|
+
expect(services[:GetTest].input).to eq(RPC::Test::New::Package::Options::AnotherTestRequest)
|
38
|
+
expect(services[:GetTest].output).to eq(RPC::Test::New::Package::Options::AnotherTestResponse)
|
39
|
+
expect(services[:OtherTest].input).to eq(A::Other::Thing)
|
40
|
+
expect(services[:OtherTest].output).to eq(A::Other::Thing)
|
41
|
+
expect(services[:FooTest].input).to eq(RPC::Test::New::Package::Options::Foo)
|
42
|
+
expect(services[:FooTest].output).to eq(RPC::Test::New::Package::Options::Foo)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def with_protos(file_paths)
|
48
|
+
fail 'CONFIG env variable unexpectedly unset' unless ENV['CONFIG']
|
49
|
+
bins_sub_dir = ENV['CONFIG']
|
50
|
+
|
51
|
+
pb_dir = File.dirname(__FILE__)
|
52
|
+
bins_dir = File.join('..', '..', '..', '..', '..', 'bins', bins_sub_dir)
|
53
|
+
|
54
|
+
plugin = File.join(bins_dir, 'grpc_ruby_plugin')
|
55
|
+
protoc = File.join(bins_dir, 'protobuf', 'protoc')
|
56
|
+
|
57
|
+
# Generate the service from the proto
|
58
|
+
Dir.mktmpdir(nil, File.dirname(__FILE__)) do |tmp_dir|
|
59
|
+
gen_file = system(protoc,
|
60
|
+
'-I.',
|
61
|
+
*file_paths,
|
62
|
+
"--grpc_out=#{tmp_dir}", # generate the service
|
63
|
+
"--ruby_out=#{tmp_dir}", # generate the definitions
|
64
|
+
"--plugin=protoc-gen-grpc=#{plugin}",
|
65
|
+
chdir: pb_dir,
|
66
|
+
out: File::NULL)
|
67
|
+
|
68
|
+
expect(gen_file).to be_truthy
|
69
|
+
begin
|
70
|
+
$LOAD_PATH.push(tmp_dir)
|
71
|
+
yield
|
72
|
+
ensure
|
73
|
+
$LOAD_PATH.delete(tmp_dir)
|
50
74
|
end
|
51
75
|
end
|
52
76
|
end
|
@@ -0,0 +1,604 @@
|
|
1
|
+
|
2
|
+
#include <string.h>
|
3
|
+
#include "upb/upb.h"
|
4
|
+
#include "upb/decode.h"
|
5
|
+
|
6
|
+
#include "upb/port_def.inc"
|
7
|
+
|
8
|
+
/* Maps descriptor type -> upb field type. */
|
9
|
+
const uint8_t upb_desctype_to_fieldtype[] = {
|
10
|
+
UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
|
11
|
+
UPB_TYPE_DOUBLE, /* DOUBLE */
|
12
|
+
UPB_TYPE_FLOAT, /* FLOAT */
|
13
|
+
UPB_TYPE_INT64, /* INT64 */
|
14
|
+
UPB_TYPE_UINT64, /* UINT64 */
|
15
|
+
UPB_TYPE_INT32, /* INT32 */
|
16
|
+
UPB_TYPE_UINT64, /* FIXED64 */
|
17
|
+
UPB_TYPE_UINT32, /* FIXED32 */
|
18
|
+
UPB_TYPE_BOOL, /* BOOL */
|
19
|
+
UPB_TYPE_STRING, /* STRING */
|
20
|
+
UPB_TYPE_MESSAGE, /* GROUP */
|
21
|
+
UPB_TYPE_MESSAGE, /* MESSAGE */
|
22
|
+
UPB_TYPE_BYTES, /* BYTES */
|
23
|
+
UPB_TYPE_UINT32, /* UINT32 */
|
24
|
+
UPB_TYPE_ENUM, /* ENUM */
|
25
|
+
UPB_TYPE_INT32, /* SFIXED32 */
|
26
|
+
UPB_TYPE_INT64, /* SFIXED64 */
|
27
|
+
UPB_TYPE_INT32, /* SINT32 */
|
28
|
+
UPB_TYPE_INT64, /* SINT64 */
|
29
|
+
};
|
30
|
+
|
31
|
+
/* Data pertaining to the parse. */
|
32
|
+
typedef struct {
|
33
|
+
const char *ptr; /* Current parsing position. */
|
34
|
+
const char *field_start; /* Start of this field. */
|
35
|
+
const char *limit; /* End of delimited region or end of buffer. */
|
36
|
+
upb_arena *arena;
|
37
|
+
int depth;
|
38
|
+
uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
|
39
|
+
} upb_decstate;
|
40
|
+
|
41
|
+
/* Data passed by value to each parsing function. */
|
42
|
+
typedef struct {
|
43
|
+
char *msg;
|
44
|
+
const upb_msglayout *layout;
|
45
|
+
upb_decstate *state;
|
46
|
+
} upb_decframe;
|
47
|
+
|
48
|
+
#define CHK(x) if (!(x)) { return 0; }
|
49
|
+
|
50
|
+
static bool upb_skip_unknowngroup(upb_decstate *d, int field_number);
|
51
|
+
static bool upb_decode_message(upb_decstate *d, char *msg,
|
52
|
+
const upb_msglayout *l);
|
53
|
+
|
54
|
+
static bool upb_decode_varint(const char **ptr, const char *limit,
|
55
|
+
uint64_t *val) {
|
56
|
+
uint8_t byte;
|
57
|
+
int bitpos = 0;
|
58
|
+
const char *p = *ptr;
|
59
|
+
*val = 0;
|
60
|
+
|
61
|
+
do {
|
62
|
+
CHK(bitpos < 70 && p < limit);
|
63
|
+
byte = *p;
|
64
|
+
*val |= (uint64_t)(byte & 0x7F) << bitpos;
|
65
|
+
p++;
|
66
|
+
bitpos += 7;
|
67
|
+
} while (byte & 0x80);
|
68
|
+
|
69
|
+
*ptr = p;
|
70
|
+
return true;
|
71
|
+
}
|
72
|
+
|
73
|
+
static bool upb_decode_varint32(const char **ptr, const char *limit,
|
74
|
+
uint32_t *val) {
|
75
|
+
uint64_t u64;
|
76
|
+
CHK(upb_decode_varint(ptr, limit, &u64) && u64 <= UINT32_MAX);
|
77
|
+
*val = (uint32_t)u64;
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
|
81
|
+
static bool upb_decode_64bit(const char **ptr, const char *limit,
|
82
|
+
uint64_t *val) {
|
83
|
+
CHK(limit - *ptr >= 8);
|
84
|
+
memcpy(val, *ptr, 8);
|
85
|
+
*ptr += 8;
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
|
89
|
+
static bool upb_decode_32bit(const char **ptr, const char *limit,
|
90
|
+
uint32_t *val) {
|
91
|
+
CHK(limit - *ptr >= 4);
|
92
|
+
memcpy(val, *ptr, 4);
|
93
|
+
*ptr += 4;
|
94
|
+
return true;
|
95
|
+
}
|
96
|
+
|
97
|
+
static int32_t upb_zzdecode_32(uint32_t n) {
|
98
|
+
return (n >> 1) ^ -(int32_t)(n & 1);
|
99
|
+
}
|
100
|
+
|
101
|
+
static int64_t upb_zzdecode_64(uint64_t n) {
|
102
|
+
return (n >> 1) ^ -(int64_t)(n & 1);
|
103
|
+
}
|
104
|
+
|
105
|
+
static bool upb_decode_string(const char **ptr, const char *limit,
|
106
|
+
int *outlen) {
|
107
|
+
uint32_t len;
|
108
|
+
|
109
|
+
CHK(upb_decode_varint32(ptr, limit, &len) &&
|
110
|
+
len < INT32_MAX &&
|
111
|
+
limit - *ptr >= (int32_t)len);
|
112
|
+
|
113
|
+
*outlen = len;
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
|
117
|
+
static void upb_set32(void *msg, size_t ofs, uint32_t val) {
|
118
|
+
memcpy((char*)msg + ofs, &val, sizeof(val));
|
119
|
+
}
|
120
|
+
|
121
|
+
static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame) {
|
122
|
+
upb_msg_addunknown(frame->msg, d->field_start, d->ptr - d->field_start,
|
123
|
+
d->arena);
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
static bool upb_skip_unknownfielddata(upb_decstate *d, uint32_t tag,
|
129
|
+
uint32_t group_fieldnum) {
|
130
|
+
switch (tag & 7) {
|
131
|
+
case UPB_WIRE_TYPE_VARINT: {
|
132
|
+
uint64_t val;
|
133
|
+
return upb_decode_varint(&d->ptr, d->limit, &val);
|
134
|
+
}
|
135
|
+
case UPB_WIRE_TYPE_32BIT: {
|
136
|
+
uint32_t val;
|
137
|
+
return upb_decode_32bit(&d->ptr, d->limit, &val);
|
138
|
+
}
|
139
|
+
case UPB_WIRE_TYPE_64BIT: {
|
140
|
+
uint64_t val;
|
141
|
+
return upb_decode_64bit(&d->ptr, d->limit, &val);
|
142
|
+
}
|
143
|
+
case UPB_WIRE_TYPE_DELIMITED: {
|
144
|
+
int len;
|
145
|
+
CHK(upb_decode_string(&d->ptr, d->limit, &len));
|
146
|
+
d->ptr += len;
|
147
|
+
return true;
|
148
|
+
}
|
149
|
+
case UPB_WIRE_TYPE_START_GROUP:
|
150
|
+
return upb_skip_unknowngroup(d, tag >> 3);
|
151
|
+
case UPB_WIRE_TYPE_END_GROUP:
|
152
|
+
return (tag >> 3) == group_fieldnum;
|
153
|
+
}
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
|
157
|
+
static bool upb_skip_unknowngroup(upb_decstate *d, int field_number) {
|
158
|
+
while (d->ptr < d->limit && d->end_group == 0) {
|
159
|
+
uint32_t tag = 0;
|
160
|
+
CHK(upb_decode_varint32(&d->ptr, d->limit, &tag));
|
161
|
+
CHK(upb_skip_unknownfielddata(d, tag, field_number));
|
162
|
+
}
|
163
|
+
|
164
|
+
CHK(d->end_group == field_number);
|
165
|
+
d->end_group = 0;
|
166
|
+
return true;
|
167
|
+
}
|
168
|
+
|
169
|
+
static bool upb_array_grow(upb_array *arr, size_t elements, size_t elem_size,
|
170
|
+
upb_arena *arena) {
|
171
|
+
size_t needed = arr->len + elements;
|
172
|
+
size_t new_size = UPB_MAX(arr->size, 8);
|
173
|
+
size_t new_bytes;
|
174
|
+
size_t old_bytes;
|
175
|
+
void *new_data;
|
176
|
+
upb_alloc *alloc = upb_arena_alloc(arena);
|
177
|
+
|
178
|
+
while (new_size < needed) {
|
179
|
+
new_size *= 2;
|
180
|
+
}
|
181
|
+
|
182
|
+
old_bytes = arr->len * elem_size;
|
183
|
+
new_bytes = new_size * elem_size;
|
184
|
+
new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
|
185
|
+
CHK(new_data);
|
186
|
+
|
187
|
+
arr->data = new_data;
|
188
|
+
arr->size = new_size;
|
189
|
+
return true;
|
190
|
+
}
|
191
|
+
|
192
|
+
static void *upb_array_reserve(upb_array *arr, size_t elements,
|
193
|
+
size_t elem_size, upb_arena *arena) {
|
194
|
+
if (arr->size - arr->len < elements) {
|
195
|
+
CHK(upb_array_grow(arr, elements, elem_size, arena));
|
196
|
+
}
|
197
|
+
return (char*)arr->data + (arr->len * elem_size);
|
198
|
+
}
|
199
|
+
|
200
|
+
bool upb_array_add(upb_array *arr, size_t elements, size_t elem_size,
|
201
|
+
const void *data, upb_arena *arena) {
|
202
|
+
void *dest = upb_array_reserve(arr, elements, elem_size, arena);
|
203
|
+
|
204
|
+
CHK(dest);
|
205
|
+
arr->len += elements;
|
206
|
+
memcpy(dest, data, elements * elem_size);
|
207
|
+
|
208
|
+
return true;
|
209
|
+
}
|
210
|
+
|
211
|
+
static upb_array *upb_getarr(upb_decframe *frame,
|
212
|
+
const upb_msglayout_field *field) {
|
213
|
+
UPB_ASSERT(field->label == UPB_LABEL_REPEATED);
|
214
|
+
return *(upb_array**)&frame->msg[field->offset];
|
215
|
+
}
|
216
|
+
|
217
|
+
static upb_array *upb_getorcreatearr(upb_decframe *frame,
|
218
|
+
const upb_msglayout_field *field) {
|
219
|
+
upb_array *arr = upb_getarr(frame, field);
|
220
|
+
|
221
|
+
if (!arr) {
|
222
|
+
arr = upb_array_new(frame->state->arena);
|
223
|
+
CHK(arr);
|
224
|
+
*(upb_array**)&frame->msg[field->offset] = arr;
|
225
|
+
}
|
226
|
+
|
227
|
+
return arr;
|
228
|
+
}
|
229
|
+
|
230
|
+
static upb_msg *upb_getorcreatemsg(upb_decframe *frame,
|
231
|
+
const upb_msglayout_field *field,
|
232
|
+
const upb_msglayout **subm) {
|
233
|
+
upb_msg **submsg = (void*)(frame->msg + field->offset);
|
234
|
+
*subm = frame->layout->submsgs[field->submsg_index];
|
235
|
+
|
236
|
+
UPB_ASSERT(field->label != UPB_LABEL_REPEATED);
|
237
|
+
|
238
|
+
if (!*submsg) {
|
239
|
+
*submsg = upb_msg_new(*subm, frame->state->arena);
|
240
|
+
CHK(*submsg);
|
241
|
+
}
|
242
|
+
|
243
|
+
return *submsg;
|
244
|
+
}
|
245
|
+
|
246
|
+
static upb_msg *upb_addmsg(upb_decframe *frame,
|
247
|
+
const upb_msglayout_field *field,
|
248
|
+
const upb_msglayout **subm) {
|
249
|
+
upb_msg *submsg;
|
250
|
+
upb_array *arr = upb_getorcreatearr(frame, field);
|
251
|
+
|
252
|
+
*subm = frame->layout->submsgs[field->submsg_index];
|
253
|
+
submsg = upb_msg_new(*subm, frame->state->arena);
|
254
|
+
CHK(submsg);
|
255
|
+
upb_array_add(arr, 1, sizeof(submsg), &submsg, frame->state->arena);
|
256
|
+
|
257
|
+
return submsg;
|
258
|
+
}
|
259
|
+
|
260
|
+
static void upb_sethasbit(upb_decframe *frame,
|
261
|
+
const upb_msglayout_field *field) {
|
262
|
+
int32_t hasbit = field->presence;
|
263
|
+
UPB_ASSERT(field->presence > 0);
|
264
|
+
frame->msg[hasbit / 8] |= (1 << (hasbit % 8));
|
265
|
+
}
|
266
|
+
|
267
|
+
static void upb_setoneofcase(upb_decframe *frame,
|
268
|
+
const upb_msglayout_field *field) {
|
269
|
+
UPB_ASSERT(field->presence < 0);
|
270
|
+
upb_set32(frame->msg, ~field->presence, field->number);
|
271
|
+
}
|
272
|
+
|
273
|
+
static bool upb_decode_addval(upb_decframe *frame,
|
274
|
+
const upb_msglayout_field *field, void *val,
|
275
|
+
size_t size) {
|
276
|
+
char *field_mem = frame->msg + field->offset;
|
277
|
+
upb_array *arr;
|
278
|
+
|
279
|
+
if (field->label == UPB_LABEL_REPEATED) {
|
280
|
+
arr = upb_getorcreatearr(frame, field);
|
281
|
+
CHK(arr);
|
282
|
+
field_mem = upb_array_reserve(arr, 1, size, frame->state->arena);
|
283
|
+
CHK(field_mem);
|
284
|
+
}
|
285
|
+
|
286
|
+
memcpy(field_mem, val, size);
|
287
|
+
return true;
|
288
|
+
}
|
289
|
+
|
290
|
+
static void upb_decode_setpresent(upb_decframe *frame,
|
291
|
+
const upb_msglayout_field *field) {
|
292
|
+
if (field->label == UPB_LABEL_REPEATED) {
|
293
|
+
upb_array *arr = upb_getarr(frame, field);
|
294
|
+
UPB_ASSERT(arr->len < arr->size);
|
295
|
+
arr->len++;
|
296
|
+
} else if (field->presence < 0) {
|
297
|
+
upb_setoneofcase(frame, field);
|
298
|
+
} else if (field->presence > 0) {
|
299
|
+
upb_sethasbit(frame, field);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
static bool upb_decode_msgfield(upb_decstate *d, upb_msg *msg,
|
304
|
+
const upb_msglayout *layout, int limit) {
|
305
|
+
const char* saved_limit = d->limit;
|
306
|
+
d->limit = d->ptr + limit;
|
307
|
+
CHK(--d->depth >= 0);
|
308
|
+
upb_decode_message(d, msg, layout);
|
309
|
+
d->depth++;
|
310
|
+
d->limit = saved_limit;
|
311
|
+
CHK(d->end_group == 0);
|
312
|
+
return true;
|
313
|
+
}
|
314
|
+
|
315
|
+
static bool upb_decode_groupfield(upb_decstate *d, upb_msg *msg,
|
316
|
+
const upb_msglayout *layout,
|
317
|
+
int field_number) {
|
318
|
+
CHK(--d->depth >= 0);
|
319
|
+
upb_decode_message(d, msg, layout);
|
320
|
+
d->depth++;
|
321
|
+
CHK(d->end_group == field_number);
|
322
|
+
d->end_group = 0;
|
323
|
+
return true;
|
324
|
+
}
|
325
|
+
|
326
|
+
static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
|
327
|
+
const upb_msglayout_field *field) {
|
328
|
+
uint64_t val;
|
329
|
+
CHK(upb_decode_varint(&d->ptr, d->limit, &val));
|
330
|
+
|
331
|
+
switch (field->descriptortype) {
|
332
|
+
case UPB_DESCRIPTOR_TYPE_INT64:
|
333
|
+
case UPB_DESCRIPTOR_TYPE_UINT64:
|
334
|
+
CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
|
335
|
+
break;
|
336
|
+
case UPB_DESCRIPTOR_TYPE_INT32:
|
337
|
+
case UPB_DESCRIPTOR_TYPE_UINT32:
|
338
|
+
case UPB_DESCRIPTOR_TYPE_ENUM: {
|
339
|
+
uint32_t val32 = (uint32_t)val;
|
340
|
+
CHK(upb_decode_addval(frame, field, &val32, sizeof(val32)));
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
case UPB_DESCRIPTOR_TYPE_BOOL: {
|
344
|
+
bool valbool = val != 0;
|
345
|
+
CHK(upb_decode_addval(frame, field, &valbool, sizeof(valbool)));
|
346
|
+
break;
|
347
|
+
}
|
348
|
+
case UPB_DESCRIPTOR_TYPE_SINT32: {
|
349
|
+
int32_t decoded = upb_zzdecode_32((uint32_t)val);
|
350
|
+
CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded)));
|
351
|
+
break;
|
352
|
+
}
|
353
|
+
case UPB_DESCRIPTOR_TYPE_SINT64: {
|
354
|
+
int64_t decoded = upb_zzdecode_64(val);
|
355
|
+
CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded)));
|
356
|
+
break;
|
357
|
+
}
|
358
|
+
default:
|
359
|
+
return upb_append_unknown(d, frame);
|
360
|
+
}
|
361
|
+
|
362
|
+
upb_decode_setpresent(frame, field);
|
363
|
+
return true;
|
364
|
+
}
|
365
|
+
|
366
|
+
static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame,
|
367
|
+
const upb_msglayout_field *field) {
|
368
|
+
uint64_t val;
|
369
|
+
CHK(upb_decode_64bit(&d->ptr, d->limit, &val));
|
370
|
+
|
371
|
+
switch (field->descriptortype) {
|
372
|
+
case UPB_DESCRIPTOR_TYPE_DOUBLE:
|
373
|
+
case UPB_DESCRIPTOR_TYPE_FIXED64:
|
374
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED64:
|
375
|
+
CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
|
376
|
+
break;
|
377
|
+
default:
|
378
|
+
return upb_append_unknown(d, frame);
|
379
|
+
}
|
380
|
+
|
381
|
+
upb_decode_setpresent(frame, field);
|
382
|
+
return true;
|
383
|
+
}
|
384
|
+
|
385
|
+
static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame,
|
386
|
+
const upb_msglayout_field *field) {
|
387
|
+
uint32_t val;
|
388
|
+
CHK(upb_decode_32bit(&d->ptr, d->limit, &val));
|
389
|
+
|
390
|
+
switch (field->descriptortype) {
|
391
|
+
case UPB_DESCRIPTOR_TYPE_FLOAT:
|
392
|
+
case UPB_DESCRIPTOR_TYPE_FIXED32:
|
393
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED32:
|
394
|
+
CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
|
395
|
+
break;
|
396
|
+
default:
|
397
|
+
return upb_append_unknown(d, frame);
|
398
|
+
}
|
399
|
+
|
400
|
+
upb_decode_setpresent(frame, field);
|
401
|
+
return true;
|
402
|
+
}
|
403
|
+
|
404
|
+
static bool upb_decode_fixedpacked(upb_decstate *d, upb_array *arr,
|
405
|
+
uint32_t len, int elem_size) {
|
406
|
+
size_t elements = len / elem_size;
|
407
|
+
|
408
|
+
CHK((size_t)(elements * elem_size) == len);
|
409
|
+
CHK(upb_array_add(arr, elements, elem_size, d->ptr, d->arena));
|
410
|
+
d->ptr += len;
|
411
|
+
|
412
|
+
return true;
|
413
|
+
}
|
414
|
+
|
415
|
+
static upb_strview upb_decode_strfield(upb_decstate *d, uint32_t len) {
|
416
|
+
upb_strview ret;
|
417
|
+
ret.data = d->ptr;
|
418
|
+
ret.size = len;
|
419
|
+
d->ptr += len;
|
420
|
+
return ret;
|
421
|
+
}
|
422
|
+
|
423
|
+
static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
|
424
|
+
const upb_msglayout_field *field, int len) {
|
425
|
+
upb_array *arr = upb_getorcreatearr(frame, field);
|
426
|
+
CHK(arr);
|
427
|
+
|
428
|
+
#define VARINT_CASE(ctype, decode) \
|
429
|
+
VARINT_CASE_EX(ctype, decode, decode)
|
430
|
+
|
431
|
+
#define VARINT_CASE_EX(ctype, decode, dtype) \
|
432
|
+
{ \
|
433
|
+
const char *ptr = d->ptr; \
|
434
|
+
const char *limit = ptr + len; \
|
435
|
+
while (ptr < limit) { \
|
436
|
+
uint64_t val; \
|
437
|
+
ctype decoded; \
|
438
|
+
CHK(upb_decode_varint(&ptr, limit, &val)); \
|
439
|
+
decoded = (decode)((dtype)val); \
|
440
|
+
CHK(upb_array_add(arr, 1, sizeof(decoded), &decoded, d->arena)); \
|
441
|
+
} \
|
442
|
+
d->ptr = ptr; \
|
443
|
+
return true; \
|
444
|
+
}
|
445
|
+
|
446
|
+
switch (field->descriptortype) {
|
447
|
+
case UPB_DESCRIPTOR_TYPE_STRING:
|
448
|
+
case UPB_DESCRIPTOR_TYPE_BYTES: {
|
449
|
+
upb_strview str = upb_decode_strfield(d, len);
|
450
|
+
return upb_array_add(arr, 1, sizeof(str), &str, d->arena);
|
451
|
+
}
|
452
|
+
case UPB_DESCRIPTOR_TYPE_FLOAT:
|
453
|
+
case UPB_DESCRIPTOR_TYPE_FIXED32:
|
454
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED32:
|
455
|
+
return upb_decode_fixedpacked(d, arr, len, sizeof(int32_t));
|
456
|
+
case UPB_DESCRIPTOR_TYPE_DOUBLE:
|
457
|
+
case UPB_DESCRIPTOR_TYPE_FIXED64:
|
458
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED64:
|
459
|
+
return upb_decode_fixedpacked(d, arr, len, sizeof(int64_t));
|
460
|
+
case UPB_DESCRIPTOR_TYPE_INT32:
|
461
|
+
case UPB_DESCRIPTOR_TYPE_UINT32:
|
462
|
+
case UPB_DESCRIPTOR_TYPE_ENUM:
|
463
|
+
VARINT_CASE(uint32_t, uint32_t);
|
464
|
+
case UPB_DESCRIPTOR_TYPE_INT64:
|
465
|
+
case UPB_DESCRIPTOR_TYPE_UINT64:
|
466
|
+
VARINT_CASE(uint64_t, uint64_t);
|
467
|
+
case UPB_DESCRIPTOR_TYPE_BOOL:
|
468
|
+
VARINT_CASE(bool, bool);
|
469
|
+
case UPB_DESCRIPTOR_TYPE_SINT32:
|
470
|
+
VARINT_CASE_EX(int32_t, upb_zzdecode_32, uint32_t);
|
471
|
+
case UPB_DESCRIPTOR_TYPE_SINT64:
|
472
|
+
VARINT_CASE_EX(int64_t, upb_zzdecode_64, uint64_t);
|
473
|
+
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
|
474
|
+
const upb_msglayout *subm;
|
475
|
+
upb_msg *submsg = upb_addmsg(frame, field, &subm);
|
476
|
+
CHK(submsg);
|
477
|
+
return upb_decode_msgfield(d, submsg, subm, len);
|
478
|
+
}
|
479
|
+
case UPB_DESCRIPTOR_TYPE_GROUP:
|
480
|
+
return upb_append_unknown(d, frame);
|
481
|
+
}
|
482
|
+
#undef VARINT_CASE
|
483
|
+
UPB_UNREACHABLE();
|
484
|
+
}
|
485
|
+
|
486
|
+
static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
|
487
|
+
const upb_msglayout_field *field) {
|
488
|
+
int len;
|
489
|
+
|
490
|
+
CHK(upb_decode_string(&d->ptr, d->limit, &len));
|
491
|
+
|
492
|
+
if (field->label == UPB_LABEL_REPEATED) {
|
493
|
+
return upb_decode_toarray(d, frame, field, len);
|
494
|
+
} else {
|
495
|
+
switch (field->descriptortype) {
|
496
|
+
case UPB_DESCRIPTOR_TYPE_STRING:
|
497
|
+
case UPB_DESCRIPTOR_TYPE_BYTES: {
|
498
|
+
upb_strview str = upb_decode_strfield(d, len);
|
499
|
+
CHK(upb_decode_addval(frame, field, &str, sizeof(str)));
|
500
|
+
break;
|
501
|
+
}
|
502
|
+
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
|
503
|
+
const upb_msglayout *subm;
|
504
|
+
upb_msg *submsg = upb_getorcreatemsg(frame, field, &subm);
|
505
|
+
CHK(submsg);
|
506
|
+
CHK(upb_decode_msgfield(d, submsg, subm, len));
|
507
|
+
break;
|
508
|
+
}
|
509
|
+
default:
|
510
|
+
/* TODO(haberman): should we accept the last element of a packed? */
|
511
|
+
d->ptr += len;
|
512
|
+
return upb_append_unknown(d, frame);
|
513
|
+
}
|
514
|
+
upb_decode_setpresent(frame, field);
|
515
|
+
return true;
|
516
|
+
}
|
517
|
+
}
|
518
|
+
|
519
|
+
static const upb_msglayout_field *upb_find_field(const upb_msglayout *l,
|
520
|
+
uint32_t field_number) {
|
521
|
+
/* Lots of optimization opportunities here. */
|
522
|
+
int i;
|
523
|
+
for (i = 0; i < l->field_count; i++) {
|
524
|
+
if (l->fields[i].number == field_number) {
|
525
|
+
return &l->fields[i];
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
return NULL; /* Unknown field. */
|
530
|
+
}
|
531
|
+
|
532
|
+
static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) {
|
533
|
+
uint32_t tag;
|
534
|
+
const upb_msglayout_field *field;
|
535
|
+
int field_number;
|
536
|
+
|
537
|
+
d->field_start = d->ptr;
|
538
|
+
CHK(upb_decode_varint32(&d->ptr, d->limit, &tag));
|
539
|
+
field_number = tag >> 3;
|
540
|
+
field = upb_find_field(frame->layout, field_number);
|
541
|
+
|
542
|
+
if (field) {
|
543
|
+
switch (tag & 7) {
|
544
|
+
case UPB_WIRE_TYPE_VARINT:
|
545
|
+
return upb_decode_varintfield(d, frame, field);
|
546
|
+
case UPB_WIRE_TYPE_32BIT:
|
547
|
+
return upb_decode_32bitfield(d, frame, field);
|
548
|
+
case UPB_WIRE_TYPE_64BIT:
|
549
|
+
return upb_decode_64bitfield(d, frame, field);
|
550
|
+
case UPB_WIRE_TYPE_DELIMITED:
|
551
|
+
return upb_decode_delimitedfield(d, frame, field);
|
552
|
+
case UPB_WIRE_TYPE_START_GROUP: {
|
553
|
+
const upb_msglayout *layout;
|
554
|
+
upb_msg *group;
|
555
|
+
|
556
|
+
if (field->label == UPB_LABEL_REPEATED) {
|
557
|
+
group = upb_addmsg(frame, field, &layout);
|
558
|
+
} else {
|
559
|
+
group = upb_getorcreatemsg(frame, field, &layout);
|
560
|
+
}
|
561
|
+
|
562
|
+
return upb_decode_groupfield(d, group, layout, field_number);
|
563
|
+
}
|
564
|
+
case UPB_WIRE_TYPE_END_GROUP:
|
565
|
+
d->end_group = field_number;
|
566
|
+
return true;
|
567
|
+
default:
|
568
|
+
CHK(false);
|
569
|
+
}
|
570
|
+
} else {
|
571
|
+
CHK(field_number != 0);
|
572
|
+
CHK(upb_skip_unknownfielddata(d, tag, -1));
|
573
|
+
CHK(upb_append_unknown(d, frame));
|
574
|
+
return true;
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
static bool upb_decode_message(upb_decstate *d, char *msg, const upb_msglayout *l) {
|
579
|
+
upb_decframe frame;
|
580
|
+
frame.msg = msg;
|
581
|
+
frame.layout = l;
|
582
|
+
frame.state = d;
|
583
|
+
|
584
|
+
while (d->ptr < d->limit) {
|
585
|
+
CHK(upb_decode_field(d, &frame));
|
586
|
+
}
|
587
|
+
|
588
|
+
return true;
|
589
|
+
}
|
590
|
+
|
591
|
+
bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
|
592
|
+
upb_arena *arena) {
|
593
|
+
upb_decstate state;
|
594
|
+
state.ptr = buf;
|
595
|
+
state.limit = buf + size;
|
596
|
+
state.arena = arena;
|
597
|
+
state.depth = 64;
|
598
|
+
state.end_group = 0;
|
599
|
+
|
600
|
+
CHK(upb_decode_message(&state, msg, l));
|
601
|
+
return state.end_group == 0;
|
602
|
+
}
|
603
|
+
|
604
|
+
#undef CHK
|