userver: userver/chaotic/ref.hpp Source File
Loading...
Searching...
No Matches
ref.hpp
1#pragma once
2
3#include <userver/formats/common/meta.hpp>
4#include <userver/formats/json/value.hpp>
5#include <userver/utils/box.hpp>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace chaotic {
10
11template <typename T>
12struct Ref {
13 const utils::Box<formats::common::ParseType<formats::json::Value, T>>& value;
14};
15
16template <typename Value, typename T>
17utils::Box<formats::common::ParseType<Value, T>> Parse(const Value& value, formats::parse::To<Ref<T>>) {
18 auto result = value.template As<T>();
19 return result;
20}
21
22template <typename Value, typename T>
23Value Serialize(const Ref<T>& ps, formats::serialize::To<Value>) {
24 return typename Value::Builder{T{*ps.value}}.ExtractValue();
25}
26
27} // namespace chaotic
28
29USERVER_NAMESPACE_END