xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/adapter/data_source.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #ifndef QUICHE_HTTP2_ADAPTER_DATA_SOURCE_H_
2 #define QUICHE_HTTP2_ADAPTER_DATA_SOURCE_H_
3 
4 #include <cstdint>
5 #include <string>
6 #include <utility>
7 
8 #include "absl/strings/string_view.h"
9 #include "quiche/common/platform/api/quiche_export.h"
10 
11 namespace http2 {
12 namespace adapter {
13 
14 // Represents a source of DATA frames for transmission to the peer.
15 class QUICHE_EXPORT DataFrameSource {
16  public:
~DataFrameSource()17   virtual ~DataFrameSource() {}
18 
19   enum : int64_t { kBlocked = 0, kError = -1 };
20 
21   // Returns the number of bytes to send in the next DATA frame, and whether
22   // this frame indicates the end of the data. Returns {kBlocked, false} if
23   // blocked, {kError, false} on error.
24   virtual std::pair<int64_t, bool> SelectPayloadLength(size_t max_length) = 0;
25 
26   // This method is called with a frame header and a payload length to send. The
27   // source should send or buffer the entire frame and return true, or return
28   // false without sending or buffering anything.
29   virtual bool Send(absl::string_view frame_header, size_t payload_length) = 0;
30 
31   // If true, the end of this data source indicates the end of the stream.
32   // Otherwise, this data will be followed by trailers.
33   virtual bool send_fin() const = 0;
34 };
35 
36 // Represents a source of metadata frames for transmission to the peer.
37 class QUICHE_EXPORT MetadataSource {
38  public:
~MetadataSource()39   virtual ~MetadataSource() {}
40 
41   // Returns the number of frames of at most |max_frame_size| required to
42   // serialize the metadata for this source. Only required by the nghttp2
43   // implementation.
44   virtual size_t NumFrames(size_t max_frame_size) const = 0;
45 
46   // This method is called with a destination buffer and length. It should
47   // return the number of payload bytes copied to |dest|, or a negative integer
48   // to indicate an error, as well as a boolean indicating whether the metadata
49   // has been completely copied.
50   virtual std::pair<int64_t, bool> Pack(uint8_t* dest, size_t dest_len) = 0;
51 
52   // This method is called when transmission of the metadata for this source
53   // fails in a non-recoverable way.
54   virtual void OnFailure() = 0;
55 };
56 
57 }  // namespace adapter
58 }  // namespace http2
59 
60 #endif  // QUICHE_HTTP2_ADAPTER_DATA_SOURCE_H_
61