[ox] Make UUID serializable, and make serialize as a string in OC
This commit is contained in:
6
deps/ox/src/ox/oc/read.cpp
vendored
6
deps/ox/src/ox/oc/read.cpp
vendored
@@ -290,6 +290,12 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, UUID *val) noexcept {
|
||||
UUIDStr str;
|
||||
oxReturnError(field(key, &str));
|
||||
return UUID::fromString(str).moveTo(val);
|
||||
}
|
||||
|
||||
Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) noexcept {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
|
3
deps/ox/src/ox/oc/read.hpp
vendored
3
deps/ox/src/ox/oc/read.hpp
vendored
@@ -21,6 +21,7 @@
|
||||
#include <ox/std/memops.hpp>
|
||||
#include <ox/std/memory.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/uuid.hpp>
|
||||
|
||||
namespace ox {
|
||||
|
||||
@@ -79,6 +80,8 @@ class OrganicClawReader {
|
||||
|
||||
Error fieldCString(const char *key, char **val, std::size_t buffLen) noexcept;
|
||||
|
||||
Error field(const char *key, UUID *val) noexcept;
|
||||
|
||||
/**
|
||||
* Reads an array length from the current location in the buffer.
|
||||
* @param pass indicates that the parsing should iterate past the array length
|
||||
|
9
deps/ox/src/ox/oc/write.cpp
vendored
9
deps/ox/src/ox/oc/write.cpp
vendored
@@ -46,6 +46,15 @@ Error OrganicClawWriter::fieldCString(const char *key, char **val) noexcept {
|
||||
return fieldCString(key, const_cast<const char**>(val), {});
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::field(const char *key, const UUID *uuid) noexcept {
|
||||
const auto uuidStr = uuid->toString();
|
||||
if (targetValid() && uuidStr.len()) {
|
||||
value(key) = uuidStr.c_str();
|
||||
}
|
||||
++m_fieldIt;
|
||||
return {};
|
||||
}
|
||||
|
||||
Json::Value &OrganicClawWriter::value(const char *key) noexcept {
|
||||
if (m_json.isArray()) {
|
||||
return m_json[m_fieldIt];
|
||||
|
7
deps/ox/src/ox/oc/write.hpp
vendored
7
deps/ox/src/ox/oc/write.hpp
vendored
@@ -18,6 +18,7 @@
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/uuid.hpp>
|
||||
|
||||
namespace ox {
|
||||
|
||||
@@ -105,7 +106,7 @@ class OrganicClawWriter {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -130,7 +131,7 @@ class OrganicClawWriter {
|
||||
value(key) = w.m_json;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -172,6 +173,8 @@ class OrganicClawWriter {
|
||||
|
||||
Error fieldCString(const char *name, char **val) noexcept;
|
||||
|
||||
Error field(const char *key, const UUID *uuid) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, T *val) noexcept;
|
||||
|
||||
|
Reference in New Issue
Block a user