This commit is contained in:
csh
2025-07-05 10:38:05 +08:00
parent 3cc1fccc81
commit 0c4619261d
39 changed files with 2085 additions and 875 deletions
@@ -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)
{