proxygen
proxygen::StructuredHeadersDecoder Class Reference

#include <StructuredHeadersDecoder.h>

Public Member Functions

 StructuredHeadersDecoder (const std::string &s)
 
StructuredHeaders::DecodeError decodeItem (StructuredHeaderItem &result)
 
StructuredHeaders::DecodeError decodeList (std::vector< StructuredHeaderItem > &result)
 
StructuredHeaders::DecodeError decodeDictionary (Dictionary &result)
 
StructuredHeaders::DecodeError decodeParameterisedList (ParameterisedList &result)
 

Private Types

enum  MapType { MapType::DICTIONARY = 0, MapType::PARAMETERISED_MAP = 1 }
 

Private Member Functions

StructuredHeaders::DecodeError decodeMap (std::unordered_map< std::string, StructuredHeaderItem > &result, MapType mapType)
 

Private Attributes

StructuredHeadersBuffer buf_
 

Detailed Description

Definition at line 18 of file StructuredHeadersDecoder.h.

Member Enumeration Documentation

Enumerator
DICTIONARY 
PARAMETERISED_MAP 

Definition at line 34 of file StructuredHeadersDecoder.h.

34  {
35  DICTIONARY = 0,
36  PARAMETERISED_MAP = 1
37  };

Constructor & Destructor Documentation

proxygen::StructuredHeadersDecoder::StructuredHeadersDecoder ( const std::string s)
inlineexplicit

Definition at line 21 of file StructuredHeadersDecoder.h.

References decodeDictionary(), decodeItem(), decodeList(), and decodeParameterisedList().

21 : buf_(s) {}
static set< string > s

Member Function Documentation

DecodeError proxygen::StructuredHeadersDecoder::decodeDictionary ( Dictionary result)

Definition at line 61 of file StructuredHeadersDecoder.cpp.

Referenced by StructuredHeadersDecoder(), and proxygen::TEST_F().

61  {
62  return decodeMap(result, MapType::DICTIONARY);
63 }
StructuredHeaders::DecodeError decodeMap(std::unordered_map< std::string, StructuredHeaderItem > &result, MapType mapType)
DecodeError proxygen::StructuredHeadersDecoder::decodeItem ( StructuredHeaderItem result)

Definition at line 17 of file StructuredHeadersDecoder.cpp.

References proxygen::StructuredHeaders::INVALID_CHARACTER, and proxygen::StructuredHeaders::OK.

Referenced by StructuredHeadersDecoder(), proxygen::TEST_F(), and proxygen::TEST_P().

18  {
19  auto err = buf_.parseItem(result);
20  if (err != DecodeError::OK) {
21  return err;
22  }
23  return buf_.isEmpty() ?
24  DecodeError::OK : buf_.handleDecodeError(DecodeError::INVALID_CHARACTER);
25 }
StructuredHeaders::DecodeError parseItem(StructuredHeaderItem &result)
DecodeError handleDecodeError(const DecodeError &err)
DecodeError proxygen::StructuredHeadersDecoder::decodeList ( std::vector< StructuredHeaderItem > &  result)

Definition at line 27 of file StructuredHeadersDecoder.cpp.

References proxygen::StructuredHeaders::OK, and proxygen::StructuredHeaders::UNEXPECTED_END_OF_BUFFER.

Referenced by StructuredHeadersDecoder(), proxygen::TEST_F(), and proxygen::TEST_P().

28  {
29 
30  while (!buf_.isEmpty()) {
31 
32  StructuredHeaderItem item;
33  auto err = buf_.parseItem(item);
34  if (err != DecodeError::OK) {
35  return err;
36  }
37 
38  result.push_back(item);
39 
41 
42  if (buf_.isEmpty()) {
43  return DecodeError::OK;
44  }
45 
46  err = buf_.removeSymbol(",", true);
47  if (err != DecodeError::OK) {
48  return err;
49  }
50 
52 
53  if (buf_.isEmpty()) {
54  return buf_.handleDecodeError(DecodeError::UNEXPECTED_END_OF_BUFFER);
55  }
56  }
57 
58  return buf_.handleDecodeError(DecodeError::UNEXPECTED_END_OF_BUFFER);
59 }
DecodeError removeSymbol(const std::string &symbol, bool strict)
StructuredHeaders::DecodeError parseItem(StructuredHeaderItem &result)
DecodeError handleDecodeError(const DecodeError &err)
DecodeError proxygen::StructuredHeadersDecoder::decodeMap ( std::unordered_map< std::string, StructuredHeaderItem > &  result,
MapType  mapType 
)
private

Definition at line 103 of file StructuredHeadersDecoder.cpp.

