1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "quiche/http2/hpack/decoder/hpack_block_decoder.h"
6
7 #include <cstdint>
8
9 #include "absl/strings/str_cat.h"
10 #include "quiche/common/platform/api/quiche_flag_utils.h"
11 #include "quiche/common/platform/api/quiche_logging.h"
12
13 namespace http2 {
14
Decode(DecodeBuffer * db)15 DecodeStatus HpackBlockDecoder::Decode(DecodeBuffer* db) {
16 if (!before_entry_) {
17 QUICHE_DVLOG(2) << "HpackBlockDecoder::Decode resume entry, db->Remaining="
18 << db->Remaining();
19 DecodeStatus status = entry_decoder_.Resume(db, listener_);
20 switch (status) {
21 case DecodeStatus::kDecodeDone:
22 before_entry_ = true;
23 break;
24 case DecodeStatus::kDecodeInProgress:
25 QUICHE_DCHECK_EQ(0u, db->Remaining());
26 return DecodeStatus::kDecodeInProgress;
27 case DecodeStatus::kDecodeError:
28 QUICHE_CODE_COUNT_N(decompress_failure_3, 1, 23);
29 return DecodeStatus::kDecodeError;
30 }
31 }
32 QUICHE_DCHECK(before_entry_);
33 while (db->HasData()) {
34 QUICHE_DVLOG(2) << "HpackBlockDecoder::Decode start entry, db->Remaining="
35 << db->Remaining();
36 DecodeStatus status = entry_decoder_.Start(db, listener_);
37 switch (status) {
38 case DecodeStatus::kDecodeDone:
39 continue;
40 case DecodeStatus::kDecodeInProgress:
41 QUICHE_DCHECK_EQ(0u, db->Remaining());
42 before_entry_ = false;
43 return DecodeStatus::kDecodeInProgress;
44 case DecodeStatus::kDecodeError:
45 QUICHE_CODE_COUNT_N(decompress_failure_3, 2, 23);
46 return DecodeStatus::kDecodeError;
47 }
48 QUICHE_DCHECK(false);
49 }
50 QUICHE_DCHECK(before_entry_);
51 return DecodeStatus::kDecodeDone;
52 }
53
DebugString() const54 std::string HpackBlockDecoder::DebugString() const {
55 return absl::StrCat(
56 "HpackBlockDecoder(", entry_decoder_.DebugString(), ", listener@",
57 absl::Hex(reinterpret_cast<intptr_t>(listener_)),
58 (before_entry_ ? ", between entries)" : ", in an entry)"));
59 }
60
operator <<(std::ostream & out,const HpackBlockDecoder & v)61 std::ostream& operator<<(std::ostream& out, const HpackBlockDecoder& v) {
62 return out << v.DebugString();
63 }
64
65 } // namespace http2
66