[ox/oc] Fix array writing to write all values
All checks were successful
Build / build (push) Successful in 2m6s
All checks were successful
Build / build (push) Successful in 2m6s
This is necessary because OC array sizes are determined through the presence of the data.
This commit is contained in:
parent
4b9758f478
commit
6b774ec285
44
deps/ox/src/ox/oc/write.hpp
vendored
44
deps/ox/src/ox/oc/write.hpp
vendored
@ -37,7 +37,7 @@ class OrganicClawWriter {
|
||||
explicit OrganicClawWriter(Json::Value json, int unionIdx = -1) noexcept;
|
||||
|
||||
Error field(const char *key, const int8_t *val) noexcept {
|
||||
if (*val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -45,7 +45,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const int16_t *val) noexcept {
|
||||
if (*val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -53,7 +53,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const int32_t *val) noexcept {
|
||||
if (*val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -61,7 +61,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const int64_t *val) noexcept {
|
||||
if (*val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -70,7 +70,7 @@ class OrganicClawWriter {
|
||||
|
||||
|
||||
Error field(const char *key, const uint8_t *val) noexcept {
|
||||
if (*val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -78,7 +78,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const uint16_t *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -86,7 +86,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const uint32_t *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -94,15 +94,15 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
Error field(const char *key, const uint64_t *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, const bool *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
Error field(char const*key, bool const*val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -110,10 +110,10 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
template<typename U, bool force = true>
|
||||
Error field(const char*, UnionView<U, force> val) noexcept;
|
||||
Error field(char const*, UnionView<U, force> val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char *key, const HashMap<String, T> *val) noexcept {
|
||||
Error field(char const*key, HashMap<String, T> const*val) noexcept {
|
||||
if (targetValid()) {
|
||||
const auto &keys = val->keys();
|
||||
OrganicClawWriter w;
|
||||
@ -132,7 +132,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, const BString<L> *val) noexcept {
|
||||
Error field(char const*key, BString<L> const*val) noexcept {
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
@ -141,7 +141,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, const BasicString<L> *val) noexcept {
|
||||
Error field(char const*key, BasicString<L> const*val) noexcept {
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
@ -199,10 +199,24 @@ Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) n
|
||||
OrganicClawWriter w((Json::Value(Json::arrayValue)));
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
oxReturnError(handler.field("", &val[i]));
|
||||
oxReturnError(handler.field({}, &val[i]));
|
||||
}
|
||||
if (w.m_json.isNull()) {
|
||||
if constexpr(is_same_v<T, bool>) {
|
||||
value(key) = Json::booleanValue;
|
||||
} else if constexpr(is_integral_v<T>) {
|
||||
value(key) = Json::intValue;
|
||||
} else if constexpr(isOxString_v<T>) {
|
||||
value(key) = Json::stringValue;
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
value(key) = Json::arrayValue;
|
||||
} else {
|
||||
value(key) = Json::objectValue;
|
||||
}
|
||||
} else {
|
||||
value(key) = w.m_json;
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user