proxygen
proxygen::HPACKContext Class Reference

#include <HPACKContext.h>

Inheritance diagram for proxygen::HPACKContext:
proxygen::HPACKDecoder proxygen::HPACKEncoder TestContext

Public Member Functions

 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
 

Protected Member Functions

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

HeaderTable table_
 

Detailed Description

Definition at line 18 of file HPACKContext.h.

Constructor & Destructor Documentation

proxygen::HPACKContext::HPACKContext ( uint32_t  tableSize)
explicit

Definition at line 14 of file HPACKContext.cpp.

14  :
15  table_(tableSize) {
16 }
proxygen::HPACKContext::~HPACKContext ( )
inline

Definition at line 21 of file HPACKContext.h.

References getHeader(), getIndex(), isStatic(), nameIndex(), and uint32_t.

21 {}

Member Function Documentation

void proxygen::HPACKContext::describe ( std::ostream &  os) const

Definition at line 82 of file HPACKContext.cpp.

References table_.

Referenced by getHeadersStored(), and proxygen::operator<<().

82  {
83  os << table_;
84 }
uint32_t proxygen::HPACKContext::dynamicToGlobalIndex ( uint32_t  index) const
inlineprotected

Definition at line 79 of file HPACKContext.h.

References getStaticTable(), and proxygen::HeaderTable::size().

Referenced by getIndex(), and nameIndex().

79  {
80  return index + getStaticTable().size();
81  }
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t proxygen::HPACKContext::getBytesStored ( ) const
inline

Definition at line 56 of file HPACKContext.h.

References proxygen::HeaderTable::bytes(), and table_.

56  {
57  return table_.bytes();
58  }
uint32_t bytes() const
Definition: HeaderTable.h:112
const HPACKHeader & proxygen::HPACKContext::getHeader ( uint32_t  index)
Returns
header at the given index by composing dynamic and static tables

Definition at line 68 of file HPACKContext.cpp.

References proxygen::HeaderTable::getHeader(), getStaticTable(), globalToDynamicIndex(), globalToStaticIndex(), isStatic(), and table_.

Referenced by proxygen::HPACKDecoder::decodeIndexedHeader(), proxygen::HPACKDecoder::decodeLiteralHeader(), TEST_F(), TEST_P(), and ~HPACKContext().

68  {
69  if (isStatic(index)) {
71  }
72  return table_.getHeader(globalToDynamicIndex(index));
73 }
uint32_t globalToStaticIndex(uint32_t index) const
Definition: HPACKContext.h:76
const HPACKHeader & getHeader(uint32_t index) const
Definition: HeaderTable.cpp:93
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
bool isStatic(uint32_t index) const
uint32_t globalToDynamicIndex(uint32_t index) const
Definition: HPACKContext.h:73
uint32_t proxygen::HPACKContext::getHeadersStored ( ) const
inline

Definition at line 60 of file HPACKContext.h.

References describe(), seedHeaderTable(), proxygen::HeaderTable::size(), and table_.

60  {
61  return table_.size();
62  }
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t proxygen::HPACKContext::getIndex ( const HPACKHeader header) const

get the index of the given header by looking into both dynamic and static header table

Returns
0 if cannot be found

Definition at line 18 of file HPACKContext.cpp.

References dynamicToGlobalIndex(), folly::basic_fbstring< E, T, A, Storage >::empty(), proxygen::HPACKHeaderName::getHeaderCode(), proxygen::HeaderTable::getIndex(), getStaticTable(), proxygen::HPACKHeaderName::isCommonHeader(), proxygen::StaticHeaderTable::isHeaderCodeInTableWithNonEmptyValue(), proxygen::HPACKHeader::name, staticToGlobalIndex(), table_, uint32_t, and proxygen::HPACKHeader::value.

Referenced by proxygen::HPACKEncoder::encodeHeader(), TEST_F(), and ~HPACKContext().

