proxygen
HPACKCodec.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 <memory>
19 #include <string>
20 #include <vector>
21 
22 namespace folly { namespace io {
23 class Cursor;
24 }}
25 
26 namespace proxygen {
27 
28 class HPACKHeader;
29 
30 namespace compress {
31 std::pair<std::vector<HPACKHeader>, uint32_t> prepareHeaders(
32  std::vector<Header>& headers);
33 }
34 
35 /*
36  * Current version of the wire protocol. When we're making changes to the wire
37  * protocol we need to change this version and the NPN string so that old
38  * clients will not be able to negotiate it anymore.
39  */
40 
41 class HPACKCodec : public HeaderCodec {
42  public:
43  explicit HPACKCodec(TransportDirection direction);
44  ~HPACKCodec() override {}
45 
46  std::unique_ptr<folly::IOBuf> encode(
47  std::vector<compress::Header>& headers) noexcept;
48 
49  void decodeStreaming(
50  folly::io::Cursor& cursor,
51  uint32_t length,
52  HPACK::StreamingCallback* streamingCb) noexcept;
53 
55  encoder_.setHeaderTableSize(size);
56  }
57 
59  decoder_.setHeaderTableMaxSize(size);
60  }
61 
62  void describe(std::ostream& os) const;
63 
64  void setMaxUncompressed(uint64_t maxUncompressed) override {
65  HeaderCodec::setMaxUncompressed(maxUncompressed);
66  decoder_.setMaxUncompressed(maxUncompressed);
67  }
68 
70  return HPACKTableInfo(encoder_.getTableSize(),
71  encoder_.getBytesStored(),
72  encoder_.getHeadersStored(),
73  decoder_.getTableSize(),
74  decoder_.getBytesStored(),
75  decoder_.getHeadersStored());
76  }
77 
79  encoder_.setHeaderIndexingStrategy(indexingStrat);
80  }
82  return encoder_.getHeaderIndexingStrategy();
83  }
84 
85  protected:
88 
89  private:
90  void recordCompressedSize(const folly::IOBuf* buf);
91 
92  std::vector<HPACKHeader> decodedHeaders_;
93 };
94 
95 std::ostream& operator<<(std::ostream& os, const HPACKCodec& codec);
96 }
void setDecoderHeaderTableMaxSize(uint32_t size)
Definition: HPACKCodec.h:58
unique_ptr< IOBuf > encode(vector< HPACKHeader > &headers, HPACKEncoder &encoder)
void setEncoderHeaderTableSize(uint32_t size)
Definition: HPACKCodec.h:54
HPACKEncoder encoder_
Definition: HPACKCodec.h:86
CodecFactory codec
~HPACKCodec() override
Definition: HPACKCodec.h:44
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::vector< HPACKHeader > decodedHeaders_
Definition: HPACKCodec.h:92
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: HPACKCodec.h:81
requires E e noexcept(noexcept(s.error(std::move(e))))
HPACKDecoder decoder_
Definition: HPACKCodec.h:87
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
std::pair< vector< HPACKHeader >, uint32_t > prepareHeaders(vector< Header > &headers)
Definition: HPACKCodec.cpp:29
void setHeaderIndexingStrategy(const HeaderIndexingStrategy *indexingStrat)
Definition: HPACKCodec.h:78
HPACKTableInfo getHPACKTableInfo() const
Definition: HPACKCodec.h:69
void setMaxUncompressed(uint64_t maxUncompressed) override
Definition: HPACKCodec.h:64
std::ostream & operator<<(std::ostream &out, dynamic const &d)
Definition: dynamic-inl.h:1158