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_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_DECODE_HUFF_H 20 #define GRPC_SRC_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: GetOp2(size_t i)29 static inline uint64_t GetOp2(size_t i) { return table2_0_ops_[i]; } GetEmit2(size_t,size_t emit)30 static inline uint64_t GetEmit2(size_t, size_t emit) { 31 return table2_0_emit_[emit]; 32 } GetOp3(size_t i)33 static inline uint64_t GetOp3(size_t i) { return table3_0_ops_[i]; } GetEmit3(size_t,size_t emit)34 static inline uint64_t GetEmit3(size_t, size_t emit) { 35 return table3_0_emit_[emit]; 36 } GetOp4(size_t i)37 static inline uint64_t GetOp4(size_t i) { 38 return table4_ops_[i >> 6][i & 0x3f]; 39 } GetEmit4(size_t i,size_t emit)40 static inline uint64_t GetEmit4(size_t i, size_t emit) { 41 return table4_emit_[i >> 6][emit]; 42 } GetOp1(size_t i)43 static inline uint64_t GetOp1(size_t i) { 44 return table1_0_inner_[table1_0_outer_[i]]; 45 } GetEmit1(size_t,size_t emit)46 static inline uint64_t GetEmit1(size_t, size_t emit) { 47 return table1_0_emit_[emit]; 48 } GetOp5(size_t i)49 static inline uint64_t GetOp5(size_t i) { 50 return (i < 2 ? (i ? 6 : 2) : ((i - 2) ? 14 : 10)); 51 } GetEmit5(size_t,size_t emit)52 static inline uint64_t GetEmit5(size_t, size_t emit) { 53 return (emit < 2 ? (emit + 33) : ((emit - 2) + 40)); 54 } GetOp7(size_t i)55 static inline uint64_t GetOp7(size_t i) { 56 return ((i < 2 ? (i) : ((i - 2) + 1)) < 1 57 ? (((void)(i < 2 ? (i) : ((i - 2) + 1)), 2)) 58 : (((i < 2 ? (i) : ((i - 2) + 1)) - 1) ? 0 : 1)); 59 } GetEmit7(size_t,size_t emit)60 static inline uint64_t GetEmit7(size_t, size_t emit) { 61 return ((void)emit, 63); 62 } GetOp8(size_t i)63 static inline uint64_t GetOp8(size_t i) { 64 return table8_0_inner_[table8_0_outer_[i]]; 65 } GetEmit8(size_t,size_t emit)66 static inline uint64_t GetEmit8(size_t, size_t emit) { 67 return (emit < 2 ? (emit ? 39 : 63) : ((emit - 2) ? 124 : 43)); 68 } GetOp9(size_t i)69 static inline uint64_t GetOp9(size_t i) { 70 return table9_0_inner_[table9_0_outer_[i]]; 71 } GetEmit9(size_t,size_t emit)72 static inline uint64_t GetEmit9(size_t, size_t emit) { 73 return table9_0_emit_[emit]; 74 } GetOp10(size_t i)75 static inline uint64_t GetOp10(size_t i) { return table10_0_ops_[i]; } GetEmit10(size_t,size_t emit)76 static inline uint64_t GetEmit10(size_t, size_t emit) { 77 return table10_0_emit_[emit]; 78 } GetOp11(size_t i)79 static inline uint64_t GetOp11(size_t i) { return table11_0_ops_[i]; } GetEmit11(size_t,size_t emit)80 static inline uint64_t GetEmit11(size_t, size_t emit) { 81 return table11_0_emit_[emit]; 82 } GetOp6(size_t i)83 static inline uint64_t GetOp6(size_t i) { 84 return table6_ops_[i >> 6][i & 0x3f]; 85 } GetEmit6(size_t i,size_t emit)86 static inline uint64_t GetEmit6(size_t i, size_t emit) { 87 return table6_emit_[i >> 6][emit]; 88 } GetOp13(size_t i)89 static inline uint64_t GetOp13(size_t i) { 90 return table13_0_inner_[(i < 3 ? (i) : ((i - 3) / 12 + 3))]; 91 } GetEmit13(size_t,size_t emit)92 static inline uint64_t GetEmit13(size_t, size_t emit) { 93 return (emit < 1 ? (((void)emit, 92)) : ((emit - 1) ? 208 : 195)); 94 } GetOp14(size_t i)95 static inline uint64_t GetOp14(size_t i) { return table14_0_ops_[i]; } GetEmit14(size_t,size_t emit)96 static inline uint64_t GetEmit14(size_t, size_t emit) { 97 return table14_0_emit_[emit]; 98 } GetOp15(size_t i)99 static inline uint64_t GetOp15(size_t i) { return table15_0_ops_[i]; } GetEmit15(size_t,size_t emit)100 static inline uint64_t GetEmit15(size_t, size_t emit) { 101 return table15_0_emit_[emit]; 102 } GetOp16(size_t i)103 static inline uint64_t GetOp16(size_t i) { return table16_0_ops_[i]; } GetEmit16(size_t,size_t emit)104 static inline uint64_t GetEmit16(size_t, size_t emit) { 105 return table16_0_emit_[emit]; 106 } GetOp12(size_t i)107 static inline uint64_t GetOp12(size_t i) { 108 return table12_0_inner_[table12_0_outer_[i]]; 109 } GetEmit12(size_t,size_t emit)110 static inline uint64_t GetEmit12(size_t, size_t emit) { 111 return table12_0_emit_[emit]; 112 } GetOp17(size_t i)113 static inline uint64_t GetOp17(size_t i) { return i ? 3 : 1; } GetEmit17(size_t,size_t emit)114 static inline uint64_t GetEmit17(size_t, size_t emit) { 115 return emit ? 142 : 9; 116 } GetOp18(size_t i)117 static inline uint64_t GetOp18(size_t i) { return i ? 3 : 1; } GetEmit18(size_t,size_t emit)118 static inline uint64_t GetEmit18(size_t, size_t emit) { return emit + 144; } GetOp19(size_t i)119 static inline uint64_t GetOp19(size_t i) { return i ? 3 : 1; } GetEmit19(size_t,size_t emit)120 static inline uint64_t GetEmit19(size_t, size_t emit) { 121 return emit ? 159 : 148; 122 } GetOp20(size_t i)123 static inline uint64_t GetOp20(size_t i) { return i ? 3 : 1; } GetEmit20(size_t,size_t emit)124 static inline uint64_t GetEmit20(size_t, size_t emit) { 125 return emit ? 206 : 171; 126 } GetOp21(size_t i)127 static inline uint64_t GetOp21(size_t i) { return i ? 3 : 1; } GetEmit21(size_t,size_t emit)128 static inline uint64_t GetEmit21(size_t, size_t emit) { 129 return emit ? 225 : 215; 130 } GetOp22(size_t i)131 static inline uint64_t GetOp22(size_t i) { return i ? 3 : 1; } GetEmit22(size_t,size_t emit)132 static inline uint64_t GetEmit22(size_t, size_t emit) { return emit + 236; } GetOp23(size_t i)133 static inline uint64_t GetOp23(size_t i) { 134 return (i < 2 ? (i ? 6 : 2) : ((i - 2) ? 14 : 10)); 135 } GetEmit23(size_t,size_t emit)136 static inline uint64_t GetEmit23(size_t, size_t emit) { 137 return (emit < 2 ? (emit ? 207 : 199) : ((emit - 2) + 234)); 138 } GetOp24(size_t i)139 static inline uint64_t GetOp24(size_t i) { return table24_0_inner_[i]; } GetEmit24(size_t,size_t emit)140 static inline uint64_t GetEmit24(size_t, size_t emit) { 141 return table24_0_emit_[emit]; 142 } GetOp25(size_t i)143 static inline uint64_t GetOp25(size_t i) { return table25_0_inner_[i]; } GetEmit25(size_t,size_t emit)144 static inline uint64_t GetEmit25(size_t, size_t emit) { 145 return table25_0_emit_[emit]; 146 } GetOp27(size_t i)147 static inline uint64_t GetOp27(size_t i) { 148 return ( 149 (i < 1 ? (((void)i, 0)) : ((i - 1) / 14 + 1)) < 1 150 ? (((void)(i < 1 ? (((void)i, 0)) : ((i - 1) / 14 + 1)), 2)) 151 : (((i < 1 ? (((void)i, 0)) : ((i - 1) / 14 + 1)) - 1) ? 0 : 1)); 152 } GetEmit27(size_t,size_t emit)153 static inline uint64_t GetEmit27(size_t, size_t emit) { 154 return ((void)emit, 254); 155 } GetOp26(size_t i)156 static inline uint64_t GetOp26(size_t i) { 157 return table26_0_inner_[(i < 1 ? (((void)i, 0)) : ((i - 1)))]; 158 } GetEmit26(size_t,size_t emit)159 static inline uint64_t GetEmit26(size_t, size_t emit) { 160 return table26_0_emit_[emit]; 161 } GetOp28(size_t i)162 static inline uint64_t GetOp28(size_t i) { 163 return (i < 2 ? (i ? 10 : 2) : ((i - 2) ? 6 : 18)); 164 } GetEmit28(size_t,size_t emit)165 static inline uint64_t GetEmit28(size_t, size_t emit) { 166 return (emit < 1 ? (((void)emit, 10)) : ((emit - 1) ? 22 : 13)); 167 } GetOp30(size_t i)168 static inline uint64_t GetOp30(size_t i) { return table30_0_inner_[i]; } GetEmit30(size_t,size_t emit)169 static inline uint64_t GetEmit30(size_t, size_t emit) { 170 return table30_0_emit_[emit]; 171 } GetOp29(size_t i)172 static inline uint64_t GetOp29(size_t i) { 173 return table29_0_inner_[(i < 13 ? (i / 2 + 0) : ((i - 13) + 6))]; 174 } GetEmit29(size_t,size_t emit)175 static inline uint64_t GetEmit29(size_t, size_t emit) { 176 return table29_0_emit_[emit]; 177 } 178 179 private: 180 static const uint8_t table2_0_emit_[10]; 181 static const uint8_t table2_0_ops_[32]; 182 static const uint8_t table3_0_emit_[36]; 183 static const uint8_t table3_0_ops_[64]; 184 static const uint8_t table4_0_emit_[22]; 185 static const uint8_t table4_0_ops_[64]; 186 static const uint8_t table4_1_emit_[46]; 187 static const uint8_t table4_1_ops_[64]; 188 static const uint8_t* const table4_emit_[2]; 189 static const uint8_t* const table4_ops_[2]; 190 static const uint8_t table1_0_emit_[74]; 191 static const uint16_t table1_0_inner_[76]; 192 static const uint8_t table1_0_outer_[256]; 193 static const uint8_t table8_0_inner_[6]; 194 static const uint8_t table8_0_outer_[8]; 195 static const uint8_t table9_0_emit_[6]; 196 static const uint8_t table9_0_inner_[8]; 197 static const uint8_t table9_0_outer_[16]; 198 static const uint8_t table10_0_emit_[12]; 199 static const uint8_t table10_0_ops_[32]; 200 static const uint8_t table11_0_emit_[14]; 201 static const uint8_t table11_0_ops_[64]; 202 static const uint8_t table6_0_emit_[3]; 203 static const uint8_t table6_0_ops_[64]; 204 static const uint8_t table6_1_emit_[14]; 205 static const uint8_t table6_1_ops_[64]; 206 static const uint8_t* const table6_emit_[2]; 207 static const uint8_t* const table6_ops_[2]; 208 static const uint8_t table13_0_inner_[5]; 209 static const uint8_t table14_0_emit_[11]; 210 static const uint8_t table14_0_ops_[32]; 211 static const uint8_t table15_0_emit_[24]; 212 static const uint8_t table15_0_ops_[64]; 213 static const uint8_t table16_0_emit_[50]; 214 static const uint8_t table16_0_ops_[128]; 215 static const uint8_t table12_0_emit_[79]; 216 static const uint16_t table12_0_inner_[90]; 217 static const uint8_t table12_0_outer_[256]; 218 static const uint8_t table24_0_emit_[8]; 219 static const uint8_t table24_0_inner_[8]; 220 static const uint8_t table25_0_emit_[16]; 221 static const uint8_t table25_0_inner_[16]; 222 static const uint8_t table26_0_emit_[30]; 223 static const uint16_t table26_0_inner_[31]; 224 static const uint8_t table30_0_emit_[7]; 225 static const uint8_t table30_0_inner_[8]; 226 static const uint8_t table29_0_emit_[9]; 227 static const uint8_t table29_0_inner_[9]; 228 }; 229 template <typename F> 230 class HuffDecoder : public HuffDecoderCommon { 231 public: HuffDecoder(F sink,const uint8_t * begin,const uint8_t * end)232 HuffDecoder(F sink, const uint8_t* begin, const uint8_t* end) 233 : sink_(sink), begin_(begin), end_(end) {} Run()234 bool Run() { 235 while (!done_) { 236 if (!RefillTo8()) { 237 Done0(); 238 break; 239 } 240 const auto index = (buffer_ >> (buffer_len_ - 8)) & 0xff; 241 const auto op = GetOp1(index); 242 const int consumed = op & 15; 243 buffer_len_ -= consumed; 244 const auto emit_ofs = op >> 6; 245 switch ((op >> 4) & 3) { 246 case 1: { 247 DecodeStep0(); 248 break; 249 } 250 case 2: { 251 DecodeStep1(); 252 break; 253 } 254 case 0: { 255 sink_(GetEmit1(index, emit_ofs + 0)); 256 break; 257 } 258 } 259 } 260 return ok_; 261 } 262 263 private: RefillTo8()264 bool RefillTo8() { 265 switch (buffer_len_) { 266 case 0: 267 case 1: 268 case 2: 269 case 3: 270 case 4: 271 case 5: 272 case 6: 273 case 7: { 274 return Read1(); 275 } 276 } 277 return true; 278 } Read1()279 bool Read1() { 280 if (end_ - begin_ < 1) return false; 281 buffer_ <<= 8; 282 buffer_ |= static_cast<uint64_t>(*begin_++) << 0; 283 buffer_len_ += 8; 284 return true; 285 } Done0()286 void Done0() { 287 done_ = true; 288 switch (buffer_len_) { 289 case 7: { 290 const auto index = buffer_ & 127; 291 const auto op = GetOp4(index); 292 switch (op & 3) { 293 case 1: { 294 ok_ = false; 295 break; 296 } 297 case 2: { 298 sink_(GetEmit4(index, op >> 2)); 299 break; 300 } 301 } 302 return; 303 } 304 case 5: { 305 const auto index = buffer_ & 31; 306 const auto op = GetOp2(index); 307 switch (op & 3) { 308 case 1: { 309 ok_ = false; 310 break; 311 } 312 case 2: { 313 sink_(GetEmit2(index, op >> 2)); 314 break; 315 } 316 } 317 return; 318 } 319 case 6: { 320 const auto index = buffer_ & 63; 321 const auto op = GetOp3(index); 322 switch (op & 3) { 323 case 1: { 324 ok_ = false; 325 break; 326 } 327 case 2: { 328 sink_(GetEmit3(index, op >> 2)); 329 break; 330 } 331 } 332 return; 333 } 334 case 1: 335 case 2: 336 case 3: 337 case 4: { 338 ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1; 339 return; 340 } 341 case 0: { 342 return; 343 } 344 } 345 } DecodeStep0()346 void DecodeStep0() { 347 if (!RefillTo2()) { 348 Done1(); 349 return; 350 } 351 const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3; 352 const auto op = GetOp5(index); 353 const int consumed = op & 3; 354 buffer_len_ -= consumed; 355 const auto emit_ofs = op >> 2; 356 sink_(GetEmit5(index, emit_ofs + 0)); 357 } RefillTo2()358 bool RefillTo2() { 359 switch (buffer_len_) { 360 case 0: 361 case 1: { 362 return Read1(); 363 } 364 } 365 return true; 366 } Done1()367 void Done1() { 368 done_ = true; 369 switch (buffer_len_) { 370 case 0: 371 case 1: { 372 ok_ = false; 373 return; 374 } 375 } 376 } DecodeStep1()377 void DecodeStep1() { 378 if (!RefillTo7()) { 379 Done2(); 380 return; 381 } 382 const auto index = (buffer_ >> (buffer_len_ - 7)) & 0x7f; 383 const auto op = GetOp6(index); 384 const int consumed = op & 7; 385 buffer_len_ -= consumed; 386 const auto emit_ofs = op >> 4; 387 switch ((op >> 3) & 1) { 388 case 1: { 389 DecodeStep2(); 390 break; 391 } 392 case 0: { 393 sink_(GetEmit6(index, emit_ofs + 0)); 394 break; 395 } 396 } 397 } RefillTo7()398 bool RefillTo7() { 399 switch (buffer_len_) { 400 case 0: 401 case 1: 402 case 2: 403 case 3: 404 case 4: 405 case 5: 406 case 6: { 407 return Read1(); 408 } 409 } 410 return true; 411 } Done2()412 void Done2() { 413 done_ = true; 414 switch (buffer_len_) { 415 case 4: { 416 const auto index = buffer_ & 15; 417 const auto op = GetOp9(index); 418 switch (op & 3) { 419 case 1: { 420 ok_ = false; 421 break; 422 } 423 case 2: { 424 sink_(GetEmit9(index, op >> 2)); 425 break; 426 } 427 } 428 return; 429 } 430 case 5: { 431 const auto index = buffer_ & 31; 432 const auto op = GetOp10(index); 433 switch (op & 3) { 434 case 1: { 435 ok_ = false; 436 break; 437 } 438 case 2: { 439 sink_(GetEmit10(index, op >> 2)); 440 break; 441 } 442 } 443 return; 444 } 445 case 2: { 446 const auto index = buffer_ & 3; 447 const auto op = GetOp7(index); 448 switch (op & 3) { 449 case 1: { 450 ok_ = false; 451 break; 452 } 453 case 2: { 454 sink_(GetEmit7(index, op >> 2)); 455 break; 456 } 457 } 458 return; 459 } 460 case 6: { 461 const auto index = buffer_ & 63; 462 const auto op = GetOp11(index); 463 switch (op & 3) { 464 case 1: { 465 ok_ = false; 466 break; 467 } 468 case 2: { 469 sink_(GetEmit11(index, op >> 2)); 470 break; 471 } 472 } 473 return; 474 } 475 case 3: { 476 const auto index = buffer_ & 7; 477 const auto op = GetOp8(index); 478 switch (op & 3) { 479 case 1: { 480 ok_ = false; 481 break; 482 } 483 case 2: { 484 sink_(GetEmit8(index, op >> 2)); 485 break; 486 } 487 } 488 return; 489 } 490 case 1: { 491 ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1; 492 return; 493 } 494 case 0: { 495 return; 496 } 497 } 498 } DecodeStep2()499 void DecodeStep2() { 500 if (!RefillTo8()) { 501 Done3(); 502 return; 503 } 504 const auto index = (buffer_ >> (buffer_len_ - 8)) & 0xff; 505 const auto op = GetOp12(index); 506 const int consumed = op & 15; 507 buffer_len_ -= consumed; 508 const auto emit_ofs = op >> 8; 509 switch ((op >> 4) & 15) { 510 case 8: { 511 DecodeStep10(); 512 break; 513 } 514 case 10: { 515 DecodeStep11(); 516 break; 517 } 518 case 11: { 519 DecodeStep12(); 520 break; 521 } 522 case 9: { 523 DecodeStep14(); 524 break; 525 } 526 case 1: { 527 DecodeStep3(); 528 break; 529 } 530 case 2: { 531 DecodeStep4(); 532 break; 533 } 534 case 3: { 535 DecodeStep5(); 536 break; 537 } 538 case 4: { 539 DecodeStep6(); 540 break; 541 } 542 case 5: { 543 DecodeStep7(); 544 break; 545 } 546 case 6: { 547 DecodeStep8(); 548 break; 549 } 550 case 7: { 551 DecodeStep9(); 552 break; 553 } 554 case 0: { 555 sink_(GetEmit12(index, emit_ofs + 0)); 556 break; 557 } 558 } 559 } Done3()560 void Done3() { 561 done_ = true; 562 switch (buffer_len_) { 563 case 7: { 564 const auto index = buffer_ & 127; 565 const auto op = GetOp16(index); 566 switch (op & 3) { 567 case 1: { 568 ok_ = false; 569 break; 570 } 571 case 2: { 572 sink_(GetEmit16(index, op >> 2)); 573 break; 574 } 575 } 576 return; 577 } 578 case 4: { 579 const auto index = buffer_ & 15; 580 const auto op = GetOp13(index); 581 switch (op & 3) { 582 case 1: { 583 ok_ = false; 584 break; 585 } 586 case 2: { 587 sink_(GetEmit13(index, op >> 2)); 588 break; 589 } 590 } 591 return; 592 } 593 case 5: { 594 const auto index = buffer_ & 31; 595 const auto op = GetOp14(index); 596 switch (op & 3) { 597 case 1: { 598 ok_ = false; 599 break; 600 } 601 case 2: { 602 sink_(GetEmit14(index, op >> 2)); 603 break; 604 } 605 } 606 return; 607 } 608 case 6: { 609 const auto index = buffer_ & 63; 610 const auto op = GetOp15(index); 611 switch (op & 3) { 612 case 1: { 613 ok_ = false; 614 break; 615 } 616 case 2: { 617 sink_(GetEmit15(index, op >> 2)); 618 break; 619 } 620 } 621 return; 622 } 623 case 1: 624 case 2: 625 case 3: { 626 ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1; 627 return; 628 } 629 case 0: { 630 return; 631 } 632 } 633 } DecodeStep3()634 void DecodeStep3() { 635 if (!RefillTo1()) { 636 Done4(); 637 return; 638 } 639 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 640 const auto op = GetOp17(index); 641 const int consumed = op & 1; 642 buffer_len_ -= consumed; 643 const auto emit_ofs = op >> 1; 644 sink_(GetEmit17(index, emit_ofs + 0)); 645 } RefillTo1()646 bool RefillTo1() { 647 switch (buffer_len_) { 648 case 0: { 649 return Read1(); 650 } 651 } 652 return true; 653 } Done4()654 void Done4() { 655 done_ = true; 656 ok_ = false; 657 } DecodeStep4()658 void DecodeStep4() { 659 if (!RefillTo1()) { 660 Done5(); 661 return; 662 } 663 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 664 const auto op = GetOp18(index); 665 const int consumed = op & 1; 666 buffer_len_ -= consumed; 667 const auto emit_ofs = op >> 1; 668 sink_(GetEmit18(index, emit_ofs + 0)); 669 } Done5()670 void Done5() { 671 done_ = true; 672 ok_ = false; 673 } DecodeStep5()674 void DecodeStep5() { 675 if (!RefillTo1()) { 676 Done6(); 677 return; 678 } 679 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 680 const auto op = GetOp19(index); 681 const int consumed = op & 1; 682 buffer_len_ -= consumed; 683 const auto emit_ofs = op >> 1; 684 sink_(GetEmit19(index, emit_ofs + 0)); 685 } Done6()686 void Done6() { 687 done_ = true; 688 ok_ = false; 689 } DecodeStep6()690 void DecodeStep6() { 691 if (!RefillTo1()) { 692 Done7(); 693 return; 694 } 695 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 696 const auto op = GetOp20(index); 697 const int consumed = op & 1; 698 buffer_len_ -= consumed; 699 const auto emit_ofs = op >> 1; 700 sink_(GetEmit20(index, emit_ofs + 0)); 701 } Done7()702 void Done7() { 703 done_ = true; 704 ok_ = false; 705 } DecodeStep7()706 void DecodeStep7() { 707 if (!RefillTo1()) { 708 Done8(); 709 return; 710 } 711 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 712 const auto op = GetOp21(index); 713 const int consumed = op & 1; 714 buffer_len_ -= consumed; 715 const auto emit_ofs = op >> 1; 716 sink_(GetEmit21(index, emit_ofs + 0)); 717 } Done8()718 void Done8() { 719 done_ = true; 720 ok_ = false; 721 } DecodeStep8()722 void DecodeStep8() { 723 if (!RefillTo1()) { 724 Done9(); 725 return; 726 } 727 const auto index = (buffer_ >> (buffer_len_ - 1)) & 0x1; 728 const auto op = GetOp22(index); 729 const int consumed = op & 1; 730 buffer_len_ -= consumed; 731 const auto emit_ofs = op >> 1; 732 sink_(GetEmit22(index, emit_ofs + 0)); 733 } Done9()734 void Done9() { 735 done_ = true; 736 ok_ = false; 737 } DecodeStep9()738 void DecodeStep9() { 739 if (!RefillTo2()) { 740 Done10(); 741 return; 742 } 743 const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3; 744 const auto op = GetOp23(index); 745 const int consumed = op & 3; 746 buffer_len_ -= consumed; 747 const auto emit_ofs = op >> 2; 748 sink_(GetEmit23(index, emit_ofs + 0)); 749 } Done10()750 void Done10() { 751 done_ = true; 752 switch (buffer_len_) { 753 case 0: 754 case 1: { 755 ok_ = false; 756 return; 757 } 758 } 759 } DecodeStep10()760 void DecodeStep10() { 761 if (!RefillTo3()) { 762 Done11(); 763 return; 764 } 765 const auto index = (buffer_ >> (buffer_len_ - 3)) & 0x7; 766 const auto op = GetOp24(index); 767 const int consumed = op & 3; 768 buffer_len_ -= consumed; 769 const auto emit_ofs = op >> 2; 770 sink_(GetEmit24(index, emit_ofs + 0)); 771 } RefillTo3()772 bool RefillTo3() { 773 switch (buffer_len_) { 774 case 0: 775 case 1: 776 case 2: { 777 return Read1(); 778 } 779 } 780 return true; 781 } Done11()782 void Done11() { 783 done_ = true; 784 switch (buffer_len_) { 785 case 0: 786 case 1: 787 case 2: { 788 ok_ = false; 789 return; 790 } 791 } 792 } DecodeStep11()793 void DecodeStep11() { 794 if (!RefillTo4()) { 795 Done12(); 796 return; 797 } 798 const auto index = (buffer_ >> (buffer_len_ - 4)) & 0xf; 799 const auto op = GetOp25(index); 800 const int consumed = op & 7; 801 buffer_len_ -= consumed; 802 const auto emit_ofs = op >> 3; 803 sink_(GetEmit25(index, emit_ofs + 0)); 804 } RefillTo4()805 bool RefillTo4() { 806 switch (buffer_len_) { 807 case 0: 808 case 1: 809 case 2: 810 case 3: { 811 return Read1(); 812 } 813 } 814 return true; 815 } Done12()816 void Done12() { 817 done_ = true; 818 switch (buffer_len_) { 819 case 0: 820 case 1: 821 case 2: 822 case 3: { 823 ok_ = false; 824 return; 825 } 826 } 827 } DecodeStep12()828 void DecodeStep12() { 829 if (!RefillTo5()) { 830 Done13(); 831 return; 832 } 833 const auto index = (buffer_ >> (buffer_len_ - 5)) & 0x1f; 834 const auto op = GetOp26(index); 835 const int consumed = op & 7; 836 buffer_len_ -= consumed; 837 const auto emit_ofs = op >> 4; 838 switch ((op >> 3) & 1) { 839 case 1: { 840 DecodeStep13(); 841 break; 842 } 843 case 0: { 844 sink_(GetEmit26(index, emit_ofs + 0)); 845 break; 846 } 847 } 848 } RefillTo5()849 bool RefillTo5() { 850 switch (buffer_len_) { 851 case 0: 852 case 1: 853 case 2: 854 case 3: 855 case 4: { 856 return Read1(); 857 } 858 } 859 return true; 860 } Done13()861 void Done13() { 862 done_ = true; 863 switch (buffer_len_) { 864 case 4: { 865 const auto index = buffer_ & 15; 866 const auto op = GetOp27(index); 867 switch (op & 3) { 868 case 1: { 869 ok_ = false; 870 break; 871 } 872 case 2: { 873 sink_(GetEmit27(index, op >> 2)); 874 break; 875 } 876 } 877 return; 878 } 879 case 1: 880 case 2: 881 case 3: { 882 ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1; 883 return; 884 } 885 case 0: { 886 return; 887 } 888 } 889 } DecodeStep13()890 void DecodeStep13() { 891 if (!RefillTo2()) { 892 Done14(); 893 return; 894 } 895 const auto index = (buffer_ >> (buffer_len_ - 2)) & 0x3; 896 const auto op = GetOp28(index); 897 const int consumed = op & 3; 898 buffer_len_ -= consumed; 899 const auto emit_ofs = op >> 3; 900 switch ((op >> 2) & 1) { 901 case 1: { 902 begin_ = end_; 903 buffer_len_ = 0; 904 break; 905 } 906 case 0: { 907 sink_(GetEmit28(index, emit_ofs + 0)); 908 break; 909 } 910 } 911 } Done14()912 void Done14() { 913 done_ = true; 914 switch (buffer_len_) { 915 case 1: { 916 ok_ = (buffer_ & ((1 << buffer_len_) - 1)) == (1 << buffer_len_) - 1; 917 return; 918 } 919 case 0: { 920 return; 921 } 922 } 923 } DecodeStep14()924 void DecodeStep14() { 925 if (!RefillTo4()) { 926 Done15(); 927 return; 928 } 929 const auto index = (buffer_ >> (buffer_len_ - 4)) & 0xf; 930 const auto op = GetOp29(index); 931 const int consumed = op & 7; 932 buffer_len_ -= consumed; 933 const auto emit_ofs = op >> 3; 934 sink_(GetEmit29(index, emit_ofs + 0)); 935 } Done15()936 void Done15() { 937 done_ = true; 938 switch (buffer_len_) { 939 case 3: { 940 const auto index = buffer_ & 7; 941 const auto op = GetOp30(index); 942 switch (op & 3) { 943 case 1: { 944 ok_ = false; 945 break; 946 } 947 case 2: { 948 sink_(GetEmit30(index, op >> 2)); 949 break; 950 } 951 } 952 return; 953 } 954 case 0: 955 case 1: 956 case 2: { 957 ok_ = false; 958 return; 959 } 960 } 961 } 962 F sink_; 963 const uint8_t* begin_; 964 const uint8_t* const end_; 965 uint64_t buffer_ = 0; 966 int buffer_len_ = 0; 967 bool ok_ = true; 968 bool done_ = false; 969 }; 970 } // namespace grpc_core 971 #endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_DECODE_HUFF_H 972