proxygen
proxygen::HPACKEncoder Class Reference

#include <HPACKEncoder.h>

Inheritance diagram for proxygen::HPACKEncoder:
proxygen::HPACKEncoderBase proxygen::HPACKContext

Public Member Functions

 HPACKEncoder (bool huffman, uint32_t tableSize=HPACK::kTableSize)
 
std::unique_ptr< folly::IOBufencode (const std::vector< HPACKHeader > &headers, uint32_t headroom=0)
 
void setHeaderTableSize (uint32_t size)
 
- Public Member Functions inherited from proxygen::HPACKEncoderBase
 HPACKEncoderBase (bool huffman)
 
void setHeaderTableSize (HeaderTable &table, uint32_t size)
 
void setHeaderIndexingStrategy (const HeaderIndexingStrategy *indexingStrat)
 
const HeaderIndexingStrategygetHeaderIndexingStrategy () const
 
- Public Member Functions inherited from proxygen::HPACKContext
 HPACKContext (uint32_t tableSize)
 
 ~HPACKContext ()
 
uint32_t getIndex (const HPACKHeader &header) const
 
uint32_t nameIndex (const HPACKHeaderName &headerName) const
 
bool isStatic (uint32_t index) const
 
const HPACKHeadergetHeader (uint32_t index)
 
const HeaderTablegetTable () const
 
uint32_t getTableSize () const
 
uint32_t getBytesStored () const
 
uint32_t getHeadersStored () const
 
void seedHeaderTable (std::vector< HPACKHeader > &headers)
 
void describe (std::ostream &os) const
 

Private Member Functions

void encodeAsIndex (uint32_t index)
 
void encodeHeader (const HPACKHeader &header)
 
bool encodeAsLiteral (const HPACKHeader &header, bool indexing)
 
void encodeLiteral (const HPACKHeader &header, uint32_t nameIndex, const HPACK::Instruction &instruction)
 

Additional Inherited Members

- Static Public Attributes inherited from proxygen::HPACKEncoderBase
static const uint32_t kBufferGrowth = 4000
 
- Protected Member Functions inherited from proxygen::HPACKEncoderBase
void handlePendingContextUpdate (HPACKEncodeBuffer &buf, uint32_t tableCapacity)
 
- Protected Member Functions inherited from proxygen::HPACKContext
const StaticHeaderTablegetStaticTable () const
 
uint32_t globalToDynamicIndex (uint32_t index) const
 
uint32_t globalToStaticIndex (uint32_t index) const
 
uint32_t dynamicToGlobalIndex (uint32_t index) const
 
uint32_t staticToGlobalIndex (uint32_t index) const
 
- Protected Attributes inherited from proxygen::HPACKEncoderBase
const HeaderIndexingStrategyindexingStrat_
 
HPACKEncodeBuffer streamBuffer_
 
bool pendingContextUpdate_ {false}
 
- Protected Attributes inherited from proxygen::HPACKContext
HeaderTable table_
 

Detailed Description

Definition at line 19 of file HPACKEncoder.h.

Constructor & Destructor Documentation

proxygen::HPACKEncoder::HPACKEncoder ( bool  huffman,
uint32_t  tableSize = HPACK::kTableSize 
)
inlineexplicit

Definition at line 22 of file HPACKEncoder.h.

References encode(), and uint32_t.

24  : HPACKEncoderBase(huffman)
25  , HPACKContext(tableSize) {}
HPACKContext(uint32_t tableSize)

Member Function Documentation

std::unique_ptr< folly::IOBuf > proxygen::HPACKEncoder::encode ( const std::vector< HPACKHeader > &  headers,
uint32_t  headroom = 0 
)

Encode the given headers.

Definition at line 17 of file HPACKEncoder.cpp.

References proxygen::HPACKEncodeBuffer::addHeadroom(), proxygen::HeaderTable::capacity(), encodeHeader(), proxygen::HPACKEncoderBase::handlePendingContextUpdate(), proxygen::HPACKEncodeBuffer::release(), proxygen::HPACKEncoderBase::streamBuffer_, and proxygen::HPACKContext::table_.

Referenced by encode(), proxygen::HPACKCodec::encode(), proxygen::hpack::encodeDecode(), HPACKEncoder(), TEST_F(), and TEST_P().

17  {
18  if (headroom) {
19  streamBuffer_.addHeadroom(headroom);
20  }
22  for (const auto& header : headers) {
23  encodeHeader(header);
24  }
25  return streamBuffer_.release();
26 }
uint32_t capacity() const
Definition: HeaderTable.h:86
std::unique_ptr< folly::IOBuf > release()
HPACKEncodeBuffer streamBuffer_
void addHeadroom(uint32_t bytes)
void encodeHeader(const HPACKHeader &header)
void handlePendingContextUpdate(HPACKEncodeBuffer &buf, uint32_t tableCapacity)
void proxygen::HPACKEncoder::encodeAsIndex ( uint32_t  index)
private

Definition at line 63 of file HPACKEncoder.cpp.

References proxygen::HPACKEncodeBuffer::encodeInteger(), proxygen::HPACK::INDEX_REF, and proxygen::HPACKEncoderBase::streamBuffer_.

Referenced by encodeHeader(), and setHeaderTableSize().

