blob: a17664f8ded243321f2781dba1f3e3b01ce15445 [file] [log] [blame]
QUICHE teamfd50a402018-12-07 22:54:05 -05001// 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
QUICHE teamfd50a402018-12-07 22:54:05 -050013#include "net/third_party/quiche/src/http2/decoder/decode_buffer.h"
14#include "net/third_party/quiche/src/http2/decoder/decode_status.h"
15#include "net/third_party/quiche/src/http2/hpack/decoder/hpack_entry_decoder.h"
16#include "net/third_party/quiche/src/http2/hpack/decoder/hpack_entry_decoder_listener.h"
17#include "net/third_party/quiche/src/http2/platform/api/http2_export.h"
QUICHE team61940b42019-03-07 23:32:27 -050018#include "net/third_party/quiche/src/http2/platform/api/http2_logging.h"
QUICHE teamfd50a402018-12-07 22:54:05 -050019#include "net/third_party/quiche/src/http2/platform/api/http2_string.h"
20
21namespace http2 {
22
23class HTTP2_EXPORT_PRIVATE HpackBlockDecoder {
24 public:
25 explicit HpackBlockDecoder(HpackEntryDecoderListener* listener)
26 : listener_(listener) {
27 DCHECK_NE(listener_, nullptr);
28 }
29 ~HpackBlockDecoder() {}
30
31 HpackBlockDecoder(const HpackBlockDecoder&) = delete;
32 HpackBlockDecoder& operator=(const HpackBlockDecoder&) = delete;
33
34 // Prepares the decoder to start decoding a new HPACK block. Expected
35 // to be called from an implementation of Http2FrameDecoderListener's
36 // OnHeadersStart or OnPushPromiseStart methods.
37 void Reset() {
QUICHE team61940b42019-03-07 23:32:27 -050038 HTTP2_DVLOG(2) << "HpackBlockDecoder::Reset";
QUICHE teamfd50a402018-12-07 22:54:05 -050039 before_entry_ = true;
40 }
41
42 // Decode the fragment of the HPACK block contained in the decode buffer.
43 // Expected to be called from an implementation of Http2FrameDecoderListener's
44 // OnHpackFragment method.
45 DecodeStatus Decode(DecodeBuffer* db);
46
47 // Is the decoding process between entries (i.e. would the next byte be the
48 // first byte of a new HPACK entry)?
49 bool before_entry() const { return before_entry_; }
50
51 Http2String DebugString() const;
52
53 private:
54 HpackEntryDecoder entry_decoder_;
55 HpackEntryDecoderListener* const listener_;
56 bool before_entry_ = true;
57};
58
59HTTP2_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& out,
60 const HpackBlockDecoder& v);
61
62} // namespace http2
63
64#endif // QUICHE_HTTP2_HPACK_DECODER_HPACK_BLOCK_DECODER_H_