References proxygen::StructuredHeaders::DUPLICATE_KEY, proxygen::StructuredHeaders::StructuredHeaderItem::NONE, proxygen::StructuredHeaders::OK, string, proxygen::StructuredHeaders::StructuredHeaderItem::tag, proxygen::StructuredHeaders::UNEXPECTED_END_OF_BUFFER, and value.

105  {
106 
107  std::string delimiter = (mapType == MapType::PARAMETERISED_MAP) ? ";" : ",";
108 
110 
111  if ((mapType == MapType::PARAMETERISED_MAP) &&
112  (buf_.removeSymbol(delimiter, false) != DecodeError::OK)) {
113  return DecodeError::OK;
114  }
115 
116  while (!buf_.isEmpty()) {
117 
119 
120  std::string thisKey;
121  auto err = buf_.parseIdentifier(thisKey);
122  if (err != DecodeError::OK) {
123  return err;
124  }
125 
126  if (result.find(thisKey) != result.end()) {
127  return buf_.handleDecodeError(DecodeError::DUPLICATE_KEY);
128  }
129 
130  err = buf_.removeSymbol("=", mapType == MapType::DICTIONARY);
131  if (err != DecodeError::OK) {
132  if (mapType == MapType::DICTIONARY) {
133  return err;
134  } else {
135  StructuredHeaderItem value;
136  value.tag = StructuredHeaderItem::Type::NONE;
137  result[thisKey] = value;
138  }
139  } else {
140  StructuredHeaderItem value;
141  err = buf_.parseItem(value);
142  if (err != DecodeError::OK) {
143  return err;
144  }
145 
146  result[thisKey] = value;
147  }
148 
150 
151  if (buf_.isEmpty()) {
152  return DecodeError::OK;
153  }
154 
155  err = buf_.removeSymbol(delimiter, mapType == MapType::DICTIONARY);
156  if (err != DecodeError::OK) {
157  if (mapType == MapType::PARAMETERISED_MAP) {
158  return DecodeError::OK;
159  } else {
160  return err;
161  }
162  }
163  }
164 
165  return buf_.handleDecodeError(DecodeError::UNEXPECTED_END_OF_BUFFER);
166 
167 }
DecodeError removeSymbol(const std::string &symbol, bool strict)
StructuredHeaders::DecodeError parseItem(StructuredHeaderItem &result)
static const char *const value
Definition: Conv.cpp:50
DecodeError handleDecodeError(const DecodeError &err)
const char * string
Definition: Conv.cpp:212
StructuredHeaders::DecodeError parseIdentifier(StructuredHeaderItem &result)
DecodeError proxygen::StructuredHeadersDecoder::decodeParameterisedList ( ParameterisedList result)

Definition at line 65 of file StructuredHeadersDecoder.cpp.

References proxygen::StructuredHeaders::ParameterisedIdentifier::identifier, proxygen::StructuredHeaders::OK, proxygen::StructuredHeaders::ParameterisedIdentifier::parameterMap, and proxygen::StructuredHeaders::UNEXPECTED_END_OF_BUFFER.

Referenced by StructuredHeadersDecoder(), and proxygen::TEST_F().

66  {
67 
68  while (!buf_.isEmpty()) {
69 
70  ParameterisedIdentifier primaryIdentifier;
71 
72  auto err = buf_.parseIdentifier(primaryIdentifier.identifier);
73  if (err != DecodeError::OK) {
74  return err;
75  }
76 
78 
79  err = decodeMap(primaryIdentifier.parameterMap, MapType::PARAMETERISED_MAP);
80  if (err != DecodeError::OK) {
81  return err;
82  }
83 
84  result.emplace_back(primaryIdentifier);
85 
87 
88  if (buf_.isEmpty()) {
89  return DecodeError::OK;
90  }
91 
92  if (buf_.removeSymbol(",", true) != DecodeError::OK) {
93  return err;
94  }
95 
97 
98  }
99 
100  return buf_.handleDecodeError(DecodeError::UNEXPECTED_END_OF_BUFFER);
101 }
DecodeError removeSymbol(const std::string &symbol, bool strict)
StructuredHeaders::DecodeError decodeMap(std::unordered_map< std::string, StructuredHeaderItem > &result, MapType mapType)
DecodeError handleDecodeError(const DecodeError &err)
StructuredHeaders::DecodeError parseIdentifier(StructuredHeaderItem &result)

Member Data Documentation

StructuredHeadersBuffer proxygen::StructuredHeadersDecoder::buf_
private

Definition at line 43 of file StructuredHeadersDecoder.h.


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