xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/qpack/qpack_decoder_stream_receiver.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // 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 "absl/strings/string_view.h"
11 #include "quiche/quic/core/qpack/qpack_instruction_decoder.h"
12 #include "quiche/quic/core/qpack/qpack_stream_receiver.h"
13 #include "quiche/quic/core/quic_error_codes.h"
14 #include "quiche/quic/core/quic_types.h"
15 #include "quiche/quic/platform/api/quic_export.h"
16 
17 namespace quic {
18 
19 // This class decodes data received on the decoder stream,
20 // and passes it along to its Delegate.
21 class QUICHE_EXPORT QpackDecoderStreamReceiver
22     : public QpackInstructionDecoder::Delegate,
23       public QpackStreamReceiver {
24  public:
25   // An interface for handling instructions decoded from the decoder stream, see
26   // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.3
27   class QUICHE_EXPORT Delegate {
28    public:
29     virtual ~Delegate() = default;
30 
31     // 5.3.1 Insert Count Increment
32     virtual void OnInsertCountIncrement(uint64_t increment) = 0;
33     // 5.3.2 Header Acknowledgement
34     virtual void OnHeaderAcknowledgement(QuicStreamId stream_id) = 0;
35     // 5.3.3 Stream Cancellation
36     virtual void OnStreamCancellation(QuicStreamId stream_id) = 0;
37     // Decoding error
38     virtual void OnErrorDetected(QuicErrorCode error_code,
39                                  absl::string_view error_message) = 0;
40   };
41 
42   explicit QpackDecoderStreamReceiver(Delegate* delegate);
43   QpackDecoderStreamReceiver() = delete;
44   QpackDecoderStreamReceiver(const QpackDecoderStreamReceiver&) = delete;
45   QpackDecoderStreamReceiver& operator=(const QpackDecoderStreamReceiver&) =
46       delete;
47 
48   // Implements QpackStreamReceiver::Decode().
49   // Decode data and call appropriate Delegate method after each decoded
50   // instruction.  Once an error occurs, Delegate::OnErrorDetected() is called,
51   // and all further data is ignored.
52   void Decode(absl::string_view data) override;
53 
54   // QpackInstructionDecoder::Delegate implementation.
55   bool OnInstructionDecoded(const QpackInstruction* instruction) override;
56   void OnInstructionDecodingError(QpackInstructionDecoder::ErrorCode error_code,
57                                   absl::string_view error_message) override;
58 
59  private:
60   QpackInstructionDecoder instruction_decoder_;
61   Delegate* const delegate_;
62 
63   // True if a decoding error has been detected.
64   bool error_detected_;
65 };
66 
67 }  // namespace quic
68 
69 #endif  // QUICHE_QUIC_CORE_QPACK_QPACK_DECODER_STREAM_RECEIVER_H_
70