[ox/mc,oc] Add support for ox::Array serialization
This commit is contained in:
parent
58b7f813cc
commit
2e051f947d
17
deps/ox/src/ox/mc/read.hpp
vendored
17
deps/ox/src/ox/mc/read.hpp
vendored
@ -281,7 +281,20 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
|
||||
return field(name, val->data(), val->size());
|
||||
}
|
||||
++m_field;
|
||||
return OxError(0);
|
||||
return {};
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
if (m_unionIdx == -1 || m_unionIdx == m_field) {
|
||||
// set size of val if the field is present, don't worry about it if not
|
||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||
oxRequire(len, arrayLength(name, false));
|
||||
if (len > val->size()) {
|
||||
return OxError(1, "Input array is too long");
|
||||
}
|
||||
}
|
||||
return field(name, val->data(), val->size());
|
||||
}
|
||||
++m_field;
|
||||
return {};
|
||||
} else {
|
||||
if ((m_unionIdx == -1 || m_unionIdx == m_field) && val) {
|
||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||
@ -291,7 +304,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
|
||||
}
|
||||
}
|
||||
++m_field;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/mc/write.hpp
vendored
2
deps/ox/src/ox/mc/write.hpp
vendored
@ -290,7 +290,7 @@ constexpr Error MetalClawWriter::fieldCString(const char*, const char *val, std:
|
||||
|
||||
template<typename T>
|
||||
constexpr Error MetalClawWriter::field(const char*, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(nullptr, val->data(), val->size());
|
||||
} else {
|
||||
bool fieldSet = false;
|
||||
|
8
deps/ox/src/ox/oc/read.hpp
vendored
8
deps/ox/src/ox/oc/read.hpp
vendored
@ -147,6 +147,14 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
|
||||
const auto srcSize = srcVal.size();
|
||||
val->resize(srcSize);
|
||||
err = field(key, val->data(), val->size());
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
const auto &srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
if (srcSize > val->size()) {
|
||||
err = OxError(1, "Input array is too long");
|
||||
} else {
|
||||
err = field(key, val->data(), val->size());
|
||||
}
|
||||
} else if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty() || jv.isObject()) {
|
||||
|
2
deps/ox/src/ox/oc/write.hpp
vendored
2
deps/ox/src/ox/oc/write.hpp
vendored
@ -214,7 +214,7 @@ Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcep
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(key, val->data(), val->size());
|
||||
} else if (val && targetValid()) {
|
||||
OrganicClawWriter w;
|
||||
|
Loading…
Reference in New Issue
Block a user