63  {
64  VLOG(10) << "encoding index=" << index;
66 }
const Instruction INDEX_REF
HPACKEncodeBuffer streamBuffer_
uint32_t encodeInteger(uint64_t value, uint8_t instruction, uint8_t nbit)
bool proxygen::HPACKEncoder::encodeAsLiteral ( const HPACKHeader header,
bool  indexing 
)
private

Definition at line 28 of file HPACKEncoder.cpp.

References proxygen::HeaderTable::add(), proxygen::HPACKHeader::bytes(), proxygen::HeaderTable::capacity(), proxygen::HPACKHeader::copy(), encodeLiteral(), proxygen::HPACK::LITERAL, proxygen::HPACK::LITERAL_INC_INDEX, proxygen::HPACKHeader::name, proxygen::HPACKContext::nameIndex(), and proxygen::HPACKContext::table_.

Referenced by encodeHeader(), and setHeaderTableSize().

28  {
29  if (header.bytes() > table_.capacity()) {
30  // May want to investigate further whether or not this is wanted.
31  // Flushing the table on a large header frees up some memory,
32  // however, there will be no compression due to an empty table, and
33  // the table will fill up again fairly quickly
34  indexing = false;
35  }
36 
37  HPACK::Instruction instruction = (indexing) ?
39 
40  encodeLiteral(header, nameIndex(header.name), instruction);
41  // indexed ones need to get added to the header table
42  if (indexing) {
43  CHECK(table_.add(header.copy()));
44  }
45  return true;
46 }
uint32_t capacity() const
Definition: HeaderTable.h:86
void encodeLiteral(const HPACKHeader &header, uint32_t nameIndex, const HPACK::Instruction &instruction)
uint32_t nameIndex(const HPACKHeaderName &headerName) const
const Instruction LITERAL_INC_INDEX
const Instruction LITERAL
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33
void proxygen::HPACKEncoder::encodeHeader ( const HPACKHeader header)
private

Definition at line 68 of file HPACKEncoder.cpp.

References encodeAsIndex(), encodeAsLiteral(), proxygen::HPACKContext::getIndex(), proxygen::HeaderIndexingStrategy::indexHeader(), proxygen::HPACKEncoderBase::indexingStrat_, and uint32_t.

Referenced by encode(), and setHeaderTableSize().

68  {
69  // First determine whether the header is defined as indexable using the
70  // set strategy if applicable, else assume it is indexable
71  bool indexable = !indexingStrat_ || indexingStrat_->indexHeader(header);
72 
73  // If the header was not defined as indexable, its a reasonable assumption
74  // that it does not appear in either the static or dynamic table and should
75  // not be searched. The only time this is not true is if the header indexing
76  // strat specified an exact header/value pair that is in the static header
77  // table although semantically the header indexing strategy should indeed act
78  // as an override so we assume this is desired if such a case occurs
79  uint32_t index = 0;
80  if (indexable) {
81  index = getIndex(header);
82  }
83 
84  // Finally encode the header as determined above
85  if (index) {
86  encodeAsIndex(index);
87  } else {
88  encodeAsLiteral(header, indexable);
89  }
90 }
void encodeAsIndex(uint32_t index)
bool encodeAsLiteral(const HPACKHeader &header, bool indexing)
uint32_t getIndex(const HPACKHeader &header) const
virtual bool indexHeader(const HPACKHeader &header) const
const HeaderIndexingStrategy * indexingStrat_
void proxygen::HPACKEncoder::encodeLiteral ( const HPACKHeader header,
uint32_t  nameIndex,
const HPACK::Instruction instruction 
)
private

Definition at line 48 of file HPACKEncoder.cpp.

References proxygen::HPACKEncodeBuffer::encodeInteger(), proxygen::HPACKEncodeBuffer::encodeLiteral(), proxygen::HPACKHeaderName::get(), proxygen::HPACKHeader::name, proxygen::HPACKContext::nameIndex(), proxygen::HPACKEncoderBase::streamBuffer_, and proxygen::HPACKHeader::value.

Referenced by encodeAsLiteral(), and setHeaderTableSize().

50  {
51  // name
52  if (nameIndex) {
53  VLOG(10) << "encoding name index=" << nameIndex;
55  } else {
56  streamBuffer_.encodeInteger(0, instruction);
57  streamBuffer_.encodeLiteral(header.name.get());
58  }
59  // value
60  streamBuffer_.encodeLiteral(header.value);
61 }
uint32_t encodeLiteral(folly::StringPiece literal)
uint32_t nameIndex(const HPACKHeaderName &headerName) const
HPACKEncodeBuffer streamBuffer_
uint32_t encodeInteger(uint64_t value, uint8_t instruction, uint8_t nbit)
void proxygen::HPACKEncoder::setHeaderTableSize ( uint32_t  size)
inline

Definition at line 35 of file HPACKEncoder.h.

References encodeAsIndex(), encodeAsLiteral(), encodeHeader(), encodeLiteral(), proxygen::HPACKContext::nameIndex(), proxygen::HPACKEncoderBase::setHeaderTableSize(), proxygen::HPACKContext::table_, and uint32_t.

Referenced by TEST_P().

35  {
37  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void setHeaderTableSize(HeaderTable &table, uint32_t size)

The documentation for this class was generated from the following files: