proxygen
proxygen::HPACKDecoder Class Reference

#include <HPACKDecoder.h>

Inheritance diagram for proxygen::HPACKDecoder:
proxygen::HPACKDecoderBase proxygen::HPACKContext

Public Member Functions

 HPACKDecoder (uint32_t tableSize=HPACK::kTableSize, uint32_t maxUncompressed=HeaderCodec::kMaxUncompressed)
 
void decodeStreaming (folly::io::Cursor &cursor, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
 
- Public Member Functions inherited from proxygen::HPACKDecoderBase
 HPACKDecoderBase (uint32_t tableSize, uint32_t maxUncompressed)
 
HPACK::DecodeError getError () const
 
bool hasError () const
 
void setHeaderTableMaxSize (uint32_t maxSize)
 
void setMaxUncompressed (uint64_t maxUncompressed)
 
- 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

bool isValid (uint32_t index)
 
uint32_t decodeIndexedHeader (HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 
uint32_t decodeLiteralHeader (HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 
uint32_t decodeHeader (HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 

Additional Inherited Members

- Public Types inherited from proxygen::HPACKDecoderBase
using headers_t = std::vector< HPACKHeader >
 
- Protected Member Functions inherited from proxygen::HPACKDecoderBase
uint32_t emit (const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 
void completeDecode (HeaderCodec::Type type, HPACK::StreamingCallback *streamingCb, uint32_t compressedSize, uint32_t emittedSize)
 
void handleTableSizeUpdate (HPACKDecodeBuffer &dbuf, HeaderTable &table)
 
- 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::HPACKDecoderBase
HPACK::DecodeError err_ {HPACK::DecodeError::NONE}
 
uint32_t maxTableSize_
 
uint64_t maxUncompressed_
 
- Protected Attributes inherited from proxygen::HPACKContext
HeaderTable table_
 

Detailed Description

Definition at line 22 of file HPACKDecoder.h.

Constructor & Destructor Documentation

proxygen::HPACKDecoder::HPACKDecoder ( uint32_t  tableSize = HPACK::kTableSize,
uint32_t  maxUncompressed = HeaderCodec::kMaxUncompressed 
)
inlineexplicit

Definition at line 25 of file HPACKDecoder.h.

References decodeHeader(), decodeIndexedHeader(), decodeLiteralHeader(), decodeStreaming(), isValid(), and uint32_t.

28  : HPACKDecoderBase(tableSize, maxUncompressed),
29  HPACKContext(tableSize) {}
HPACKDecoderBase(uint32_t tableSize, uint32_t maxUncompressed)
HPACKContext(uint32_t tableSize)

Member Function Documentation

uint32_t proxygen::HPACKDecoder::decodeHeader ( HPACKDecodeBuffer dbuf,
HPACK::StreamingCallback streamingCb,
headers_t emitted 
)
private

Definition at line 130 of file HPACKDecoder.cpp.

References decodeIndexedHeader(), decodeLiteralHeader(), proxygen::HPACKDecoderBase::handleTableSizeUpdate(), proxygen::HPACK::INDEX_REF, proxygen::HPACK::LITERAL_INC_INDEX, proxygen::HPACKDecodeBuffer::peek(), proxygen::HPACKContext::table_, proxygen::HPACK::TABLE_SIZE_UPDATE, and uint8_t.

Referenced by decodeStreaming(), and HPACKDecoder().

133  {
134  uint8_t byte = dbuf.peek();
135  if (byte & HPACK::INDEX_REF.code) {
136  return decodeIndexedHeader(dbuf, streamingCb, emitted);
137  } else if (byte & HPACK::LITERAL_INC_INDEX.code) {
138  // else it's fine, fall through to decodeLiteralHeader
139  } else if (byte & HPACK::TABLE_SIZE_UPDATE.code) {
141  return 0;
142  } // else LITERAL
143  // LITERAL_NO_INDEXING or LITERAL_INCR_INDEXING
144  return decodeLiteralHeader(dbuf, streamingCb, emitted);
145 }
const Instruction INDEX_REF
void handleTableSizeUpdate(HPACKDecodeBuffer &dbuf, HeaderTable &table)
uint32_t decodeIndexedHeader(HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
const Instruction TABLE_SIZE_UPDATE
const Instruction LITERAL_INC_INDEX
uint32_t decodeLiteralHeader(HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
uint32_t proxygen::HPACKDecoder::decodeIndexedHeader ( HPACKDecodeBuffer dbuf,
HPACK::StreamingCallback streamingCb,
headers_t emitted 
)
private

Definition at line 101 of file HPACKDecoder.cpp.

References proxygen::HPACKDecodeBuffer::decodeInteger(), proxygen::HPACKDecoderBase::emit(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::HPACKContext::getHeader(), proxygen::HPACK::INDEX_REF, proxygen::HPACK::INVALID_INDEX, isValid(), proxygen::HPACK::NONE, and uint64_t.

Referenced by decodeHeader(), and HPACKDecoder().

104  {
105  uint64_t index;
106  err_ = dbuf.decodeInteger(HPACK::INDEX_REF.prefixLength, index);
108  LOG(ERROR) << "Decode error decoding index err_=" << err_;
109  return 0;
110  }
111  // validate the index
112  if (index == 0 || !isValid(index)) {
113  LOG(ERROR) << "received invalid index: " << index;
115  return 0;
116  }
117 
118  auto& header = getHeader(index);
119  return emit(header, streamingCb, emitted);
120 }
const Instruction INDEX_REF
const HPACKHeader & getHeader(uint32_t index)
uint32_t emit(const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
bool isValid(uint32_t index)
uint32_t proxygen::HPACKDecoder::decodeLiteralHeader ( HPACKDecodeBuffer dbuf,
HPACK::StreamingCallback streamingCb,
headers_t emitted 
)
private

Definition at line 44 of file HPACKDecoder.cpp.

References proxygen::HeaderTable::add(), proxygen::HPACK::Instruction::code, proxygen::HPACKDecodeBuffer::decodeInteger(), proxygen::HPACKDecodeBuffer::decodeLiteral(), proxygen::HPACKDecoderBase::emit(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::HPACKContext::getHeader(), proxygen::HPACK::INVALID_INDEX, isValid(), proxygen::HPACK::LITERAL, proxygen::HPACK::LITERAL_INC_INDEX, folly::gen::move, proxygen::HPACKHeader::name, proxygen::HPACKDecodeBuffer::next(), proxygen::HPACK::NONE, proxygen::HPACKDecodeBuffer::peek(), proxygen::HPACK::Instruction::prefixLength, proxygen::HPACKContext::table_, uint32_t, uint64_t, uint8_t, and proxygen::HPACKHeader::value.

Referenced by decodeHeader(), and HPACKDecoder().

47  {
48  uint8_t byte = dbuf.peek();
49  bool indexing = byte & HPACK::LITERAL_INC_INDEX.code;
50  HPACKHeader header;
51  uint8_t indexMask = 0x3F; // 0011 1111
53  if (!indexing) {
54  // bool neverIndex = byte & HPACK::LITERAL_NEV_INDEX.code;
55  // TODO: we need to emit this flag with the headers
56  indexMask = 0x0F; // 0000 1111
58  }
59  if (byte & indexMask) {
60  uint64_t index;
61  err_ = dbuf.decodeInteger(length, index);
63  LOG(ERROR) << "Decode error decoding index err_=" << err_;
64  return 0;
65  }
66  // validate the index
67  if (!isValid(index)) {
68  LOG(ERROR) << "received invalid index: " << index;
70  return 0;
71  }
72  header.name = getHeader(index).name;
73  } else {
74  // skip current byte
75  dbuf.next();
76  folly::fbstring headerName;
77  err_ = dbuf.decodeLiteral(headerName);
78  header.name = headerName;
80  LOG(ERROR) << "Error decoding header name err_=" << err_;
81  return 0;
82  }
83  }
84  // value
85  err_ = dbuf.decodeLiteral(header.value);
87  LOG(ERROR) << "Error decoding header value name=" << header.name
88  << " err_=" << err_;
89  return 0;
90  }
91 
92  uint32_t emittedSize = emit(header, streamingCb, emitted);
93 
94  if (indexing) {
95  table_.add(std::move(header));
96  }
97 
98  return emittedSize;
99 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const Instruction LITERAL_INC_INDEX
const HPACKHeader & getHeader(uint32_t index)
uint32_t emit(const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
HPACKHeaderName name
Definition: HPACKHeader.h:82
const Instruction LITERAL
bool isValid(uint32_t index)
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33
void proxygen::HPACKDecoder::decodeStreaming ( folly::io::Cursor cursor,
uint32_t  totalBytes,
HPACK::StreamingCallback streamingCb 
)

given a Cursor and a total amount of bytes we can consume from it, decode headers and invoke a callback.

Definition at line 21 of file HPACKDecoder.cpp.

References proxygen::HPACKDecoderBase::completeDecode(), proxygen::HPACKDecodeBuffer::consumedBytes(), decodeHeader(), proxygen::HPACKDecodeBuffer::empty(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::HPACKDecoderBase::hasError(), proxygen::HPACK::HEADERS_TOO_LARGE, proxygen::HeaderCodec::HPACK, proxygen::HPACKDecoderBase::maxUncompressed_, and uint32_t.

Referenced by proxygen::hpack::decode(), proxygen::HPACKCodec::decodeStreaming(), encodeDecode(), and HPACKDecoder().

24  {
25  HPACKDecodeBuffer dbuf(cursor, totalBytes, maxUncompressed_);
26  uint32_t emittedSize = 0;
27 
28  while (!hasError() && !dbuf.empty()) {
29  emittedSize += decodeHeader(dbuf, streamingCb, nullptr);
30 
31  if (emittedSize > maxUncompressed_) {
32  LOG(ERROR) << "exceeded uncompressed size limit of "
33  << maxUncompressed_ << " bytes";
35  break;
36  }
37  emittedSize += 2;
38  }
39 
40  completeDecode(HeaderCodec::Type::HPACK, streamingCb, dbuf.consumedBytes(),
41  emittedSize);
42 }
uint32_t decodeHeader(HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
void completeDecode(HeaderCodec::Type type, HPACK::StreamingCallback *streamingCb, uint32_t compressedSize, uint32_t emittedSize)
bool proxygen::HPACKDecoder::isValid ( uint32_t  index)
private

Definition at line 122 of file HPACKDecoder.cpp.

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

Referenced by decodeIndexedHeader(), decodeLiteralHeader(), and HPACKDecoder().

122  {
123  if (isStatic(index)) {
124  return getStaticTable().isValid(globalToStaticIndex(index));
125  } else {
126  return table_.isValid(globalToDynamicIndex(index));
127  }
128 }
uint32_t globalToStaticIndex(uint32_t index) const
Definition: HPACKContext.h:76
bool isValid(uint32_t index) const
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

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