proxygen
QPACKDecoder.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 
12 #include <folly/io/Cursor.h>
13 #include <folly/io/IOBuf.h>
19 
20 namespace proxygen {
21 
23  public QPACKContext,
24  public folly::DestructorCheck {
25  public:
26  explicit QPACKDecoder(
27  uint32_t tableSize=HPACK::kTableSize,
29  : HPACKDecoderBase(tableSize, maxUncompressed),
30  QPACKContext(tableSize, false /* don't track references */) {}
31 
32  void decodeStreaming(
33  uint64_t streamId,
34  std::unique_ptr<folly::IOBuf> block,
35  uint32_t totalBytes,
36  HPACK::StreamingCallback* streamingCb);
37 
38  HPACK::DecodeError decodeEncoderStream(std::unique_ptr<folly::IOBuf> buf);
39 
40  std::unique_ptr<folly::IOBuf> encodeTableStateSync();
41 
42  std::unique_ptr<folly::IOBuf> encodeHeaderAck(uint64_t streamId) const;
43 
44  std::unique_ptr<folly::IOBuf> encodeCancelStream(uint64_t streamId);
45 
47  return holBlockCount_;
48  }
49 
51  return queuedBytes_;
52  }
53 
54  void setMaxBlocking(uint32_t maxBlocking) {
55  maxBlocking_ = maxBlocking;
56  }
57 
58  private:
59  bool isValid(bool isStatic, uint32_t index, bool aboveBase);
60 
62 
63  void decodeStreamingImpl(uint32_t largestReference,
64  uint32_t consumed,
65  HPACKDecodeBuffer& dbuf,
66  HPACK::StreamingCallback* streamingCb);
67 
69  HPACKDecodeBuffer& dbuf,
70  HPACK::StreamingCallback* streamingCb);
71 
73  HPACKDecodeBuffer& dbuf,
74  uint32_t prefixLength,
75  bool aboveBase,
76  HPACK::StreamingCallback* streamingCb,
77  headers_t* emitted);
78 
80  HPACKDecodeBuffer& dbuf,
81  bool indexing,
82  bool nameIndexed,
83  uint8_t prefixLength,
84  bool aboveBase,
85  HPACK::StreamingCallback* streamingCb);
86 
88 
89  void enqueueHeaderBlock(
90  uint64_t streamId,
91  uint32_t largestReference,
92  uint32_t baseIndex,
93  uint32_t consumed,
94  std::unique_ptr<folly::IOBuf> block,
95  size_t length,
96  HPACK::StreamingCallback* streamingCb);
97 
98  struct PendingBlock {
100  uint64_t sid,
101  uint32_t bi, uint32_t l, uint32_t cons,
102  std::unique_ptr<folly::IOBuf> b,
104  : streamID(sid), baseIndex(bi), length(l), consumed(cons),
105  block(std::move(b)), cb(c)
106  {}
111  std::unique_ptr<folly::IOBuf> block;
113  };
114 
115  // Returns true if this object was destroyed by its callback. Callers
116  // should check the result and immediately return.
117  bool decodeBlock(uint32_t largestReference, const PendingBlock& pending);
118 
119  void drainQueue();
120 
126  std::multimap<uint32_t, PendingBlock> queue_;
127 
128  // This holds the state of a partially decoded literal insert on the control
129  // stream
130  struct Partial {
131  enum { NAME, VALUE } state{NAME};
134  };
137 };
138 
139 }
const uint32_t kTableSize
std::unique_ptr< folly::IOBuf > encodeTableStateSync()
HPACK::DecodeError decodeEncoderStream(std::unique_ptr< folly::IOBuf > buf)
uint32_t decodeLiteralHeaderQ(HPACKDecodeBuffer &dbuf, bool indexing, bool nameIndexed, uint8_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb)
char b
std::vector< HPACKHeader > headers_t
static const uint32_t kMaxUncompressed
Definition: HeaderCodec.h:37
void enqueueHeaderBlock(uint64_t streamId, uint32_t largestReference, uint32_t baseIndex, uint32_t consumed, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *streamingCb)
folly::IOBufQueue ingress_
Definition: QPACKDecoder.h:136
std::multimap< uint32_t, PendingBlock > queue_
Definition: QPACKDecoder.h:126
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
uint32_t decodeHeaderQ(HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
STL namespace.
void decodeEncoderStreamInstruction(HPACKDecodeBuffer &dbuf)
uint32_t decodeIndexedHeaderQ(HPACKDecodeBuffer &dbuf, uint32_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
uint64_t getHolBlockCount() const
Definition: QPACKDecoder.h:46
static Options cacheChainLength()
Definition: IOBufQueue.h:83
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
bool decodeBlock(uint32_t largestReference, const PendingBlock &pending)
bool isValid(bool isStatic, uint32_t index, bool aboveBase)
uint64_t getQueuedBytes() const
Definition: QPACKDecoder.h:50
void setMaxBlocking(uint32_t maxBlocking)
Definition: QPACKDecoder.h:54
std::unique_ptr< folly::IOBuf > block
Definition: QPACKDecoder.h:111
PendingBlock(uint64_t sid, uint32_t bi, uint32_t l, uint32_t cons, std::unique_ptr< folly::IOBuf > b, HPACK::StreamingCallback *c)
Definition: QPACKDecoder.h:99
void decodeStreamingImpl(uint32_t largestReference, uint32_t consumed, HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
std::unique_ptr< folly::IOBuf > encodeHeaderAck(uint64_t streamId) const
uint32_t handleBaseIndex(HPACKDecodeBuffer &dbuf)
QPACKDecoder(uint32_t tableSize=HPACK::kTableSize, uint32_t maxUncompressed=HeaderCodec::kMaxUncompressed)
Definition: QPACKDecoder.h:26
HPACK::StreamingCallback * cb
Definition: QPACKDecoder.h:112
string NAME
Definition: tokenize.py:56
char c
std::unique_ptr< folly::IOBuf > encodeCancelStream(uint64_t streamId)
const uint32_t kDefaultBlocking
state
Definition: http_parser.c:272