blob: 61c2773a62e5d7148a43e73e7d0eff70f43d0eb0 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2018 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_QUIC_CORE_QPACK_QPACK_DECODER_STREAM_RECEIVER_H_
6#define QUICHE_QUIC_CORE_QPACK_QPACK_DECODER_STREAM_RECEIVER_H_
7
8#include <cstdint>
9
10#include "net/third_party/quiche/src/quic/core/qpack/qpack_instruction_decoder.h"
11#include "net/third_party/quiche/src/quic/core/quic_types.h"
12#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
14
15namespace quic {
16
17// This class decodes data received on the decoder stream,
18// and passes it along to its Delegate.
19class QUIC_EXPORT_PRIVATE QpackDecoderStreamReceiver
20 : public QpackInstructionDecoder::Delegate {
21 public:
22 // An interface for handling instructions decoded from the decoder stream, see
23 // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.3
24 class Delegate {
25 public:
26 virtual ~Delegate() = default;
27
28 // 5.3.1 Insert Count Increment
29 virtual void OnInsertCountIncrement(uint64_t increment) = 0;
30 // 5.3.2 Header Acknowledgement
31 virtual void OnHeaderAcknowledgement(QuicStreamId stream_id) = 0;
32 // 5.3.3 Stream Cancellation
33 virtual void OnStreamCancellation(QuicStreamId stream_id) = 0;
34 // Decoding error
35 virtual void OnErrorDetected(QuicStringPiece error_message) = 0;
36 };
37
38 explicit QpackDecoderStreamReceiver(Delegate* delegate);
39 QpackDecoderStreamReceiver() = delete;
40 QpackDecoderStreamReceiver(const QpackDecoderStreamReceiver&) = delete;
41 QpackDecoderStreamReceiver& operator=(const QpackDecoderStreamReceiver&) =
42 delete;
43
44 // Decode data and call appropriate Delegate method after each decoded
45 // instruction. Once an error occurs, Delegate::OnErrorDetected() is called,
46 // and all further data is ignored.
47 void Decode(QuicStringPiece data);
48
49 // QpackInstructionDecoder::Delegate implementation.
50 bool OnInstructionDecoded(const QpackInstruction* instruction) override;
51 void OnError(QuicStringPiece error_message) override;
52
53 private:
54 QpackInstructionDecoder instruction_decoder_;
55 Delegate* const delegate_;
56
57 // True if a decoding error has been detected.
58 bool error_detected_;
59};
60
61} // namespace quic
62
63#endif // QUICHE_QUIC_CORE_QPACK_QPACK_DECODER_STREAM_RECEIVER_H_