json_array
GitOrigin-RevId: 7ebdc6dc38f79b5cfe638bd38a973354a83d80c6
This commit is contained in:
parent
dd4b3ba12e
commit
963b6c060a
@ -342,6 +342,10 @@ class JsonArrayScope : public JsonScope {
|
||||
}
|
||||
template <class T>
|
||||
JsonArrayScope &operator<<(const T &x) {
|
||||
return (*this)(x);
|
||||
}
|
||||
template <class T>
|
||||
JsonArrayScope &operator()(const T &x) {
|
||||
enter_value() << x;
|
||||
return *this;
|
||||
}
|
||||
@ -391,7 +395,7 @@ class JsonObjectScope : public JsonScope {
|
||||
}
|
||||
jb_->enter_value() << key;
|
||||
*sb_ << ":";
|
||||
jb_->enter_value() << key;
|
||||
jb_->enter_value() << value;
|
||||
return *this;
|
||||
}
|
||||
JsonObjectScope &operator<<(const JsonRaw &key_value) {
|
||||
@ -785,6 +789,33 @@ auto json_object(F &&f) {
|
||||
return JsonObjectImpl<F>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class F>
|
||||
class JsonArrayImpl : Jsonable {
|
||||
public:
|
||||
JsonArrayImpl(F &&f) : f_(std::forward<F>(f)) {
|
||||
}
|
||||
void store(JsonValueScope *scope) const {
|
||||
auto array = scope->enter_array();
|
||||
f_(array);
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
};
|
||||
template <class F>
|
||||
auto json_array(F &&f) {
|
||||
return JsonArrayImpl<F>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class A, class F>
|
||||
auto json_array(const A &a, F &&f) {
|
||||
return json_array([&a, &f](auto &arr) {
|
||||
for (auto &x : a) {
|
||||
arr(f(x));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool has_json_object_field(JsonObject &object, Slice name);
|
||||
|
||||
Result<JsonValue> get_json_object_field(JsonObject &object, Slice name, JsonValue::Type type,
|
||||
|
Reference in New Issue
Block a user