proxygen
StructuredHeadersConstants.h
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  */
10 #pragma once
11 
12 #include <unordered_map>
13 #include <map>
14 #include <boost/variant.hpp>
15 
16 namespace proxygen {
17 
18 namespace StructuredHeaders {
19 
20 static const int kMaxValidIntegerLength = 19;
21 static const int kMaxValidFloatLength = 16;
22 
23 /* tagged union for an item in a structured header */
25 public:
26  enum class Type {
27  NONE,
28  STRING,
30  IDENTIFIER,
31  DOUBLE,
32  INT64
33  };
34 
35  template<typename T>
36  bool operator!=(const T& other) const {
37  return !operator==(other);
38  }
39 
40  template<typename T>
41  bool operator==(const T& other) const {
42  try {
43  return boost::get<T>(value) == other;
44  } catch (boost::bad_get& ) {
45  return false;
46  }
47  }
48 
50  boost::variant<int64_t, double, std::string> value;
51 };
52 
55  std::unordered_map<std::string, StructuredHeaderItem> parameterMap;
56 };
57 
58 using ParameterisedList =
59  std::vector<StructuredHeaders::ParameterisedIdentifier>;
60 
61 using Dictionary = std::unordered_map<std::string, StructuredHeaderItem>;
62 
63 enum class DecodeError : uint8_t {
64  OK = 0,
65  VALUE_TOO_LONG = 1,
70  DUPLICATE_KEY = 6
71 };
72 
73 enum class EncodeError : uint8_t {
74  OK = 0,
76  BAD_IDENTIFIER = 2,
77  BAD_STRING = 3,
80 };
81 
82 static const std::map<DecodeError, std::string>
84  {DecodeError::OK, "No error"},
85  {DecodeError::VALUE_TOO_LONG, "Numeric value is too long"},
86  {DecodeError::INVALID_CHARACTER, "Invalid character"},
87  {DecodeError::UNDECODEABLE_BINARY_CONTENT, "Undecodable binary content"},
88  {DecodeError::UNEXPECTED_END_OF_BUFFER, "Unexpected end of buffer"},
89  {DecodeError::UNPARSEABLE_NUMERIC_TYPE, "Unparseable numeric type"},
90  {DecodeError::DUPLICATE_KEY, "Duplicate key found"}
91 };
92 
93 static const std::map<EncodeError, std::string>
95  {EncodeError::OK, "No error"},
96  {EncodeError::EMPTY_DATA_STRUCTURE, "Empty data structure"},
97  {EncodeError::BAD_IDENTIFIER, "Bad identifier"},
98  {EncodeError::BAD_STRING, "Bad string"},
99  {EncodeError::ITEM_TYPE_MISMATCH, "Item type mismatch"},
100  {EncodeError::ENCODING_NULL_ITEM, "Tried to encode null item"}
101 };
102 
103 }
104 }
#define T(v)
Definition: http_parser.c:233
std::vector< StructuredHeaders::ParameterisedIdentifier > ParameterisedList
static const std::map< DecodeError, std::string > decodeErrorDescription
std::unordered_map< std::string, StructuredHeaderItem > parameterMap
boost::variant< int64_t, double, std::string > value
std::unordered_map< std::string, StructuredHeaderItem > Dictionary
const char * string
Definition: Conv.cpp:212
static const std::map< EncodeError, std::string > encodeErrorDescription