QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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_ENCODER_STREAM_RECEIVER_H_ |
| 6 | #define QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_ |
| 7 | |
| 8 | #include <cstdint> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_instruction_decoder.h" |
renjietang | b932f95 | 2019-06-28 11:33:11 -0700 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_stream_receiver.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | |
| 16 | namespace quic { |
| 17 | |
| 18 | // This class decodes data received on the encoder stream. |
| 19 | class QUIC_EXPORT_PRIVATE QpackEncoderStreamReceiver |
renjietang | b932f95 | 2019-06-28 11:33:11 -0700 | [diff] [blame] | 20 | : public QpackInstructionDecoder::Delegate, |
| 21 | public QpackStreamReceiver { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | public: |
| 23 | // An interface for handling instructions decoded from the encoder stream, see |
| 24 | // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.2 |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 25 | class QUIC_EXPORT_PRIVATE Delegate { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 26 | public: |
| 27 | virtual ~Delegate() = default; |
| 28 | |
| 29 | // 5.2.1. Insert With Name Reference |
| 30 | virtual void OnInsertWithNameReference(bool is_static, |
| 31 | uint64_t name_index, |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 32 | quiche::QuicheStringPiece value) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | // 5.2.2. Insert Without Name Reference |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 34 | virtual void OnInsertWithoutNameReference( |
| 35 | quiche::QuicheStringPiece name, |
| 36 | quiche::QuicheStringPiece value) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | // 5.2.3. Duplicate |
| 38 | virtual void OnDuplicate(uint64_t index) = 0; |
| 39 | // 5.2.4. Set Dynamic Table Capacity |
| 40 | virtual void OnSetDynamicTableCapacity(uint64_t capacity) = 0; |
| 41 | // Decoding error |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 42 | virtual void OnErrorDetected(quiche::QuicheStringPiece error_message) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | explicit QpackEncoderStreamReceiver(Delegate* delegate); |
| 46 | QpackEncoderStreamReceiver() = delete; |
| 47 | QpackEncoderStreamReceiver(const QpackEncoderStreamReceiver&) = delete; |
| 48 | QpackEncoderStreamReceiver& operator=(const QpackEncoderStreamReceiver&) = |
| 49 | delete; |
| 50 | ~QpackEncoderStreamReceiver() override = default; |
| 51 | |
renjietang | b932f95 | 2019-06-28 11:33:11 -0700 | [diff] [blame] | 52 | // Implements QpackStreamReceiver::Decode(). |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 53 | // Decode data and call appropriate Delegate method after each decoded |
| 54 | // instruction. Once an error occurs, Delegate::OnErrorDetected() is called, |
| 55 | // and all further data is ignored. |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 56 | void Decode(quiche::QuicheStringPiece data) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | |
| 58 | // QpackInstructionDecoder::Delegate implementation. |
| 59 | bool OnInstructionDecoded(const QpackInstruction* instruction) override; |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 60 | void OnError(quiche::QuicheStringPiece error_message) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | QpackInstructionDecoder instruction_decoder_; |
| 64 | Delegate* const delegate_; |
| 65 | |
| 66 | // True if a decoding error has been detected. |
| 67 | bool error_detected_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace quic |
| 71 | |
| 72 | #endif // QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_ |