grpc 1.49.1 → 1.50.0.pre1

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

Potentially problematic release.


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

Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +33 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +112 -96
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +84 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -15
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +1 -1
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/lib/grpc/version.rb +1 -1
  258. data/src/ruby/spec/channel_spec.rb +5 -0
  259. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  260. data/src/ruby/spec/user_agent_spec.rb +1 -1
  261. metadata +33 -19
  262. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  263. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  264. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  265. data/src/core/lib/event_engine/promise.h +0 -78
  266. data/src/core/lib/gpr/env_windows.cc +0 -74
  267. data/src/core/lib/gpr/string_windows.h +0 -32
  268. data/src/core/lib/profiling/basic_timers.cc +0 -295
  269. data/src/core/lib/profiling/stap_timers.cc +0 -50
  270. data/src/core/lib/profiling/timers.h +0 -94
@@ -0,0 +1,1018 @@
1
+ // Copyright 2022 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+ // This file is autogenerated: see
17
+ // tools/codegen/core/gen_huffman_decompressor.cc
18
+
19
+ #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_DECODE_HUFF_H
20
+ #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_DECODE_HUFF_H
21
+ #include <grpc/support/port_platform.h>
22
+
23
+ #include <cstddef>
24
+ #include <cstdint>
25
+ // GEOMETRY: 8,7,8,5
26
+ namespace grpc_core {
27
+ class HuffDecoderCommon {
28
+ protected:
29
+ static inline uint64_t GetOp2(size_t i) { return table2_0_ops_[i]; }
30
+ static inline uint64_t GetEmit2(size_t, size_t emit) {
31
+ return table2_0_emit_[emit];
32
+ }
33
+ static inline uint64_t GetOp3(size_t i) { return table3_0_ops_[i]; }
34
+ static inline uint64_t GetEmit3(size_t, size_t emit) {
35
+ return table3_0_emit_[emit];
36
+ }
37
+ static inline uint64_t GetOp4(size_t i) {
38
+ return table4_ops_[i >> 6][i & 0x3f];
39
+ }
40
+ static inline uint64_t GetEmit4(size_t i, size_t emit) {
41
+ return table4_emit_[i >> 6][emit];
42
+ }
43
+ static inline uint64_t GetOp1(size_t i) {
44
+ return table1_0_inner_[table1_0_outer_[i]];
45
+ }
46
+ static inline uint64_t GetEmit1(size_t, size_t emit) {
47
+ return table1_0_emit_[emit];
48
+ }
49
+ static inline uint64_t GetOp5(size_t i) {
50
+ return table5_0_inner_[table5_0_outer_[i]];
51
+ }
52
+ static inline uint64_t GetEmit5(size_t, size_t emit) {
53
+ return table5_0_emit_[emit];
54
+ }
55
+ static inline uint64_t GetOp7(size_t i) {
56
+ return table7_0_inner_[table7_0_outer_[i]];
57
+ }
58
+ static inline uint64_t GetEmit7(size_t, size_t emit) {
59
+ return table7_0_emit_[emit];
60
+ }
61
+ static inline uint64_t GetOp8(size_t i) {
62
+ return table8_0_inner_[table8_0_outer_[i]];
63
+ }
64
+ static inline uint64_t GetEmit8(size_t, size_t emit) {
65
+ return table8_0_emit_[emit];
66
+ }
67
+ static inline uint64_t GetOp9(size_t i) {
68
+ return table9_0_inner_[table9_0_outer_[i]];
69
+ }
70
+ static inline uint64_t GetEmit9(size_t, size_t emit) {
71
+ return table9_0_emit_[emit];
72
+ }
73
+ static inline uint64_t GetOp10(size_t i) { return table10_0_ops_[i]; }
74
+ static inline uint64_t GetEmit10(size_t, size_t emit) {
75
+ return table10_0_emit_[emit];
76
+ }
77
+ static inline uint64_t GetOp11(size_t i) { return table11_0_ops_[i]; }
78
+ static inline uint64_t GetEmit11(size_t, size_t emit) {
79
+ return table11_0_emit_[emit];
80
+ }
81
+ static inline uint64_t GetOp6(size_t i) {
82
+ return table6_ops_[i >> 6][i & 0x3f];
83
+ }
84
+ static inline uint64_t GetEmit6(size_t i, size_t emit) {
85
+ return table6_emit_[i >> 6][emit];
86
+ }
87
+ static inline uint64_t GetOp13(size_t i) {
88
+ return table13_0_inner_[table13_0_outer_[i]];
89
+ }
90
+ static inline uint64_t GetEmit13(size_t, size_t emit) {
91
+ return table13_0_emit_[emit];
92
+ }
93
+ static inline uint64_t GetOp14(size_t i) { return table14_0_ops_[i]; }
94
+ static inline uint64_t GetEmit14(size_t, size_t emit) {
95
+ return table14_0_emit_[emit];
96
+ }
97
+ static inline uint64_t GetOp15(size_t i) { return table15_0_ops_[i]; }
98
+ static inline uint64_t GetEmit15(size_t, size_t emit) {
99
+ return table15_0_emit_[emit];
100
+ }
101
+ static inline uint64_t GetOp16(size_t i) { return table16_0_ops_[i]; }
102
+ static inline uint64_t GetEmit16(size_t, size_t emit) {
103
+ return table16_0_emit_[emit];
104
+ }
105
+ static inline uint64_t GetOp12(size_t i) {
106
+ return table12_0_inner_[table12_0_outer_[i]];
107
+ }
108
+ static inline uint64_t GetEmit12(size_t, size_t emit) {
109
+ return table12_0_emit_[emit];
110
+ }
111
+ static inline uint64_t GetOp17(size_t i) {
112
+ return table17_0_inner_[table17_0_outer_[i]];
113
+ }
114
+ static inline uint64_t GetEmit17(size_t, size_t emit) {
115
+ return table17_0_emit_[emit];
116
+ }
117
+ static inline uint64_t GetOp18(size_t i) {
118
+ return table18_0_inner_[table18_0_outer_[i]];
119
+ }
120
+ static inline uint64_t GetEmit18(size_t, size_t emit) {
121
+ return table18_0_emit_[emit];
122
+ }
123
+ static inline uint64_t GetOp19(size_t i) {
124
+ return table17_0_inner_[table18_0_outer_[i]];
125
+ }
126
+ static inline uint64_t GetEmit19(size_t, size_t emit) {
127
+ return table19_0_emit_[emit];
128
+ }
129
+ static inline uint64_t GetOp20(size_t i) {
130
+ return table17_0_inner_[table18_0_outer_[i]];
131
+ }
132
+ static inline uint64_t GetEmit20(size_t, size_t emit) {
133
+ return table20_0_emit_[emit];
134
+ }
135
+ static inline uint64_t GetOp21(size_t i) {
136
+ return table17_0_inner_[table18_0_outer_[i]];
137
+ }
138
+ static inline uint64_t GetEmit21(size_t, size_t emit) {
139
+ return table21_0_emit_[emit];
140
+ }
141
+ static inline uint64_t GetOp22(size_t i) {
142
+ return table17_0_inner_[table18_0_outer_[i]];
143
+ }
144
+ static inline uint64_t GetEmit22(size_t, size_t emit) {
145
+ return table22_0_emit_[emit];
146
+ }
147
+ static inline uint64_t GetOp23(size_t i) {
148
+ return table5_0_inner_[table23_0_outer_[i]];
149
+ }
150
+ static inline uint64_t GetEmit23(size_t, size_t emit) {
151
+ return table23_0_emit_[emit];
152
+ }
153
+ static inline uint64_t GetOp24(size_t i) {
154
+ return table24_0_inner_[table24_0_outer_[i]];
155
+ }
156
+ static inline uint64_t GetEmit24(size_t, size_t emit) {
157
+ return table24_0_emit_[emit];
158
+ }
159
+ static inline uint64_t GetOp25(size_t i) {
160
+ return table25_0_inner_[table25_0_outer_[i]];
161
+ }
162
+ static inline uint64_t GetEmit25(size_t, size_t emit) {
163
+ return table25_0_emit_[emit];
164
+ }
165
+ static inline uint64_t GetOp27(size_t i) {
166
+ return table27_0_inner_[table27_0_outer_[i]];
167
+ }
168
+ static inline uint64_t GetEmit27(size_t, size_t emit) {
169
+ return table27_0_emit_[emit];
170
+ }
171
+ static inline uint64_t GetOp26(size_t i) {
172
+ return table26_0_inner_[table26_0_outer_[i]];
173
+ }
174
+ static inline uint64_t GetEmit26(size_t, size_t emit) {
175
+ return table26_0_emit_[emit];
176
+ }
177
+ static inline uint64_t GetOp28(size_t i) {
178
+ return table28_0_inner_[table5_0_outer_[i]];
179
+ }
180
+ static inline uint64_t GetEmit28(size_t, size_t emit) {
181
+ return table28_0_emit_[emit];
182
+ }
183
+ static inline uint64_t GetOp30(size_t i) {
184
+ return table30_0_inner_[table24_0_outer_[i]];
185
+ }
186
+ static inline uint64_t GetEmit30(size_t, size_t emit) {
187
+ return table30_0_emit_[emit];
188
+ }
189
+ static inline uint64_t GetOp29(size_t i) {
190
+ return table29_0_inner_[table29_0_outer_[i]];
191
+ }
192
+ static inline uint64_t GetEmit29(size_t, size_t emit) {
193
+ return table29_0_emit_[emit];
194
+ }
195
+
196
+ private:
197
+ static const uint8_t table2_0_emit_[10];
198
+ static const uint8_t table2_0_ops_[32];
199
+ static const uint8_t table3_0_emit_[36];
200
+ static const uint8_t table3_0_ops_[64];
201
+ static const uint8_t table4_0_emit_[22];
202
+ static const uint8_t table4_0_ops_[64];
203
+ static const uint8_t table4_1_emit_[46];
204
+ static const uint8_t table4_1_ops_[64];
205
+ static const uint8_t* const table4_emit_[2];
206
+ static const uint8_t* const table4_ops_[2];
207
+ static const uint8_t table1_0_emit_[74];
208
+ static const uint16_t table1_0_inner_[76];
209
+ static const uint8_t table1_0_outer_[256];
210
+ static const uint8_t table5_0_emit_[4];
211
+ static const uint8_t table5_0_inner_[4];
212
+ static const uint8_t table5_0_outer_[4];
213
+ static const uint8_t table7_0_emit_[1];
214
+ static const uint8_t table7_0_inner_[3];
215
+ static const uint8_t table7_0_outer_[4];
216
+ static const uint8_t table8_0_emit_[4];
217
+ static const uint8_t table8_0_inner_[6];
218
+ static const uint8_t table8_0_outer_[8];
219
+ static const uint8_t table9_0_emit_[6];
220
+ static const uint8_t table9_0_inner_[8];
221
+ static const uint8_t table9_0_outer_[16];
222
+ static const uint8_t table10_0_emit_[12];
223
+ static const uint8_t table10_0_ops_[32];
224
+ static const uint8_t table11_0_emit_[14];
225
+ static const uint8_t table11_0_ops_[64];
226
+ static const uint8_t table6_0_emit_[3];
227
+ static const uint8_t table6_0_ops_[64];
228
+ static const uint8_t table6_1_emit_[14];
229
+ static const uint8_t table6_1_ops_[64];
230
+ static const uint8_t* const table6_emit_[2];
231
+ static const uint8_t* const table6_ops_[2];
232
+ static const uint8_t table13_0_emit_[3];
233
+ static const uint8_t table13_0_inner_[5];
234
+ static const uint8_t table13_0_outer_[16];
235
+ static const uint8_t table14_0_emit_[11];
236
+ static const uint8_t table14_0_ops_[32];
237
+ static const uint8_t table15_0_emit_[24];
238
+ static const uint8_t table15_0_ops_[64];
239
+ static const uint8_t table16_0_emit_[50];
240
+ static const uint8_t table16_0_ops_[128];
241
+ static const uint8_t table12_0_emit_[79];
242
+ static const uint16_t table12_0_inner_[90];
243
+ static const uint8_t table12_0_outer_[256];
244
+ static const uint8_t table17_0_emit_[2];
245
+ static const uint8_t table17_0_inner_[2];
246
+ static const uint8_t table17_0_outer_[2];
247
+ static const uint8_t table18_0_emit_[2];
248
+ static const uint8_t table18_0_inner_[2];
249
+ static const uint8_t table18_0_outer_[2];
250
+ static const uint8_t table19_0_emit_[2];
251
+ static const uint8_t table20_0_emit_[2];
252
+ static const uint8_t table21_0_emit_[2];
253
+ static const uint8_t table22_0_emit_[2];
254
+ static const uint8_t table23_0_emit_[4];
255
+ static const uint8_t table23_0_outer_[4];
256
+ static const uint8_t table24_0_emit_[8];
257
+ static const uint8_t table24_0_inner_[8];
258
+ static const uint8_t table24_0_outer_[8];
259
+ static const uint8_t table25_0_emit_[16];
260
+ static const uint8_t table25_0_inner_[16];
261
+ static const uint8_t table25_0_outer_[16];
262
+ static const uint8_t table27_0_emit_[1];
263
+ static const uint8_t table27_0_inner_[3];
264
+ static const uint8_t table27_0_outer_[16];
265
+ static const uint8_t table26_0_emit_[30];
266
+ static const uint16_t table26_0_inner_[31];
267
+ static const uint8_t table26_0_outer_[32];
268
+ static const uint8_t table28_0_emit_[3];
269
+ static const uint8_t table28_0_inner_[4];
270
+ static const uint8_t table30_0_emit_[7];
271
+ static const uint8_t table30_0_inner_[8];
272
+ static const uint8_t table29_0_emit_[9];
273
+ static const uint8_t table29_0_inner_[9];
274
+ static const uint8_t table29_0_outer_[16];
275
+ };
276
+ template <typename F>
277
+ class HuffDecoder : public HuffDecoderCommon {
278
+ public:
279
+ HuffDecoder(F sink, const uint8_t* begin, const uint8_t* end)
280
+ : sink_(sink), begin_(begin), end_(end) {}
281
+ bool Run() {
282
+ while (!done_) {
283
+ if (!RefillTo8()) {
284
+ Done0();
285
+ break;
286
+ }
287
+ const auto index = (buffer_ >> (buffer_len_ - 8)) & 0xff;
288
+ const auto op = GetOp1(index);
289
+ const int consumed = op & 15;
290
+ buffer_len_ -= consumed;
291
+ const auto emit_ofs = op >> 6;
292
+ switch ((op >> 4) & 3) {
293
+ case 1: {
294
+ DecodeStep0();
295
+ break;
296
+ }
297
+ case 2: {
298
+ DecodeStep1();
299
+ break;
300
+ }
301
+ case 0: {
302
+ sink_(GetEmit1(index, emit_ofs + 0));
303
+ break;
304
+ }
305
+ }
306
+ }
307
+ return ok_;
308
+ }
309
+
310
+ private:
311
+ bool RefillTo8() {
312
+ switch (buffer_len_) {
313
+ case 0:
314
+ case 1:
315
+ case 2:
316
+ case 3:
317
+ case 4:
318
+ case 5:
319
+ case 6:
320
+ case 7: {
321
+ return Read1();
322
+ }
323
+ }
324
+ return true;
325
+ }
326
+ bool Read1() {
327
+ if (end_ - begin_ < 1) return false;
328
+ buffer_ <<= 8;
329
+ buffer_ |= static_cast<uint64_t>(*begin_++) << 0;
330
+ buffer_len_ += 8;
331
+ return true;
332
+ }
333
+ void Done0() {
334
+ done_ = true;
335
+ switch (buffer_len_) {
336
+ case 7: {
337
+ const auto index = buffer_ & 127;
338
+ const auto op = GetOp4(index);
339
+ switch (op & 3) {
340
+ case 1: {
341
+ ok_ = false;
342
+ break;
343
+ }
344
+ case 2: {
345
+ sink_(GetEmit4(index, op >> 2));
346
+ break;
347
+ }
348
+ }
349
+ return;
350
+ }
351
+ case 5: {
352
+ const auto index = buffer_ & 31;
353
+ const auto op = GetOp2(index);
354
+ switch (op & 3) {
355
+ case 1: {
356
+ ok_ = false;
357
+ break;
358
+ }
359
+ case 2: {
360
+ sink_(GetEmit2(index, op >> 2));
361
+ break;
362
+ }
363
+ }
364
+ return;
365
+ }
366
+ case 6: {
367
+ const auto index = buffer_ & 63;
368
+ const auto op = GetOp3(index);
369
+ switch (op & 3) {
370
+ case 1: {
371
+ ok_ = false;
372
+ break;
373
+ }
374
+ case 2: {
375
+ sink_(GetEmit3(index, op >> 2));
376
+ break;
377
+ }
378
+ }
379
+ return;
380
+ }
381
+ case 1:
382
+ case 2:
383
+ case 3:
384
+ case 4: {
385
+ ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1;
386
+ return;
387
+ }
388
+ case 0: {
389
+ return;
390
+ }
391
+ }
392
+ }
393
+ void DecodeStep0() {
394
+ if (!RefillTo2()) {
395
+ Done1();
396
+ return;
397
+ }
398
+ const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3;
399
+ const auto op = GetOp5(index);
400
+ const int consumed = op & 3;
401
+ buffer_len_ -= consumed;
402
+ const auto emit_ofs = op >> 2;
403
+ sink_(GetEmit5(index, emit_ofs + 0));
404
+ }
405
+ bool RefillTo2() {
406
+ switch (buffer_len_) {
407
+ case 0:
408
+ case 1: {
409
+ return Read1();
410
+ }
411
+ }
412
+ return true;
413
+ }
414
+ void Done1() {
415
+ done_ = true;
416
+ switch (buffer_len_) {
417
+ case 0:
418
+ case 1: {
419
+ ok_ = false;
420
+ return;
421
+ }
422
+ }
423
+ }
424
+ void DecodeStep1() {
425
+ if (!RefillTo7()) {
426
+ Done2();
427
+ return;
428
+ }
429
+ const auto index = (buffer_ >> (buffer_len_ - 7)) & 0x7f;
430
+ const auto op = GetOp6(index);
431
+ const int consumed = op & 7;
432
+ buffer_len_ -= consumed;
433
+ const auto emit_ofs = op >> 4;
434
+ switch ((op >> 3) & 1) {
435
+ case 1: {
436
+ DecodeStep2();
437
+ break;
438
+ }
439
+ case 0: {
440
+ sink_(GetEmit6(index, emit_ofs + 0));
441
+ break;
442
+ }
443
+ }
444
+ }
445
+ bool RefillTo7() {
446
+ switch (buffer_len_) {
447
+ case 0:
448
+ case 1:
449
+ case 2:
450
+ case 3:
451
+ case 4:
452
+ case 5:
453
+ case 6: {
454
+ return Read1();
455
+ }
456
+ }
457
+ return true;
458
+ }
459
+ void Done2() {
460
+ done_ = true;
461
+ switch (buffer_len_) {
462
+ case 4: {
463
+ const auto index = buffer_ & 15;
464
+ const auto op = GetOp9(index);
465
+ switch (op & 3) {
466
+ case 1: {
467
+ ok_ = false;
468
+ break;
469
+ }
470
+ case 2: {
471
+ sink_(GetEmit9(index, op >> 2));
472
+ break;
473
+ }
474
+ }
475
+ return;
476
+ }
477
+ case 5: {
478
+ const auto index = buffer_ & 31;
479
+ const auto op = GetOp10(index);
480
+ switch (op & 3) {
481
+ case 1: {
482
+ ok_ = false;
483
+ break;
484
+ }
485
+ case 2: {
486
+ sink_(GetEmit10(index, op >> 2));
487
+ break;
488
+ }
489
+ }
490
+ return;
491
+ }
492
+ case 2: {
493
+ const auto index = buffer_ & 3;
494
+ const auto op = GetOp7(index);
495
+ switch (op & 3) {
496
+ case 1: {
497
+ ok_ = false;
498
+ break;
499
+ }
500
+ case 2: {
501
+ sink_(GetEmit7(index, op >> 2));
502
+ break;
503
+ }
504
+ }
505
+ return;
506
+ }
507
+ case 6: {
508
+ const auto index = buffer_ & 63;
509
+ const auto op = GetOp11(index);
510
+ switch (op & 3) {
511
+ case 1: {
512
+ ok_ = false;
513
+ break;
514
+ }
515
+ case 2: {
516
+ sink_(GetEmit11(index, op >> 2));
517
+ break;
518
+ }
519
+ }
520
+ return;
521
+ }
522
+ case 3: {
523
+ const auto index = buffer_ & 7;
524
+ const auto op = GetOp8(index);
525
+ switch (op & 3) {
526
+ case 1: {
527
+ ok_ = false;
528
+ break;
529
+ }
530
+ case 2: {
531
+ sink_(GetEmit8(index, op >> 2));
532
+ break;
533
+ }
534
+ }
535
+ return;
536
+ }
537
+ case 1: {
538
+ ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1;
539
+ return;
540
+ }
541
+ case 0: {
542
+ return;
543
+ }
544
+ }
545
+ }
546
+ void DecodeStep2() {
547
+ if (!RefillTo8()) {
548
+ Done3();
549
+ return;
550
+ }
551
+ const auto index = (buffer_ >> (buffer_len_ - 8)) & 0xff;
552
+ const auto op = GetOp12(index);
553
+ const int consumed = op & 15;
554
+ buffer_len_ -= consumed;
555
+ const auto emit_ofs = op >> 8;
556
+ switch ((op >> 4) & 15) {
557
+ case 8: {
558
+ DecodeStep10();
559
+ break;
560
+ }
561
+ case 10: {
562
+ DecodeStep11();
563
+ break;
564
+ }
565
+ case 11: {
566
+ DecodeStep12();
567
+ break;
568
+ }
569
+ case 9: {
570
+ DecodeStep14();
571
+ break;
572
+ }
573
+ case 1: {
574
+ DecodeStep3();
575
+ break;
576
+ }
577
+ case 2: {
578
+ DecodeStep4();
579
+ break;
580
+ }
581
+ case 3: {
582
+ DecodeStep5();
583
+ break;
584
+ }
585
+ case 4: {
586
+ DecodeStep6();
587
+ break;
588
+ }
589
+ case 5: {
590
+ DecodeStep7();
591
+ break;
592
+ }
593
+ case 6: {
594
+ DecodeStep8();
595
+ break;
596
+ }
597
+ case 7: {
598
+ DecodeStep9();
599
+ break;
600
+ }
601
+ case 0: {
602
+ sink_(GetEmit12(index, emit_ofs + 0));
603
+ break;
604
+ }
605
+ }
606
+ }
607
+ void Done3() {
608
+ done_ = true;
609
+ switch (buffer_len_) {
610
+ case 7: {
611
+ const auto index = buffer_ & 127;
612
+ const auto op = GetOp16(index);
613
+ switch (op & 3) {
614
+ case 1: {
615
+ ok_ = false;
616
+ break;
617
+ }
618
+ case 2: {
619
+ sink_(GetEmit16(index, op >> 2));
620
+ break;
621
+ }
622
+ }
623
+ return;
624
+ }
625
+ case 4: {
626
+ const auto index = buffer_ & 15;
627
+ const auto op = GetOp13(index);
628
+ switch (op & 3) {
629
+ case 1: {
630
+ ok_ = false;
631
+ break;
632
+ }
633
+ case 2: {
634
+ sink_(GetEmit13(index, op >> 2));
635
+ break;
636
+ }
637
+ }
638
+ return;
639
+ }
640
+ case 5: {
641
+ const auto index = buffer_ & 31;
642
+ const auto op = GetOp14(index);
643
+ switch (op & 3) {
644
+ case 1: {
645
+ ok_ = false;
646
+ break;
647
+ }
648
+ case 2: {
649
+ sink_(GetEmit14(index, op >> 2));
650
+ break;
651
+ }
652
+ }
653
+ return;
654
+ }
655
+ case 6: {
656
+ const auto index = buffer_ & 63;
657
+ const auto op = GetOp15(index);
658
+ switch (op & 3) {
659
+ case 1: {
660
+ ok_ = false;
661
+ break;
662
+ }
663
+ case 2: {
664
+ sink_(GetEmit15(index, op >> 2));
665
+ break;
666
+ }
667
+ }
668
+ return;
669
+ }
670
+ case 1:
671
+ case 2:
672
+ case 3: {
673
+ ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1;
674
+ return;
675
+ }
676
+ case 0: {
677
+ return;
678
+ }
679
+ }
680
+ }
681
+ void DecodeStep3() {
682
+ if (!RefillTo1()) {
683
+ Done4();
684
+ return;
685
+ }
686
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
687
+ const auto op = GetOp17(index);
688
+ const int consumed = op & 1;
689
+ buffer_len_ -= consumed;
690
+ const auto emit_ofs = op >> 1;
691
+ sink_(GetEmit17(index, emit_ofs + 0));
692
+ }
693
+ bool RefillTo1() {
694
+ switch (buffer_len_) {
695
+ case 0: {
696
+ return Read1();
697
+ }
698
+ }
699
+ return true;
700
+ }
701
+ void Done4() {
702
+ done_ = true;
703
+ ok_ = false;
704
+ }
705
+ void DecodeStep4() {
706
+ if (!RefillTo1()) {
707
+ Done5();
708
+ return;
709
+ }
710
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
711
+ const auto op = GetOp18(index);
712
+ const int consumed = op & 1;
713
+ buffer_len_ -= consumed;
714
+ const auto emit_ofs = op >> 1;
715
+ sink_(GetEmit18(index, emit_ofs + 0));
716
+ }
717
+ void Done5() {
718
+ done_ = true;
719
+ ok_ = false;
720
+ }
721
+ void DecodeStep5() {
722
+ if (!RefillTo1()) {
723
+ Done6();
724
+ return;
725
+ }
726
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
727
+ const auto op = GetOp19(index);
728
+ const int consumed = op & 1;
729
+ buffer_len_ -= consumed;
730
+ const auto emit_ofs = op >> 1;
731
+ sink_(GetEmit19(index, emit_ofs + 0));
732
+ }
733
+ void Done6() {
734
+ done_ = true;
735
+ ok_ = false;
736
+ }
737
+ void DecodeStep6() {
738
+ if (!RefillTo1()) {
739
+ Done7();
740
+ return;
741
+ }
742
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
743
+ const auto op = GetOp20(index);
744
+ const int consumed = op & 1;
745
+ buffer_len_ -= consumed;
746
+ const auto emit_ofs = op >> 1;
747
+ sink_(GetEmit20(index, emit_ofs + 0));
748
+ }
749
+ void Done7() {
750
+ done_ = true;
751
+ ok_ = false;
752
+ }
753
+ void DecodeStep7() {
754
+ if (!RefillTo1()) {
755
+ Done8();
756
+ return;
757
+ }
758
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
759
+ const auto op = GetOp21(index);
760
+ const int consumed = op & 1;
761
+ buffer_len_ -= consumed;
762
+ const auto emit_ofs = op >> 1;
763
+ sink_(GetEmit21(index, emit_ofs + 0));
764
+ }
765
+ void Done8() {
766
+ done_ = true;
767
+ ok_ = false;
768
+ }
769
+ void DecodeStep8() {
770
+ if (!RefillTo1()) {
771
+ Done9();
772
+ return;
773
+ }
774
+ const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1;
775
+ const auto op = GetOp22(index);
776
+ const int consumed = op & 1;
777
+ buffer_len_ -= consumed;
778
+ const auto emit_ofs = op >> 1;
779
+ sink_(GetEmit22(index, emit_ofs + 0));
780
+ }
781
+ void Done9() {
782
+ done_ = true;
783
+ ok_ = false;
784
+ }
785
+ void DecodeStep9() {
786
+ if (!RefillTo2()) {
787
+ Done10();
788
+ return;
789
+ }
790
+ const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3;
791
+ const auto op = GetOp23(index);
792
+ const int consumed = op & 3;
793
+ buffer_len_ -= consumed;
794
+ const auto emit_ofs = op >> 2;
795
+ sink_(GetEmit23(index, emit_ofs + 0));
796
+ }
797
+ void Done10() {
798
+ done_ = true;
799
+ switch (buffer_len_) {
800
+ case 0:
801
+ case 1: {
802
+ ok_ = false;
803
+ return;
804
+ }
805
+ }
806
+ }
807
+ void DecodeStep10() {
808
+ if (!RefillTo3()) {
809
+ Done11();
810
+ return;
811
+ }
812
+ const auto index = (buffer_ >> (buffer_len_ - 3)) & 0x7;
813
+ const auto op = GetOp24(index);
814
+ const int consumed = op & 3;
815
+ buffer_len_ -= consumed;
816
+ const auto emit_ofs = op >> 2;
817
+ sink_(GetEmit24(index, emit_ofs + 0));
818
+ }
819
+ bool RefillTo3() {
820
+ switch (buffer_len_) {
821
+ case 0:
822
+ case 1:
823
+ case 2: {
824
+ return Read1();
825
+ }
826
+ }
827
+ return true;
828
+ }
829
+ void Done11() {
830
+ done_ = true;
831
+ switch (buffer_len_) {
832
+ case 0:
833
+ case 1:
834
+ case 2: {
835
+ ok_ = false;
836
+ return;
837
+ }
838
+ }
839
+ }
840
+ void DecodeStep11() {
841
+ if (!RefillTo4()) {
842
+ Done12();
843
+ return;
844
+ }
845
+ const auto index = (buffer_ >> (buffer_len_ - 4)) & 0xf;
846
+ const auto op = GetOp25(index);
847
+ const int consumed = op & 7;
848
+ buffer_len_ -= consumed;
849
+ const auto emit_ofs = op >> 3;
850
+ sink_(GetEmit25(index, emit_ofs + 0));
851
+ }
852
+ bool RefillTo4() {
853
+ switch (buffer_len_) {
854
+ case 0:
855
+ case 1:
856
+ case 2:
857
+ case 3: {
858
+ return Read1();
859
+ }
860
+ }
861
+ return true;
862
+ }
863
+ void Done12() {
864
+ done_ = true;
865
+ switch (buffer_len_) {
866
+ case 0:
867
+ case 1:
868
+ case 2:
869
+ case 3: {
870
+ ok_ = false;
871
+ return;
872
+ }
873
+ }
874
+ }
875
+ void DecodeStep12() {
876
+ if (!RefillTo5()) {
877
+ Done13();
878
+ return;
879
+ }
880
+ const auto index = (buffer_ >> (buffer_len_ - 5)) & 0x1f;
881
+ const auto op = GetOp26(index);
882
+ const int consumed = op & 7;
883
+ buffer_len_ -= consumed;
884
+ const auto emit_ofs = op >> 4;
885
+ switch ((op >> 3) & 1) {
886
+ case 1: {
887
+ DecodeStep13();
888
+ break;
889
+ }
890
+ case 0: {
891
+ sink_(GetEmit26(index, emit_ofs + 0));
892
+ break;
893
+ }
894
+ }
895
+ }
896
+ bool RefillTo5() {
897
+ switch (buffer_len_) {
898
+ case 0:
899
+ case 1:
900
+ case 2:
901
+ case 3:
902
+ case 4: {
903
+ return Read1();
904
+ }
905
+ }
906
+ return true;
907
+ }
908
+ void Done13() {
909
+ done_ = true;
910
+ switch (buffer_len_) {
911
+ case 4: {
912
+ const auto index = buffer_ & 15;
913
+ const auto op = GetOp27(index);
914
+ switch (op & 3) {
915
+ case 1: {
916
+ ok_ = false;
917
+ break;
918
+ }
919
+ case 2: {
920
+ sink_(GetEmit27(index, op >> 2));
921
+ break;
922
+ }
923
+ }
924
+ return;
925
+ }
926
+ case 1:
927
+ case 2:
928
+ case 3: {
929
+ ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1;
930
+ return;
931
+ }
932
+ case 0: {
933
+ return;
934
+ }
935
+ }
936
+ }
937
+ void DecodeStep13() {
938
+ if (!RefillTo2()) {
939
+ Done14();
940
+ return;
941
+ }
942
+ const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3;
943
+ const auto op = GetOp28(index);
944
+ const int consumed = op & 3;
945
+ buffer_len_ -= consumed;
946
+ const auto emit_ofs = op >> 3;
947
+ switch ((op >> 2) & 1) {
948
+ case 1: {
949
+ begin_ = end_;
950
+ buffer_len_ = 0;
951
+ break;
952
+ }
953
+ case 0: {
954
+ sink_(GetEmit28(index, emit_ofs + 0));
955
+ break;
956
+ }
957
+ }
958
+ }
959
+ void Done14() {
960
+ done_ = true;
961
+ switch (buffer_len_) {
962
+ case 1: {
963
+ ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1;
964
+ return;
965
+ }
966
+ case 0: {
967
+ return;
968
+ }
969
+ }
970
+ }
971
+ void DecodeStep14() {
972
+ if (!RefillTo4()) {
973
+ Done15();
974
+ return;
975
+ }
976
+ const auto index = (buffer_ >> (buffer_len_ - 4)) & 0xf;
977
+ const auto op = GetOp29(index);
978
+ const int consumed = op & 7;
979
+ buffer_len_ -= consumed;
980
+ const auto emit_ofs = op >> 3;
981
+ sink_(GetEmit29(index, emit_ofs + 0));
982
+ }
983
+ void Done15() {
984
+ done_ = true;
985
+ switch (buffer_len_) {
986
+ case 3: {
987
+ const auto index = buffer_ & 7;
988
+ const auto op = GetOp30(index);
989
+ switch (op & 3) {
990
+ case 1: {
991
+ ok_ = false;
992
+ break;
993
+ }
994
+ case 2: {
995
+ sink_(GetEmit30(index, op >> 2));
996
+ break;
997
+ }
998
+ }
999
+ return;
1000
+ }
1001
+ case 0:
1002
+ case 1:
1003
+ case 2: {
1004
+ ok_ = false;
1005
+ return;
1006
+ }
1007
+ }
1008
+ }
1009
+ F sink_;
1010
+ const uint8_t* begin_;
1011
+ const uint8_t* const end_;
1012
+ uint64_t buffer_ = 0;
1013
+ int buffer_len_ = 0;
1014
+ bool ok_ = true;
1015
+ bool done_ = false;
1016
+ };
1017
+ } // namespace grpc_core
1018
+ #endif // GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_DECODE_HUFF_H