json_object draft
GitOrigin-RevId: 571b710cc58c0271c0f78a9e1a1263b6858730f3
This commit is contained in:
parent
4910a36a13
commit
293b706c74
@ -203,8 +203,13 @@ void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> devi
|
||||
Slice auth_;
|
||||
};
|
||||
|
||||
token = json_encode<string>(
|
||||
JsonWebPushToken(device_token->endpoint_, device_token->p256dh_base64url_, device_token->auth_base64url_));
|
||||
token = json_encode<string>(json_object([&device_token](auto &o) {
|
||||
o("endpoint", device_token->endpoint_);
|
||||
o("keys", json_object([&device_token](auto &o) {
|
||||
o("pb256df", device_token->p256dh_base64url_);
|
||||
o("auth", device_token->auth_base64url_);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
token_type = TokenType::WEB_PUSH;
|
||||
break;
|
||||
|
@ -375,19 +375,23 @@ class JsonObjectScope : public JsonScope {
|
||||
}
|
||||
template <class S, class T>
|
||||
JsonObjectScope &operator<<(std::tuple<S, T> key_value) {
|
||||
return *this << std::pair<S, T>(std::get<0>(key_value), std::get<1>(key_value));
|
||||
return (*this)(std::get<0>(key_value), std::get<1>(key_value));
|
||||
}
|
||||
template <class S, class T>
|
||||
JsonObjectScope &operator<<(std::pair<S, T> key_value) {
|
||||
return (*this)(key_value.first, key_value.second);
|
||||
}
|
||||
template <class S, class T>
|
||||
JsonObjectScope &operator()(S &&key, T &&value) {
|
||||
CHECK(is_active());
|
||||
if (is_first_) {
|
||||
*sb_ << ",";
|
||||
} else {
|
||||
is_first_ = true;
|
||||
}
|
||||
jb_->enter_value() << key_value.first;
|
||||
jb_->enter_value() << key;
|
||||
*sb_ << ":";
|
||||
jb_->enter_value() << key_value.second;
|
||||
jb_->enter_value() << key;
|
||||
return *this;
|
||||
}
|
||||
JsonObjectScope &operator<<(const JsonRaw &key_value) {
|
||||
@ -763,6 +767,24 @@ void to_json(JsonValueScope &jv, const T &value) {
|
||||
jv << value;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
class JsonObjectImpl : Jsonable {
|
||||
public:
|
||||
JsonObjectImpl(F &&f) : f_(std::forward<F>(f)) {
|
||||
}
|
||||
void store(JsonValueScope *scope) const {
|
||||
auto object = scope->enter_object();
|
||||
f_(object);
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
};
|
||||
template <class F>
|
||||
auto json_object(F &&f) {
|
||||
return JsonObjectImpl<F>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
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