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_SENDER_H_ 6 #define QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_SENDER_H_ 7 8 #include <cstdint> 9 10 #include "absl/strings/string_view.h" 11 #include "quiche/quic/core/qpack/qpack_instruction_encoder.h" 12 #include "quiche/quic/core/qpack/qpack_stream_sender_delegate.h" 13 #include "quiche/quic/core/quic_types.h" 14 #include "quiche/quic/platform/api/quic_export.h" 15 16 namespace quic { 17 18 // This class serializes instructions for transmission on the encoder stream. 19 // Serialized instructions are buffered until Flush() is called. 20 class QUICHE_EXPORT QpackEncoderStreamSender { 21 public: 22 QpackEncoderStreamSender(HuffmanEncoding huffman_encoding); 23 QpackEncoderStreamSender(const QpackEncoderStreamSender&) = delete; 24 QpackEncoderStreamSender& operator=(const QpackEncoderStreamSender&) = delete; 25 26 // Methods for serializing and buffering instructions, see 27 // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.2 28 29 // 5.2.1. Insert With Name Reference 30 void SendInsertWithNameReference(bool is_static, uint64_t name_index, 31 absl::string_view value); 32 // 5.2.2. Insert Without Name Reference 33 void SendInsertWithoutNameReference(absl::string_view name, 34 absl::string_view value); 35 // 5.2.3. Duplicate 36 void SendDuplicate(uint64_t index); 37 // 5.2.4. Set Dynamic Table Capacity 38 void SendSetDynamicTableCapacity(uint64_t capacity); 39 40 // Returns number of bytes buffered by this object. 41 // There is no limit on how much data this object is willing to buffer. BufferedByteCount()42 QuicByteCount BufferedByteCount() const { return buffer_.size(); } 43 44 // Returns whether writing to the encoder stream is allowed. Writing is 45 // disallowed if the amount of data buffered by the underlying stream exceeds 46 // a hardcoded limit, in order to limit memory consumption in case the encoder 47 // stream is blocked. CanWrite() returning true does not mean that the 48 // encoder stream is not blocked, it just means the blocked data does not 49 // exceed the threshold. 50 bool CanWrite() const; 51 52 // Writes all buffered instructions on the encoder stream. 53 void Flush(); 54 55 // delegate must be set if dynamic table capacity is not zero. set_qpack_stream_sender_delegate(QpackStreamSenderDelegate * delegate)56 void set_qpack_stream_sender_delegate(QpackStreamSenderDelegate* delegate) { 57 delegate_ = delegate; 58 } 59 60 private: 61 QpackStreamSenderDelegate* delegate_; 62 QpackInstructionEncoder instruction_encoder_; 63 std::string buffer_; 64 }; 65 66 } // namespace quic 67 68 #endif // QUICHE_QUIC_CORE_QPACK_QPACK_ENCODER_STREAM_SENDER_H_ 69