From 0d606643f591fc252f66527a452ebae9c779ab47 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 4 Dec 2023 21:43:06 -0600 Subject: [PATCH] [ox/mc,ox/oc] Fix write for ox::Array, cleanup --- deps/ox/src/ox/mc/write.hpp | 89 +++++++++++-------------------------- deps/ox/src/ox/oc/write.cpp | 8 ---- deps/ox/src/ox/oc/write.hpp | 54 +++++++--------------- 3 files changed, 41 insertions(+), 110 deletions(-) diff --git a/deps/ox/src/ox/mc/write.hpp b/deps/ox/src/ox/mc/write.hpp index 4ee00c4e..4e955464 100644 --- a/deps/ox/src/ox/mc/write.hpp +++ b/deps/ox/src/ox/mc/write.hpp @@ -43,39 +43,30 @@ class MetalClawWriter { constexpr ~MetalClawWriter() noexcept = default; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; + constexpr Error field(const char*, const int8_t *val) noexcept; + constexpr Error field(const char*, const int16_t *val) noexcept; + constexpr Error field(const char*, const int32_t *val) noexcept; + constexpr Error field(const char*, const int64_t *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; + constexpr Error field(const char*, const uint8_t *val) noexcept; + constexpr Error field(const char*, const uint16_t *val) noexcept; + constexpr Error field(const char*, const uint32_t *val) noexcept; + constexpr Error field(const char*, const uint64_t *val) noexcept; - constexpr Error field(const char*, CommonPtrWith auto *val) noexcept; + constexpr Error field(const char*, const bool *val) noexcept; template - constexpr Error field(const char*, T *val, std::size_t len) noexcept; + constexpr Error field(const char*, const T *val, std::size_t len) noexcept; template constexpr Error field(const char *name, const HashMap *val) noexcept; - template - constexpr Error field(const char*, HashMap *val) noexcept; - template constexpr Error field(const char*, const BasicString *val) noexcept; template constexpr Error field(const char*, const BString *val) noexcept; - template - constexpr Error field(const char*, BasicString *val) noexcept; - - template - constexpr Error field(const char*, BString *val) noexcept; - constexpr Error fieldCString(const char *name, const char *const*val, std::size_t buffLen) noexcept; constexpr Error fieldCString(const char *name, const char **val) noexcept; @@ -84,20 +75,8 @@ class MetalClawWriter { constexpr Error fieldCString(const char *name, const char *val, std::size_t len) noexcept; - constexpr Error fieldCString(const char *name, char **val, std::size_t buffLen) noexcept { - return fieldCString(name, const_cast(val), buffLen); - } - - constexpr Error fieldCString(const char *name, char **val) noexcept { - return fieldCString(name, const_cast(val)); - } - - constexpr Error fieldCString(const char *name, char *val, std::size_t buffLen) noexcept { - return fieldCString(name, const_cast(val), buffLen); - } - template - constexpr Error field(const char*, T *val) noexcept; + constexpr Error field(const char*, const T *val) noexcept; template constexpr Error field(const char*, UnionView val) noexcept; @@ -159,47 +138,47 @@ constexpr MetalClawWriter::MetalClawWriter(Writer &writer, int unionIdx) } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const int8_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const int16_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const int32_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const int64_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const uint8_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const uint16_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const uint32_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const uint64_t *val) noexcept { return appendInteger(*val); } template -constexpr Error MetalClawWriter::field(const char*, CommonPtrWith auto *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const bool *val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { oxReturnError(m_fieldPresence.set(static_cast(m_field), *val)); } @@ -230,18 +209,6 @@ constexpr Error MetalClawWriter::field(const char *name, const BStringdata(), val->cap()); } -template -template -constexpr Error MetalClawWriter::field(const char *name, BasicString *val) noexcept { - return field(name, const_cast*>(val)); -} - -template -template -constexpr Error MetalClawWriter::field(const char *name, BString *val) noexcept { - return fieldCString(name, val->data(), val->cap()); -} - template constexpr Error MetalClawWriter::fieldCString(const char*, const char *const*val, std::size_t) noexcept { bool fieldSet = false; @@ -287,7 +254,7 @@ constexpr Error MetalClawWriter::fieldCString(const char*, const char *v template template -constexpr Error MetalClawWriter::field(const char*, T *val) noexcept { +constexpr Error MetalClawWriter::field(const char*, const T *val) noexcept { if constexpr(isVector_v || isArray_v) { return field(nullptr, val->data(), val->size()); } else { @@ -323,7 +290,7 @@ constexpr Error MetalClawWriter::field(const char*, UnionView template template -constexpr Error MetalClawWriter::field(const char*, T *val, std::size_t len) noexcept { +constexpr Error MetalClawWriter::field(const char*, const T *val, std::size_t len) noexcept { bool fieldSet = false; if (len && (m_unionIdx == -1 || m_unionIdx == m_field)) { // write the length @@ -334,7 +301,7 @@ constexpr Error MetalClawWriter::field(const char*, T *val, std::size_t oxReturnError(handler.template setTypeInfo("List", 0, {}, static_cast(len))); // write the array for (std::size_t i = 0; i < len; i++) { - oxReturnError(handler.field("", &val[i])); + oxReturnError(handler.field("", const_cast(&val[i]))); } oxReturnError(writer.finalize()); fieldSet = true; @@ -381,12 +348,6 @@ constexpr Error MetalClawWriter::field(const char*, const HashMap -template -constexpr Error MetalClawWriter::field(const char *name, HashMap *val) noexcept { - return field(name, const_cast*>(val)); -} - template template constexpr ox::Error MetalClawWriter::setTypeInfo( @@ -421,7 +382,7 @@ Result writeMC(Writer_c auto &writer, const auto &val) noexcept { return {}; } -Result writeMC(const auto &val, std::size_t buffReserveSz = 2 * units::KB) noexcept { +Result writeMC(auto const&val, std::size_t buffReserveSz = 2 * units::KB) noexcept { Buffer buff(buffReserveSz); BufferWriter bw(&buff, 0); oxReturnError(writeMC(bw, val)); @@ -429,7 +390,7 @@ Result writeMC(const auto &val, std::size_t buffReserveSz = 2 * units::K return buff; } -Error writeMC(char *buff, std::size_t buffLen, const auto &val, std::size_t *sizeOut = nullptr) noexcept { +Error writeMC(char *buff, std::size_t buffLen, auto const&val, std::size_t *sizeOut = nullptr) noexcept { CharBuffWriter bw(buff, buffLen); oxReturnError(writeMC(bw, val)); if (sizeOut) { diff --git a/deps/ox/src/ox/oc/write.cpp b/deps/ox/src/ox/oc/write.cpp index 40c72e89..73f95848 100644 --- a/deps/ox/src/ox/oc/write.cpp +++ b/deps/ox/src/ox/oc/write.cpp @@ -26,18 +26,10 @@ Error OrganicClawWriter::fieldCString(const char *key, const char *const*val, in return OxError(0); } -Error OrganicClawWriter::fieldCString(const char *key, char **val, int len) noexcept { - return fieldCString(key, const_cast(val), len); -} - Error OrganicClawWriter::fieldCString(const char *key, const char *const*val) noexcept { return fieldCString(key, const_cast(val), {}); } -Error OrganicClawWriter::fieldCString(const char *key, char **val) noexcept { - return fieldCString(key, const_cast(val), {}); -} - Error OrganicClawWriter::field(const char *key, const UUID *uuid) noexcept { const auto uuidStr = uuid->toString(); if (targetValid() && uuidStr.len()) { diff --git a/deps/ox/src/ox/oc/write.hpp b/deps/ox/src/ox/oc/write.hpp index db6b5af2..f636ce53 100644 --- a/deps/ox/src/ox/oc/write.hpp +++ b/deps/ox/src/ox/oc/write.hpp @@ -36,7 +36,7 @@ class OrganicClawWriter { explicit OrganicClawWriter(Json::Value json, int unionIdx = -1) noexcept; - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const int8_t *val) noexcept { if (*val) { value(key) = *val; } @@ -44,7 +44,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const int16_t *val) noexcept { if (*val) { value(key) = *val; } @@ -52,7 +52,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const int32_t *val) noexcept { if (*val) { value(key) = *val; } @@ -60,7 +60,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const int64_t *val) noexcept { if (*val) { value(key) = *val; } @@ -69,7 +69,7 @@ class OrganicClawWriter { } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const uint8_t *val) noexcept { if (*val) { value(key) = *val; } @@ -77,7 +77,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const uint16_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -85,7 +85,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const uint32_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -93,7 +93,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const uint64_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -101,7 +101,7 @@ class OrganicClawWriter { return OxError(0); } - Error field(const char *key, CommonPtrWith auto *val) noexcept { + Error field(const char *key, const bool *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -109,9 +109,6 @@ class OrganicClawWriter { return {}; } - template - Error field(const char*, T *val, std::size_t len) noexcept; - template Error field(const char*, UnionView val) noexcept; @@ -134,11 +131,6 @@ class OrganicClawWriter { return {}; } - template - Error field(const char *key, HashMap *val) noexcept { - return field(key, const_cast*>(val)); - } - template Error field(const char *key, const BString *val) noexcept { if (targetValid() && val->len()) { @@ -148,15 +140,6 @@ class OrganicClawWriter { return {}; } - template - Error field(const char *key, BString *val) noexcept { - if (targetValid() && val->len()) { - value(key) = val->c_str(); - } - ++m_fieldIt; - return {}; - } - template Error field(const char *key, const BasicString *val) noexcept { if (targetValid() && val->len()) { @@ -166,23 +149,17 @@ class OrganicClawWriter { return OxError(0); } - template - Error field(const char *key, BasicString *val) noexcept { - return field(key, const_cast*>(val)); - } - Error fieldCString(const char*, const char *const*val, int len) noexcept; - Error fieldCString(const char *name, char **val, int len) noexcept; - Error fieldCString(const char *name, const char *const*val) noexcept; - Error fieldCString(const char *name, char **val) noexcept; - Error field(const char *key, const UUID *uuid) noexcept; template - Error field(const char*, T *val) noexcept; + Error field(const char*, const T *val, std::size_t len) noexcept; + + template + Error field(const char*, const T *val) noexcept; template constexpr ox::Error setTypeInfo( @@ -200,6 +177,7 @@ class OrganicClawWriter { return {}; } + [[nodiscard]] static constexpr auto opType() noexcept { return OpType::Write; } @@ -216,7 +194,7 @@ class OrganicClawWriter { }; template -Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcept { +Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) noexcept { if (targetValid() && len) { OrganicClawWriter w((Json::Value(Json::arrayValue))); ModelHandlerInterface handler{&w}; @@ -230,7 +208,7 @@ Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcep } template -Error OrganicClawWriter::field(const char *key, T *val) noexcept { +Error OrganicClawWriter::field(const char *key, const T *val) noexcept { if constexpr(isVector_v || isArray_v) { return field(key, val->data(), val->size()); } else if (val && targetValid()) {