Skip to content

Commit

Permalink
JsonUtils: add StringName<->JSON serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sturnclaw committed Dec 7, 2024
1 parent 46c758e commit b5b06a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/JsonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "FileSystem.h"
#include "base64/base64.hpp"
#include "core/GZipFormat.h"
#include "core/StringName.h"
#include "utils.h"

#include <cinttypes>
Expand Down Expand Up @@ -851,3 +852,13 @@ void StrToMatrix4x4d(const char *str, matrix4x4d &val)
val[i] = fu[i].d;
#endif
}

void to_json(Json &out, const StringName &str)
{
out = str.sv();
}

void from_json(const Json &obj, StringName &str)
{
str = StringName(obj.get<std::string_view>());
}
5 changes: 5 additions & 0 deletions src/JsonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "matrix4x4.h"
#include "vector3.h"

class StringName;

namespace FileSystem {
class FileSource;
class FileData;
Expand Down Expand Up @@ -117,4 +119,7 @@ void StrToMatrix3x3d(const char *str, matrix3x3d &val);
void StrToMatrix4x4f(const char *str, matrix4x4f &val);
void StrToMatrix4x4d(const char *str, matrix4x4d &val);

void to_json(Json &, const StringName &);
void from_json(const Json &, StringName &);

#endif /* _JSON_UTILS_H */

0 comments on commit b5b06a7

Please sign in to comment.