19 #ifndef GRPC_CORE_LIB_JSON_JSON_H
20 #define GRPC_CORE_LIB_JSON_JSON_H
30 #include "absl/strings/string_view.h"
55 using Object = std::map<std::string, Json>;
56 using Array = std::vector<Json>;
71 Json(
Json&& other) noexcept { MoveFrom(std::move(other)); }
73 MoveFrom(std::move(other));
80 Json(
const std::string&
string,
bool is_number =
false)
81 : type_(is_number ?
Type::NUMBER :
Type::STRING), string_value_(string) {}
84 string_value_ = string;
90 Json(
const char*
string,
bool is_number =
false)
91 :
Json(std::string(string), is_number) {}
93 *
this = std::string(
string);
97 Json(
char*
string,
bool is_number =
false)
98 :
Json(std::string(string), is_number) {}
100 *
this = std::string(
string);
107 : type_(
Type::STRING), string_value_(std::move(string)) {}
110 string_value_ = std::move(
string);
123 template <
typename NumericType>
126 : type_(
Type::NUMBER), string_value_(std::to_string(number)) {}
127 template <
typename NumericType>
130 string_value_ = std::to_string(number);
139 object_value_ = object;
146 : type_(
Type::OBJECT), object_value_(std::move(object)) {}
149 object_value_ = std::move(
object);
158 array_value_ = array;
167 array_value_ = std::move(array);
172 std::string
Dump(
int indent = 0)
const;
184 if (type_ != other.type_)
return false;
188 if (string_value_ != other.string_value_)
return false;
191 if (object_value_ != other.object_value_)
return false;
194 if (array_value_ != other.array_value_)
return false;
205 void CopyFrom(
const Json& other) {
210 string_value_ = other.string_value_;
213 object_value_ = other.object_value_;
216 array_value_ = other.array_value_;
223 void MoveFrom(
Json&& other) {
229 string_value_ = std::move(other.string_value_);
232 object_value_ = std::move(other.object_value_);
235 array_value_ = std::move(other.array_value_);
243 std::string string_value_;
Json(Json &&other) noexcept
Definition: json.h:71
Type type() const
Definition: json.h:175
std::string * mutable_string_value()
Definition: json.h:177
Array * mutable_array()
Definition: json.h:181
const std::string & string_value() const
Definition: json.h:176
const Array & array_value() const
Definition: json.h:180
std::map< std::string, Json > Object
Definition: json.h:55
const Object & object_value() const
Definition: json.h:178
bool operator==(const Json &other) const
Definition: json.h:183
Json(char *string, bool is_number=false)
Definition: json.h:97
Object * mutable_object()
Definition: json.h:179
std::string Dump(int indent=0) const
Definition: json_writer.cc:334
Type
Definition: json.h:45
Json(const Array &array)
Definition: json.h:155
Json(Array &&array)
Definition: json.h:164
Json & operator=(std::string &&string)
Definition: json.h:108
Json & operator=(const Object &object)
Definition: json.h:137
Json(const char *string, bool is_number=false)
Definition: json.h:90
Json & operator=(char *string)
Definition: json.h:99
Json(const std::string &string, bool is_number=false)
Definition: json.h:80
Json & operator=(Array &&array)
Definition: json.h:165
bool operator!=(const Json &other) const
Definition: json.h:202
Json & operator=(bool b)
Definition: json.h:117
static Json Parse(absl::string_view json_str, grpc_error_handle *error)
Definition: json_reader.cc:852
Json(Object &&object)
Definition: json.h:145
Json(const Json &other)
Definition: json.h:64
Json & operator=(Json &&other) noexcept
Definition: json.h:72
Json & operator=(Object &&object)
Definition: json.h:147
Json & operator=(const std::string &string)
Definition: json.h:82
std::vector< Json > Array
Definition: json.h:56
Json(NumericType number)
Definition: json.h:125
Json & operator=(NumericType number)
Definition: json.h:128
Json(const Object &object)
Definition: json.h:136
Json & operator=(const Json &other)
Definition: json.h:65
Json(std::string &&string)
Definition: json.h:106
Json & operator=(const Array &array)
Definition: json.h:156
Json & operator=(const char *string)
Definition: json.h:92
Json(bool b)
Definition: json.h:116
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: error_internal.h:41