refactor
This commit is contained in:
@@ -5,6 +5,12 @@ namespace lsp::transform
|
||||
{
|
||||
|
||||
// ===== 全局便利函数 =====
|
||||
template<typename T>
|
||||
std::optional<T> Deserialize(const std::string& json);
|
||||
|
||||
template<typename T>
|
||||
std::optional<std::string> Serialize(const T& obj);
|
||||
|
||||
// 基本类型
|
||||
template<typename T>
|
||||
protocol::LSPAny LSPAny(const T& obj);
|
||||
|
||||
@@ -3,6 +3,28 @@
|
||||
|
||||
namespace lsp::transform
|
||||
{
|
||||
template<typename T>
|
||||
inline std::optional<T> Deserialize(const std::string& json)
|
||||
{
|
||||
T obj;
|
||||
auto ce = glz::read_json(obj, json);
|
||||
if (ce)
|
||||
return std::nullopt;
|
||||
else
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<std::string> Serialize(const T& obj)
|
||||
{
|
||||
std::string json;
|
||||
auto ce = glz::write_json(obj, json);
|
||||
if (ce)
|
||||
return std::nullopt;
|
||||
else
|
||||
return json;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline protocol::LSPAny LSPAny(const T& obj)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user