xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/hpack/decoder/hpack_block_decoder.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #ifndef QUICHE_HTTP2_HPACK_DECODER_HPACK_BLOCK_DECODER_H_
6 #define QUICHE_HTTP2_HPACK_DECODER_HPACK_BLOCK_DECODER_H_
7 
8 // HpackBlockDecoder decodes an entire HPACK block (or the available portion
9 // thereof in the DecodeBuffer) into entries, but doesn't include HPACK static
10 // or dynamic table support, so table indices remain indices at this level.
11 // Reports the entries to an HpackEntryDecoderListener.
12 
13 #include <string>
14 
15 #include "quiche/http2/decoder/decode_buffer.h"
16 #include "quiche/http2/decoder/decode_status.h"
17 #include "quiche/http2/hpack/decoder/hpack_decoding_error.h"
18 #include "quiche/http2/hpack/decoder/hpack_entry_decoder.h"
19 #include "quiche/http2/hpack/decoder/hpack_entry_decoder_listener.h"
20 #include "quiche/common/platform/api/quiche_export.h"
21 #include "quiche/common/platform/api/quiche_logging.h"
22 
23 namespace http2 {
24 
25 class QUICHE_EXPORT HpackBlockDecoder {
26  public:
HpackBlockDecoder(HpackEntryDecoderListener * listener)27   explicit HpackBlockDecoder(HpackEntryDecoderListener* listener)
28       : listener_(listener) {
29     QUICHE_DCHECK_NE(listener_, nullptr);
30   }
~HpackBlockDecoder()31   ~HpackBlockDecoder() {}
32 
33   HpackBlockDecoder(const HpackBlockDecoder&) = delete;
34   HpackBlockDecoder& operator=(const HpackBlockDecoder&) = delete;
35 
36   // Prepares the decoder to start decoding a new HPACK block. Expected
37   // to be called from an implementation of Http2FrameDecoderListener's
38   // OnHeadersStart or OnPushPromiseStart methods.
Reset()39   void Reset() {
40     QUICHE_DVLOG(2) << "HpackBlockDecoder::Reset";
41     before_entry_ = true;
42   }
43 
44   // Decode the fragment of the HPACK block contained in the decode buffer.
45   // Expected to be called from an implementation of Http2FrameDecoderListener's
46   // OnHpackFragment method.
47   DecodeStatus Decode(DecodeBuffer* db);
48 
49   // Is the decoding process between entries (i.e. would the next byte be the
50   // first byte of a new HPACK entry)?
before_entry()51   bool before_entry() const { return before_entry_; }
52 
53   // Return error code after decoding error occurred in HpackEntryDecoder.
error()54   HpackDecodingError error() const { return entry_decoder_.error(); }
55 
56   std::string DebugString() const;
57 
58  private:
59   HpackEntryDecoder entry_decoder_;
60   HpackEntryDecoderListener* const listener_;
61   bool before_entry_ = true;
62 };
63 
64 QUICHE_EXPORT std::ostream& operator<<(std::ostream& out,
65                                        const HpackBlockDecoder& v);
66 
67 }  // namespace http2
68 
69 #endif  // QUICHE_HTTP2_HPACK_DECODER_HPACK_BLOCK_DECODER_H_
70