diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/scheme/util | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/scheme/util')
-rw-r--r-- | library/cpp/scheme/util/scheme_holder.cpp | 1 | ||||
-rw-r--r-- | library/cpp/scheme/util/scheme_holder.h | 76 | ||||
-rw-r--r-- | library/cpp/scheme/util/utils.cpp | 23 | ||||
-rw-r--r-- | library/cpp/scheme/util/utils.h | 23 | ||||
-rw-r--r-- | library/cpp/scheme/util/ya.make | 14 |
5 files changed, 137 insertions, 0 deletions
diff --git a/library/cpp/scheme/util/scheme_holder.cpp b/library/cpp/scheme/util/scheme_holder.cpp new file mode 100644 index 0000000000..33232acc50 --- /dev/null +++ b/library/cpp/scheme/util/scheme_holder.cpp @@ -0,0 +1 @@ +#include "scheme_holder.h" diff --git a/library/cpp/scheme/util/scheme_holder.h b/library/cpp/scheme/util/scheme_holder.h new file mode 100644 index 0000000000..f2fa16d1cd --- /dev/null +++ b/library/cpp/scheme/util/scheme_holder.h @@ -0,0 +1,76 @@ +#pragma once + +#include <library/cpp/scheme/scheme.h> + + +// Scheme adapter that holds referenced value +template <typename TScheme> +class TSchemeHolder { +public: + TSchemeHolder() + : Value_(NSc::Null()) + , Scheme_(&Value_) + { + } + + explicit TSchemeHolder(NSc::TValue&& value) + : Value_(std::move(value)) + , Scheme_(&Value_) + { + } + + explicit TSchemeHolder(const NSc::TValue& value) + : Value_(value) + , Scheme_(&Value_) + { + } + + TSchemeHolder(TSchemeHolder<TScheme>&& rhs) + : Value_(std::move(rhs.Value_)) + , Scheme_(&Value_) + { + } + + TSchemeHolder(const TSchemeHolder<TScheme>& rhs) + : Value_(rhs.Value_) + , Scheme_(&Value_) + { + } + + TSchemeHolder<TScheme>& operator=(TSchemeHolder<TScheme>&& rhs) { + Value_ = std::move(rhs.Value_); + return *this; + } + TSchemeHolder<TScheme>& operator=(const TSchemeHolder<TScheme>& rhs) { + Value_ = rhs.Value_; + return *this; + } + + TScheme& Scheme() { + return Scheme_; + } + const TScheme& Scheme() const { + return Scheme_; + } + TScheme& operator->() { + return Scheme_; + } + const TScheme& operator->() const { + return Scheme_; + } + + NSc::TValue& Value() { + return Value_; + } + const NSc::TValue& Value() const { + return Value_; + } + + bool IsNull() const { + return Value_.IsNull(); + } + +private: + NSc::TValue Value_; + TScheme Scheme_; +}; diff --git a/library/cpp/scheme/util/utils.cpp b/library/cpp/scheme/util/utils.cpp new file mode 100644 index 0000000000..40cceceacd --- /dev/null +++ b/library/cpp/scheme/util/utils.cpp @@ -0,0 +1,23 @@ +#include "utils.h" + +#include <library/cpp/string_utils/base64/base64.h> + +namespace NScUtils { + +void CopyField(const NSc::TValue& from, NSc::TValue& to) { + to = from; +} + +} // namespace NScUtils + +void TSerializer<NSc::TValue>::Save(IOutputStream* out, const NSc::TValue& v) { + TString json = Base64Encode(v.ToJson()); + ::Save(out, json); +} + +void TSerializer<NSc::TValue>::Load(IInputStream* in, NSc::TValue& v) { + TString json; + ::Load(in, json); + json = Base64Decode(json); + v = NSc::TValue::FromJsonThrow(json); +} diff --git a/library/cpp/scheme/util/utils.h b/library/cpp/scheme/util/utils.h new file mode 100644 index 0000000000..f7d666f67a --- /dev/null +++ b/library/cpp/scheme/util/utils.h @@ -0,0 +1,23 @@ +#pragma once + +#include <library/cpp/scheme/scheme.h> + +#include <util/generic/strbuf.h> +#include <util/ysaveload.h> + +namespace NScUtils { + +void CopyField(const NSc::TValue& from, NSc::TValue& to); + +template <typename... Args> +void CopyField(const NSc::TValue& from, NSc::TValue& to, TStringBuf path, Args... args) { + CopyField(from[path], to[path], args...); +} + +} // namespace NScUtils + +template<> +struct TSerializer<NSc::TValue> { + static void Save(IOutputStream* out, const NSc::TValue& v); + static void Load(IInputStream* in, NSc::TValue& v); +}; diff --git a/library/cpp/scheme/util/ya.make b/library/cpp/scheme/util/ya.make new file mode 100644 index 0000000000..dffd1c8070 --- /dev/null +++ b/library/cpp/scheme/util/ya.make @@ -0,0 +1,14 @@ +LIBRARY() + +OWNER(g:cards_serivce) + +SRCS( + scheme_holder.cpp + utils.cpp +) + +PEERDIR( + library/cpp/string_utils/base64 +) + +END() |