proxygen
CompressionScheme.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
15 
16 namespace proxygen { namespace compress {
17 
19 
21  public:
23  }
24  virtual ~CompressionScheme() {
25  }
26 
27  /* Parent class for acks */
28  struct Ack {
29  virtual ~Ack() {
30  }
31  };
32 
33  /* Generate an ack for the given sequence number */
34  virtual std::unique_ptr<Ack> getAck(uint16_t seqn) = 0;
35 
36  /* Deliver an ack to the client/encoder */
37  virtual void recvAck(std::unique_ptr<Ack>) = 0;
38 
39  /* Encode the header list.
40  * The simulator sets newPacket if this block should be considered
41  * to start a new packet because of a time gap since the previous.
42  * Returns a pair { must-process-in-order, header block }
43  */
44  virtual std::pair<FrameFlags, std::unique_ptr<folly::IOBuf>> encode(
45  bool newPacket,
46  std::vector<compress::Header> allHeaders,
47  SimStats& stats) = 0;
48 
49  /* Decode the supplied buffer. allowOOO indicates if the server can process
50  * out of order.
51  */
52  virtual void decode(FrameFlags flags,
53  std::unique_ptr<folly::IOBuf> encodedReq,
54  SimStats& stats,
55  SimStreamingCallback& cb) = 0;
56 
57  /* Return the number of times the decoder was head-of-line blocked */
58  virtual uint32_t getHolBlockCount() const = 0;
59 
60  /* Loop callback simulates packet flushing once per loop*/
61  void runLoopCallback() noexcept override;
62 
63  /* List of blocks encoded in the current event loop */
64  using BlockInfo = std::tuple<FrameFlags,
65  bool /*newPacket*/,
66  std::unique_ptr<folly::IOBuf>,
68  std::list<BlockInfo> encodedBlocks;
69 
70  std::list<BlockInfo> packetBlocks;
71 
72  // Running index of how many requests have been compressed with this scheme
73  size_t index{0};
74 
75  // Used for starting new packets.
76  std::chrono::milliseconds prev;
77 
78  size_t packetBytes{0};
79  std::chrono::milliseconds decodeDelay;
80 
81  std::list<uint16_t> packetIndices;
82 
83  private:
85 };
86 
87 }} // namespace proxygen::compress
std::tuple< FrameFlags, bool, std::unique_ptr< folly::IOBuf >, SimStreamingCallback * > BlockInfo
virtual uint32_t getHolBlockCount() const =0
flags
Definition: http_parser.h:127
virtual void recvAck(std::unique_ptr< Ack >)=0
virtual std::pair< FrameFlags, std::unique_ptr< folly::IOBuf > > encode(bool newPacket, std::vector< compress::Header > allHeaders, SimStats &stats)=0
requires E e noexcept(noexcept(s.error(std::move(e))))
virtual std::unique_ptr< Ack > getAck(uint16_t seqn)=0
std::chrono::milliseconds decodeDelay
CompressionScheme(CompressionSimulator *sim)
virtual void decode(FrameFlags flags, std::unique_ptr< folly::IOBuf > encodedReq, SimStats &stats, SimStreamingCallback &cb)=0