1 #ifndef QUICHE_BALSA_BALSA_HEADERS_SEQUENCE_H_ 2 #define QUICHE_BALSA_BALSA_HEADERS_SEQUENCE_H_ 3 4 #include <cstddef> 5 #include <memory> 6 7 #include "absl/container/inlined_vector.h" 8 #include "quiche/balsa/balsa_headers.h" 9 #include "quiche/common/platform/api/quiche_export.h" 10 11 namespace quiche { 12 13 // Represents a sequence of BalsaHeaders. The sequence owns each BalsaHeaders, 14 // and the user asks for pointers to successive BalsaHeaders in the sequence. 15 class QUICHE_EXPORT BalsaHeadersSequence { 16 public: 17 // Appends `headers` to the end of the sequence. 18 void Append(std::unique_ptr<BalsaHeaders> headers); 19 20 // Returns true if there is a BalsaHeaders that has not yet been returned from 21 // `Next()`. IFF true, `Next()` will return non-nullptr. 22 bool HasNext() const; 23 24 // Returns true if the sequence has no BalsaHeaders. It is possible to have 25 // both !HasNext() and !IsEmpty() if all BalsaHeaders have been consumed. IsEmpty()26 bool IsEmpty() const { return sequence_.empty(); } 27 28 // Returns a non-owning pointer to the next BalsaHeaders in the sequence, or 29 // nullptr if the next does not exist. 30 BalsaHeaders* Next(); 31 32 // Similar to `Next()` but does not advance the sequence. 33 // TODO(b/68801833): Consider removing after full refactoring is in place. 34 BalsaHeaders* PeekNext(); 35 36 // Clears the sequence. Any previously returned BalsaHeaders become invalid. 37 void Clear(); 38 39 private: 40 // Typically at most two interim responses: an optional 100 Continue and an 41 // optional 103 Early Hints. 42 absl::InlinedVector<std::unique_ptr<BalsaHeaders>, 2> sequence_; 43 44 // The index of the next entry in the sequence. 45 size_t next_ = 0; 46 }; 47 48 } // namespace quiche 49 50 #endif // QUICHE_BALSA_BALSA_HEADERS_SEQUENCE_H_ 51