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> 9 #include <string> 10 11 #include "absl/strings/string_view.h" 12 #include "quiche/quic/core/qpack/qpack_instruction_decoder.h" 13 #include "quiche/quic/core/qpack/qpack_stream_receiver.h" 14 #include "quiche/quic/core/quic_error_codes.h" 15 #include "quiche/quic/platform/api/quic_export.h" 16 17 namespace quic { 18 19 // This class decodes data received on the encoder stream. 20 class QUICHE_EXPORT QpackEncoderStreamReceiver 21 : public QpackInstructionDecoder::Delegate, 22 public QpackStreamReceiver { 23 public: 24 // An interface for handling instructions decoded from the encoder stream, see 25 // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.2 26 class QUICHE_EXPORT Delegate { 27 public: 28 virtual ~Delegate() = default; 29 30 // 5.2.1. Insert With Name Reference 31 virtual void OnInsertWithNameReference(bool is_static, uint64_t name_index, 32 absl::string_view value) = 0; 33 // 5.2.2. Insert Without Name Reference 34 virtual void OnInsertWithoutNameReference(absl::string_view name, 35 absl::string_view value) = 0; 36 // 5.2.3. Duplicate 37 virtual void OnDuplicate(uint64_t index) = 0; 38 // 5.2.4. Set Dynamic Table Capacity 39 virtual void OnSetDynamicTableCapacity(uint64_t capacity) = 0; 40 // Decoding error 41 virtual void OnErrorDetected(QuicErrorCode error_code, 42 absl::string_view error_message) = 0; 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 52 // Implements QpackStreamReceiver::Decode(). 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. 56 void Decode(absl::string_view data) override; 57 58 // QpackInstructionDecoder::Delegate implementation. 59 bool OnInstructionDecoded(const QpackInstruction* instruction) override; 60 void OnInstructionDecodingError(QpackInstructionDecoder::ErrorCode error_code, 61 absl::string_view error_message) override; 62 63 private: 64 QpackInstructionDecoder instruction_decoder_; 65 Delegate* const delegate_; 66 67 // True if a decoding error has been detected. 68 bool error_detected_; 69 }; 70 71 } // namespace quic 72 73 #endif // QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_RECEIVER_H_ 74