proxygen
QPACKCodec.cpp
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  */
11 
12 #include <algorithm>
13 #include <folly/String.h>
14 #include <folly/io/Cursor.h>
15 #include <proxygen/lib/http/codec/compress/HPACKCodec.h> // for prepareHeaders
17 #include <iosfwd>
18 
19 using folly::IOBuf;
20 using folly::io::Cursor;
24 using std::unique_ptr;
25 using std::vector;
26 
27 namespace proxygen {
28 
30  : encoder_(true, HPACK::kTableSize),
31  decoder_(HPACK::kTableSize, maxUncompressed_) {}
32 
34  const QPACKEncoder::EncodeResult& encodeRes) {
36  if (encodeRes.control) {
37  encodedSize_.compressed += encodeRes.control->computeChainDataLength();
38  }
39  if (encodeRes.stream) {
40  encodedSize_.compressed += encodeRes.stream->computeChainDataLength();
41  }
42  if (stats_) {
44  }
45 }
46 
48  vector<Header>& headers, uint64_t streamId) noexcept {
49  auto prepared = compress::prepareHeaders(headers);
50  encodedSize_.uncompressed = prepared.second;
51  auto res = encoder_.encode(prepared.first, encodeHeadroom_, streamId);
53  return res;
54 }
55 
58  std::unique_ptr<folly::IOBuf> block,
59  uint32_t length,
60  HPACK::StreamingCallback* streamingCb) noexcept {
61  if (streamingCb) {
62  streamingCb->stats = stats_;
63  }
64  decoder_.decodeStreaming(streamID, std::move(block), length, streamingCb);
65 }
66 
67 void QPACKCodec::describe(std::ostream& stream) const {
68  stream << "DecoderTable:\n" << decoder_;
69  stream << "EncoderTable:\n" << encoder_;
70 }
71 
72 std::ostream& operator<<(std::ostream& os, const QPACKCodec& codec) {
73  codec.describe(os);
74  return os;
75 }
76 
77 }
const uint32_t kTableSize
void describe(std::ostream &os) const
Definition: QPACKCodec.cpp:67
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
QPACKDecoder decoder_
Definition: QPACKCodec.h:131
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
requires E e noexcept(noexcept(s.error(std::move(e))))
QPACKEncoder::EncodeResult encode(std::vector< compress::Header > &headers, uint64_t id) noexcept
Definition: QPACKCodec.cpp:47
HTTPHeaderSize encodedSize_
Definition: HeaderCodec.h:90
EncodeResult encode(const std::vector< HPACKHeader > &headers, uint32_t headroom, uint64_t streamId)
std::pair< vector< HPACKHeader >, uint32_t > prepareHeaders(vector< Header > &headers)
Definition: HPACKCodec.cpp:29
uint32_t encodeHeadroom_
Definition: HeaderCodec.h:91
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
std::deque< HeaderPiece > HeaderPieceList
Definition: HeaderPiece.h:59
QPACKEncoder encoder_
Definition: QPACKCodec.h:130
virtual void recordEncode(Type type, HTTPHeaderSize &size)=0
void recordCompressedSize(const QPACKEncoder::EncodeResult &encodeRes)
Definition: QPACKCodec.cpp:33
uint32_t streamID
Definition: SPDYCodec.cpp:131
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t length, HPACK::StreamingCallback *streamingCb) noexcept
Definition: QPACKCodec.cpp:56