[ox/mc,oc] Add support for ox::Array serialization

This commit is contained in:
Gary Talent 2023-02-18 17:07:14 -06:00
parent 58b7f813cc
commit 2e051f947d
4 changed files with 25 additions and 4 deletions

View File

@ -281,7 +281,20 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
return field(name, val->data(), val->size()); return field(name, val->data(), val->size());
} }
++m_field; ++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 { } else {
if ((m_unionIdx == -1 || m_unionIdx == m_field) && val) { if ((m_unionIdx == -1 || m_unionIdx == m_field) && val) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { 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; ++m_field;
return OxError(0); return {};
} }
} }

View File

@ -290,7 +290,7 @@ constexpr Error MetalClawWriter::fieldCString(const char*, const char *val, std:
template<typename T> template<typename T>
constexpr Error MetalClawWriter::field(const char*, T *val) noexcept { 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()); return field(nullptr, val->data(), val->size());
} else { } else {
bool fieldSet = false; bool fieldSet = false;

View File

@ -147,6 +147,14 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
const auto srcSize = srcVal.size(); const auto srcSize = srcVal.size();
val->resize(srcSize); val->resize(srcSize);
err = field(key, val->data(), val->size()); 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()) { } else if (targetValid()) {
const auto &jv = value(key); const auto &jv = value(key);
if (jv.empty() || jv.isObject()) { if (jv.empty() || jv.isObject()) {

View File

@ -214,7 +214,7 @@ Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcep
template<typename T> template<typename T>
Error OrganicClawWriter::field(const char *key, T *val) noexcept { 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()); return field(key, val->data(), val->size());
} else if (val && targetValid()) { } else if (val && targetValid()) {
OrganicClawWriter w; OrganicClawWriter w;