18  {
19  // First consult the static header table if applicable
20  // Applicability is determined by the following guided optimizations:
21  // 1) The set of CommonHeaders includes all StaticTable headers and so we can
22  // quickly conclude that we need not check the StaticTable
23  // for non-CommonHeaders
24  // 2) The StaticTable only contains non empty values for a very small subset
25  // of header names. As getIndex is only meaingful if both name and value
26  // match, we know that if our header has a value and is not part of the very
27  // small subset of header names, there is no point consulting the StaticTable
28  bool consultStaticTable = false;
29  if (header.value.empty()) {
30  consultStaticTable = header.name.isCommonHeader();
31  } else {
32  consultStaticTable =
34  header.name.getHeaderCode());
35  }
36  if (consultStaticTable) {
37  uint32_t staticIndex = getStaticTable().getIndex(header);
38  if (staticIndex) {
39  return staticToGlobalIndex(staticIndex);
40  }
41  }
42 
43  // Else check the dynamic table
44  uint32_t dynamicIndex = table_.getIndex(header);
45  if (dynamicIndex) {
46  return dynamicToGlobalIndex(dynamicIndex);
47  } else {
48  return dynamicIndex;
49  }
50 }
static bool isHeaderCodeInTableWithNonEmptyValue(HTTPHeaderCode headerCode)
uint32_t staticToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:82
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
uint32_t getIndex(const HPACKHeader &header) const
Definition: HeaderTable.cpp:63
uint32_t dynamicToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:79
const StaticHeaderTable& proxygen::HPACKContext::getStaticTable ( ) const
inlineprotected
const HeaderTable& proxygen::HPACKContext::getTable ( ) const
inline

Definition at line 48 of file HPACKContext.h.

References table_.

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

48  {
49  return table_;
50  }
uint32_t proxygen::HPACKContext::getTableSize ( ) const
inline

Definition at line 52 of file HPACKContext.h.

References proxygen::HeaderTable::capacity(), and table_.

52  {
53  return table_.capacity();
54  }
uint32_t capacity() const
Definition: HeaderTable.h:86
uint32_t proxygen::HPACKContext::globalToDynamicIndex ( uint32_t  index) const
inlineprotected

Definition at line 73 of file HPACKContext.h.

References getStaticTable(), and proxygen::HeaderTable::size().

Referenced by getHeader(), and proxygen::HPACKDecoder::isValid().

73  {
74  return index - getStaticTable().size();
75  }
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t proxygen::HPACKContext::globalToStaticIndex ( uint32_t  index) const
inlineprotected

Definition at line 76 of file HPACKContext.h.

Referenced by getHeader(), and proxygen::HPACKDecoder::isValid().

76  {
77  return index;
78  }
bool proxygen::HPACKContext::isStatic ( uint32_t  index) const
Returns
true if the given index points to a static header entry

Definition at line 64 of file HPACKContext.cpp.

References getStaticTable(), and proxygen::HeaderTable::size().

Referenced by getHeader(), proxygen::HPACKDecoder::isValid(), TEST_F(), and ~HPACKContext().

64  {
65  return index <= getStaticTable().size();
66 }
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t proxygen::HPACKContext::nameIndex ( const HPACKHeaderName headerName) const

index of a header entry with the given name from dynamic or static table

Returns
0 if name not found

Definition at line 52 of file HPACKContext.cpp.

References dynamicToGlobalIndex(), getStaticTable(), proxygen::HeaderTable::nameIndex(), staticToGlobalIndex(), table_, and uint32_t.

Referenced by proxygen::HPACKEncoder::encodeAsLiteral(), proxygen::HPACKEncoder::encodeLiteral(), proxygen::HPACKEncoder::setHeaderTableSize(), and ~HPACKContext().

52  {
53  uint32_t index = getStaticTable().nameIndex(headerName);
54  if (index) {
55  return staticToGlobalIndex(index);
56  }
57  index = table_.nameIndex(headerName);
58  if (index) {
59  return dynamicToGlobalIndex(index);
60  }
61  return 0;
62 }
uint32_t staticToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:82
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
uint32_t nameIndex(const HPACKHeaderName &headerName) const
Definition: HeaderTable.cpp:88
uint32_t dynamicToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:79
void proxygen::HPACKContext::seedHeaderTable ( std::vector< HPACKHeader > &  headers)

Definition at line 75 of file HPACKContext.cpp.

References proxygen::HeaderTable::add(), folly::gen::move, and table_.

Referenced by getHeadersStored().

76  {
77  for (auto& header: headers) {
78  table_.add(std::move(header));
79  }
80 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33
uint32_t proxygen::HPACKContext::staticToGlobalIndex ( uint32_t  index) const
inlineprotected

Definition at line 82 of file HPACKContext.h.

Referenced by getIndex(), and nameIndex().

82  {
83  return index;
84  }

Member Data Documentation


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