diff --git a/deps/ox/src/ox/mc/read.cpp b/deps/ox/src/ox/mc/read.cpp index 6b20a312..17ab4190 100644 --- a/deps/ox/src/ox/mc/read.cpp +++ b/deps/ox/src/ox/mc/read.cpp @@ -31,40 +31,40 @@ MetalClawReader::~MetalClawReader() noexcept { } } -Error MetalClawReader::field(const char*, int8_t *val) { +Error MetalClawReader::field(const char*, int8_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, int16_t *val) { +Error MetalClawReader::field(const char*, int16_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, int32_t *val) { +Error MetalClawReader::field(const char*, int32_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, int64_t *val) { +Error MetalClawReader::field(const char*, int64_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, uint8_t *val) { +Error MetalClawReader::field(const char*, uint8_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, uint16_t *val) { +Error MetalClawReader::field(const char*, uint16_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, uint32_t *val) { +Error MetalClawReader::field(const char*, uint32_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, uint64_t *val) { +Error MetalClawReader::field(const char*, uint64_t *val) noexcept { return readInteger(val); } -Error MetalClawReader::field(const char*, bool *val) { +Error MetalClawReader::field(const char*, bool *val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { auto valErr = m_fieldPresence.get(m_field); *val = valErr.value; @@ -74,7 +74,7 @@ Error MetalClawReader::field(const char*, bool *val) { return OxError(0); } -Error MetalClawReader::field(const char*, SerStr val) { +Error MetalClawReader::field(const char*, SerStr val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_fieldPresence.get(m_field)) { // read the length @@ -109,7 +109,7 @@ Error MetalClawReader::field(const char*, SerStr val) { return OxError(0); } -Result MetalClawReader::arrayLength(const char*, bool pass) { +Result MetalClawReader::arrayLength(const char*, bool pass) noexcept { if ((m_unionIdx == -1 || m_unionIdx == m_field) && m_fieldPresence.get(m_field)) { // read the length if (m_buffIt >= m_buffLen) { @@ -125,7 +125,8 @@ Result MetalClawReader::arrayLength(const char*, bool pass) { return OxError(1); } -[[nodiscard]] StringLength MetalClawReader::stringLength(const char*) { +[[nodiscard]] +StringLength MetalClawReader::stringLength(const char*) noexcept { if ((m_unionIdx == -1 || m_unionIdx == m_field) && m_fieldPresence.get(m_field)) { // read the length std::size_t bytesRead = 0; @@ -135,15 +136,15 @@ Result MetalClawReader::arrayLength(const char*, bool pass) { return 0; } -MetalClawReader MetalClawReader::child(const char*, int unionIdx) { +MetalClawReader MetalClawReader::child(const char*, int unionIdx) noexcept { return MetalClawReader(m_buff + m_buffIt, m_buffLen - m_buffIt, unionIdx, this); } -bool MetalClawReader::fieldPresent(const char*) const { +bool MetalClawReader::fieldPresent(const char*) const noexcept { return m_fieldPresence.get(m_field).value; } -bool MetalClawReader::fieldPresent(int fieldNo) const { +bool MetalClawReader::fieldPresent(int fieldNo) const noexcept { return m_fieldPresence.get(fieldNo).value; } diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index 14fa7ac8..650b6d13 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -10,7 +10,9 @@ #include #include +#include #include +#include #include #include #include @@ -40,86 +42,89 @@ class MetalClawReader { ~MetalClawReader() noexcept; - Error field(const char*, int8_t *val); - Error field(const char*, int16_t *val); - Error field(const char*, int32_t *val); - Error field(const char*, int64_t *val); + Error field(const char*, int8_t *val) noexcept; + Error field(const char*, int16_t *val) noexcept; + Error field(const char*, int32_t *val) noexcept; + Error field(const char*, int64_t *val) noexcept; - Error field(const char*, uint8_t *val); - Error field(const char*, uint16_t *val); - Error field(const char*, uint32_t *val); - Error field(const char*, uint64_t *val); + Error field(const char*, uint8_t *val) noexcept; + Error field(const char*, uint16_t *val) noexcept; + Error field(const char*, uint32_t *val) noexcept; + Error field(const char*, uint64_t *val) noexcept; - Error field(const char*, bool *val); + Error field(const char*, bool *val) noexcept; // array handler template - Error field(const char*, T *val, std::size_t len); + Error field(const char*, T *val, std::size_t len) noexcept; // map handler template - Error field(const char*, HashMap *val); + Error field(const char*, HashMap *val) noexcept; // array handler, with callback to allow handling individual elements template - Error field(const char*, Handler handler); + Error field(const char*, Handler handler) noexcept; template - Error field(const char*, T *val); + Error field(const char*, T *val) noexcept; template - Error field(const char*, UnionView val); + Error field(const char*, UnionView val) noexcept; template - Error field(const char*, BString *val); + Error field(const char*, const BString *val) noexcept; - Error field(const char*, SerStr val); + Error field(const char*, SerStr 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 */ - Result arrayLength(const char *name, bool pass = true); + Result arrayLength(const char *name, bool pass = true) noexcept; /** * Reads an string length from the current location in the buffer. */ [[nodiscard]] - StringLength stringLength(const char *name); + StringLength stringLength(const char *name) noexcept; template - void setTypeInfo(const char *name = T::TypeName, int fields = countFields()); + void setTypeInfo(const char *name = getModelTypeName(), int fields = countFields()) noexcept; /** * Returns a MetalClawReader to parse a child object. */ [[nodiscard]] - MetalClawReader child(const char *name, int unionIdx = -1); + MetalClawReader child(const char *name, int unionIdx = -1) noexcept; /** * Indicates whether or not the next field to be read is present. */ - bool fieldPresent(const char *name) const; + [[nodiscard]] + bool fieldPresent(const char *name) const noexcept; /** * Indicates whether or not the given field is present. */ - bool fieldPresent(int fieldNo) const; + [[nodiscard]] + bool fieldPresent(int fieldNo) const noexcept; void nextField() noexcept; - static constexpr auto opType() { + [[nodiscard]] + static constexpr auto opType() noexcept { return OpType::Read; } private: template - Error readInteger(I *val); + Error readInteger(I *val) noexcept; }; template -Error MetalClawReader::field(const char *name, T *val) { +Error MetalClawReader::field(const char *name, T *val) noexcept { if constexpr(isVector_v) { if (m_unionIdx == -1 || m_unionIdx == m_field) { // set size of val if the field is present, don't worry about it if not @@ -142,7 +147,7 @@ Error MetalClawReader::field(const char *name, T *val) { } template -Error MetalClawReader::field(const char*, UnionView val) { +Error MetalClawReader::field(const char*, UnionView val) noexcept { if ((m_unionIdx == -1 || m_unionIdx == m_field) && val.get() && m_fieldPresence.get(m_field)) { auto reader = child("", val.idx()); oxReturnError(model(&reader, val.get())); @@ -152,12 +157,12 @@ Error MetalClawReader::field(const char*, UnionView val) { } template -Error MetalClawReader::field(const char *name, BString *val) { +Error MetalClawReader::field(const char *name, const BString *val) noexcept { return field(name, SerStr(val->data(), val->cap())); } template -Error MetalClawReader::readInteger(I *val) { +Error MetalClawReader::readInteger(I *val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_fieldPresence.get(m_field)) { std::size_t bytesRead = 0; @@ -179,7 +184,7 @@ Error MetalClawReader::readInteger(I *val) { // array handler template -Error MetalClawReader::field(const char *name, T *val, std::size_t valLen) { +Error MetalClawReader::field(const char *name, T *val, std::size_t valLen) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_fieldPresence.get(m_field)) { // read the length @@ -208,7 +213,7 @@ Error MetalClawReader::field(const char *name, T *val, std::size_t valLen) { } template -Error MetalClawReader::field(const char*, HashMap *val) { +Error MetalClawReader::field(const char*, HashMap *val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_fieldPresence.get(m_field)) { // read the length @@ -235,7 +240,7 @@ Error MetalClawReader::field(const char*, HashMap *val) { } template -Error MetalClawReader::field(const char*, Handler handler) { +Error MetalClawReader::field(const char*, Handler handler) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_fieldPresence.get(m_field)) { // read the length @@ -261,28 +266,28 @@ Error MetalClawReader::field(const char*, Handler handler) { } template -void MetalClawReader::setTypeInfo(const char*, int fields) { +void MetalClawReader::setTypeInfo(const char*, int fields) noexcept { m_fields = fields; m_buffIt = (fields / 8 + 1) - (fields % 8 == 0); m_fieldPresence.setFields(fields); - m_fieldPresence.setMaxLen(m_buffIt); + m_fieldPresence.setMaxLen(static_cast(m_buffIt)); } template -Error readMC(const char *buff, std::size_t buffLen, T *val) { +Error readMC(const char *buff, std::size_t buffLen, T *val) noexcept { MetalClawReader reader(bit_cast(buff), buffLen); return model(&reader, val); } template -Result readMC(const char *buff, std::size_t buffLen) { +Result readMC(const char *buff, std::size_t buffLen) noexcept { T val; oxReturnError(readMC(buff, buffLen, &val)); - return move(val); + return val; } template -Result readMC(const Vector &buff) { +Result readMC(const Buffer &buff) noexcept { return readMC(buff.data(), buff.size()); } diff --git a/deps/ox/src/ox/mc/write.cpp b/deps/ox/src/ox/mc/write.cpp index 4dc61619..ac975ee5 100644 --- a/deps/ox/src/ox/mc/write.cpp +++ b/deps/ox/src/ox/mc/write.cpp @@ -28,40 +28,40 @@ MetalClawWriter::~MetalClawWriter() noexcept { } } -Error MetalClawWriter::field(const char*, int8_t *val) noexcept { +Error MetalClawWriter::field(const char*, const int8_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, int16_t *val) noexcept { +Error MetalClawWriter::field(const char*, const int16_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, int32_t *val) noexcept { +Error MetalClawWriter::field(const char*, const int32_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, int64_t *val) noexcept { +Error MetalClawWriter::field(const char*, const int64_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, uint8_t *val) noexcept { +Error MetalClawWriter::field(const char*, const uint8_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, uint16_t *val) noexcept { +Error MetalClawWriter::field(const char*, const uint16_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, uint32_t *val) noexcept { +Error MetalClawWriter::field(const char*, const uint32_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, uint64_t *val) noexcept { +Error MetalClawWriter::field(const char*, const uint64_t *val) noexcept { return appendInteger(*val); } -Error MetalClawWriter::field(const char*, bool *val) noexcept { +Error MetalClawWriter::field(const char*, const bool *val) noexcept { if (m_unionIdx == -1 || m_unionIdx == m_field) { oxReturnError(m_fieldPresence.set(m_field, *val)); } diff --git a/deps/ox/src/ox/mc/write.hpp b/deps/ox/src/ox/mc/write.hpp index 03bbe9fe..03844988 100644 --- a/deps/ox/src/ox/mc/write.hpp +++ b/deps/ox/src/ox/mc/write.hpp @@ -42,23 +42,23 @@ class MetalClawWriter { ~MetalClawWriter() noexcept; - Error field(const char*, int8_t *val) noexcept; - Error field(const char*, int16_t *val) noexcept; - Error field(const char*, int32_t *val) noexcept; - Error field(const char*, int64_t *val) noexcept; + Error field(const char*, const int8_t *val) noexcept; + Error field(const char*, const int16_t *val) noexcept; + Error field(const char*, const int32_t *val) noexcept; + Error field(const char*, const int64_t *val) noexcept; - Error field(const char*, uint8_t *val) noexcept; - Error field(const char*, uint16_t *val) noexcept; - Error field(const char*, uint32_t *val) noexcept; - Error field(const char*, uint64_t *val) noexcept; + Error field(const char*, const uint8_t *val) noexcept; + Error field(const char*, const uint16_t *val) noexcept; + Error field(const char*, const uint32_t *val) noexcept; + Error field(const char*, const uint64_t *val) noexcept; - Error field(const char*, bool *val) noexcept; + Error field(const char*, const bool *val) noexcept; template - Error field(const char*, T *val, std::size_t len); + Error field(const char*, T *val, std::size_t len) noexcept; template - Error field(const char*, HashMap *val); + Error field(const char*, HashMap *val) noexcept; template Error field(const char*, BString *val) noexcept; @@ -66,17 +66,19 @@ class MetalClawWriter { Error field(const char*, SerStr val) noexcept; template - Error field(const char*, T *val); + Error field(const char*, T *val) noexcept; template - Error field(const char*, UnionView val); + Error field(const char*, UnionView val) noexcept; template - void setTypeInfo(const char *name = T::TypeName, int fields = countFields()); + void setTypeInfo(const char *name = T::TypeName, int fields = countFields()) noexcept; + [[nodiscard]] std::size_t size() noexcept; - static constexpr auto opType() { + [[nodiscard]] + static constexpr auto opType() noexcept { return OpType::Write; } @@ -92,7 +94,7 @@ Error MetalClawWriter::field(const char *name, BString *val) noexcept { } template -Error MetalClawWriter::field(const char*, T *val) { +Error MetalClawWriter::field(const char*, T *val) noexcept { if constexpr(isVector_v) { return field(nullptr, val->data(), val->size()); } else { @@ -112,7 +114,7 @@ Error MetalClawWriter::field(const char*, T *val) { } template -Error MetalClawWriter::field(const char*, UnionView val) { +Error MetalClawWriter::field(const char*, UnionView val) noexcept { bool fieldSet = false; if (val.get() && (m_unionIdx == -1 || m_unionIdx == m_field)) { MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt, val.idx()); @@ -128,7 +130,7 @@ Error MetalClawWriter::field(const char*, UnionView val) { } template -Error MetalClawWriter::field(const char*, T *val, std::size_t len) { +Error MetalClawWriter::field(const char*, T *val, std::size_t len) noexcept { bool fieldSet = false; if (len && (m_unionIdx == -1 || m_unionIdx == m_field)) { @@ -159,7 +161,7 @@ Error MetalClawWriter::field(const char*, T *val, std::size_t len) { } template -Error MetalClawWriter::field(const char*, HashMap *val) { +Error MetalClawWriter::field(const char*, HashMap *val) noexcept { const auto &keys = val->keys(); const auto len = keys.size(); bool fieldSet = false; @@ -216,7 +218,7 @@ Error MetalClawWriter::appendInteger(I val) noexcept { } template -void MetalClawWriter::setTypeInfo(const char*, int fields) { +void MetalClawWriter::setTypeInfo(const char*, int fields) noexcept { m_fields = fields; m_fieldPresence.setFields(fields); m_buffIt = m_fieldPresence.getMaxLen(); @@ -224,7 +226,7 @@ void MetalClawWriter::setTypeInfo(const char*, int fields) { } template -Result writeMC(T *val) { +Result writeMC(T *val) noexcept { Buffer buff(10 * units::MB); MetalClawWriter writer(bit_cast(buff.data()), buff.size()); oxReturnError(model(&writer, val)); @@ -233,7 +235,7 @@ Result writeMC(T *val) { } template -Error writeMC(char *buff, std::size_t buffLen, T *val, std::size_t *sizeOut = nullptr) { +Error writeMC(char *buff, std::size_t buffLen, T *val, std::size_t *sizeOut = nullptr) noexcept { MetalClawWriter writer(bit_cast(buff), buffLen); auto err = model(&writer, val); if (sizeOut) { diff --git a/deps/ox/src/ox/oc/read.cpp b/deps/ox/src/ox/oc/read.cpp index d74381bd..46b323c7 100644 --- a/deps/ox/src/ox/oc/read.cpp +++ b/deps/ox/src/ox/oc/read.cpp @@ -30,12 +30,12 @@ OrganicClawReader::OrganicClawReader(const char *json, std::size_t jsonLen) { } } -OrganicClawReader::OrganicClawReader(const Json::Value &json, int unionIdx): +OrganicClawReader::OrganicClawReader(const Json::Value &json, int unionIdx) noexcept: m_json(json), m_unionIdx(unionIdx) { } -Error OrganicClawReader::field(const char *key, int8_t *val) { +Error OrganicClawReader::field(const char *key, int8_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -51,7 +51,7 @@ Error OrganicClawReader::field(const char *key, int8_t *val) { return err; } -Error OrganicClawReader::field(const char *key, int16_t *val) { +Error OrganicClawReader::field(const char *key, int16_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -67,7 +67,7 @@ Error OrganicClawReader::field(const char *key, int16_t *val) { return err; } -Error OrganicClawReader::field(const char *key, int32_t *val) { +Error OrganicClawReader::field(const char *key, int32_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -83,7 +83,7 @@ Error OrganicClawReader::field(const char *key, int32_t *val) { return err; } -Error OrganicClawReader::field(const char *key, int64_t *val) { +Error OrganicClawReader::field(const char *key, int64_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -100,7 +100,7 @@ Error OrganicClawReader::field(const char *key, int64_t *val) { } -Error OrganicClawReader::field(const char *key, uint8_t *val) { +Error OrganicClawReader::field(const char *key, uint8_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -116,7 +116,7 @@ Error OrganicClawReader::field(const char *key, uint8_t *val) { return err; } -Error OrganicClawReader::field(const char *key, uint16_t *val) { +Error OrganicClawReader::field(const char *key, uint16_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -132,7 +132,7 @@ Error OrganicClawReader::field(const char *key, uint16_t *val) { return err; } -Error OrganicClawReader::field(const char *key, uint32_t *val) { +Error OrganicClawReader::field(const char *key, uint32_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -148,7 +148,7 @@ Error OrganicClawReader::field(const char *key, uint32_t *val) { return err; } -Error OrganicClawReader::field(const char *key, uint64_t *val) { +Error OrganicClawReader::field(const char *key, uint64_t *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -164,7 +164,7 @@ Error OrganicClawReader::field(const char *key, uint64_t *val) { return err; } -Error OrganicClawReader::field(const char *key, bool *val) { +Error OrganicClawReader::field(const char *key, bool *val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -180,7 +180,7 @@ Error OrganicClawReader::field(const char *key, bool *val) { return err; } -Error OrganicClawReader::field(const char *key, SerStr val) { +Error OrganicClawReader::field(const char *key, SerStr val) noexcept { auto err = OxError(0); const char *begin = nullptr, *end = nullptr; const auto &jv = value(key); @@ -208,7 +208,7 @@ Error OrganicClawReader::field(const char *key, SerStr val) { return err; } -Result OrganicClawReader::arrayLength(const char *key, bool) { +Result OrganicClawReader::arrayLength(const char *key, bool) noexcept { const auto &jv = value(key); if (jv.empty()) { return 0; @@ -219,7 +219,8 @@ Result OrganicClawReader::arrayLength(const char *key, bool) { return OxError(1, "Type mismatch"); } -[[nodiscard]] std::size_t OrganicClawReader::stringLength(const char *key) { +[[nodiscard]] +std::size_t OrganicClawReader::stringLength(const char *key) noexcept { const char *begin = nullptr, *end = nullptr; const auto &jv = value(key); if (jv.empty()) { @@ -232,15 +233,15 @@ Result OrganicClawReader::arrayLength(const char *key, bool) { return OxError(1, "Type mismatch"); } -OrganicClawReader OrganicClawReader::child(const char *key, int unionIdx) { +OrganicClawReader OrganicClawReader::child(const char *key, int unionIdx) noexcept { return OrganicClawReader(m_json[key], unionIdx); } -bool OrganicClawReader::fieldPresent(const char *key) { +bool OrganicClawReader::fieldPresent(const char *key) noexcept { return !m_json[key].empty(); } -Json::Value &OrganicClawReader::value(const char *key) { +Json::Value &OrganicClawReader::value(const char *key) noexcept { if (m_json.isArray()) { return m_json[m_fieldIt]; } else { diff --git a/deps/ox/src/ox/oc/read.hpp b/deps/ox/src/ox/oc/read.hpp index ab41dcac..9dfd402a 100644 --- a/deps/ox/src/ox/oc/read.hpp +++ b/deps/ox/src/ox/oc/read.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -30,38 +31,38 @@ class OrganicClawReader { int m_unionIdx = -1; public: - OrganicClawReader() = default; + OrganicClawReader() noexcept = default; OrganicClawReader(const uint8_t *buff, std::size_t buffSize); OrganicClawReader(const char *json, std::size_t buffSize); - explicit OrganicClawReader(const Json::Value &json, int unionIdx = -1); + explicit OrganicClawReader(const Json::Value &json, int unionIdx = -1) noexcept; - Error field(const char *key, int8_t *val); - Error field(const char *key, int16_t *val); - Error field(const char *key, int32_t *val); - Error field(const char *key, int64_t *val); + Error field(const char *key, int8_t *val) noexcept; + Error field(const char *key, int16_t *val) noexcept; + Error field(const char *key, int32_t *val) noexcept; + Error field(const char *key, int64_t *val) noexcept; - Error field(const char *key, uint8_t *val); - Error field(const char *key, uint16_t *val); - Error field(const char *key, uint32_t *val); - Error field(const char *key, uint64_t *val); + Error field(const char *key, uint8_t *val) noexcept; + Error field(const char *key, uint16_t *val) noexcept; + Error field(const char *key, uint32_t *val) noexcept; + Error field(const char *key, uint64_t *val) noexcept; - Error field(const char *key, bool *val); + Error field(const char *key, bool *val) noexcept; // array handler template - Error field(const char *key, T *val, std::size_t len); + Error field(const char *key, T *val, std::size_t len) noexcept; template - Error field(const char*, HashMap *val); + Error field(const char*, HashMap *val) noexcept; template - Error field(const char *key, T *val); + Error field(const char *key, T *val) noexcept; template - Error field(const char *key, UnionView val); + Error field(const char *key, UnionView val) noexcept; template Error field(const char *key, BasicString *val) noexcept; @@ -69,49 +70,48 @@ class OrganicClawReader { template Error field(const char *key, BString *val) noexcept; - Error field(const char *key, SerStr val); + Error field(const char *key, SerStr 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 */ - Result arrayLength(const char *key, bool pass = true); + Result arrayLength(const char *key, bool pass = true) noexcept; /** * Reads an string length from the current location in the buffer. */ [[nodiscard]] - std::size_t stringLength(const char *name); + std::size_t stringLength(const char *name) noexcept; template - constexpr void setTypeInfo(const char* = T::TypeName, int = countFields()) { + constexpr void setTypeInfo(const char* = getModelTypeName(), int = countFields()) noexcept { } /** * Returns a OrganicClawReader to parse a child object. */ [[nodiscard]] - OrganicClawReader child(const char *key, int unionIdx = -1); + OrganicClawReader child(const char *key, int unionIdx = -1) noexcept; // compatibility stub constexpr void nextField() noexcept {} - bool fieldPresent(const char *key); + bool fieldPresent(const char *key) noexcept; - static constexpr auto opType() { + static constexpr auto opType() noexcept { return OpType::Read; } private: - - Json::Value &value(const char *key); + Json::Value &value(const char *key) noexcept; bool targetValid() noexcept; }; template -Error OrganicClawReader::field(const char *key, T *val) { +Error OrganicClawReader::field(const char *key, T *val) noexcept { auto err = OxError(0); if constexpr(isVector_v) { return field(key, val->data(), val->size()); @@ -129,7 +129,7 @@ Error OrganicClawReader::field(const char *key, T *val) { } template -Error OrganicClawReader::field(const char *key, UnionView val) { +Error OrganicClawReader::field(const char *key, UnionView val) noexcept { auto err = OxError(0); if (targetValid()) { const auto &jv = value(key); @@ -162,13 +162,13 @@ Error OrganicClawReader::field(const char *key, BasicString *val) noexcept { } template -Error OrganicClawReader::field(const char *name, BString *val) noexcept { - return field(name, SerStr(val->data(), val->cap())); +Error OrganicClawReader::field(const char *key, BString *val) noexcept { + return field(key, SerStr(val->data(), val->cap())); } // array handler template -Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) { +Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) noexcept { const auto &srcVal = value(key); auto srcSize = srcVal.size(); if (srcSize > valLen) { @@ -182,7 +182,7 @@ Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) { } template -Error OrganicClawReader::field(const char *key, HashMap *val) { +Error OrganicClawReader::field(const char *key, HashMap *val) noexcept { const auto &srcVal = value(key); auto keys = srcVal.getMemberNames(); auto srcSize = srcVal.size(); @@ -214,19 +214,19 @@ Error readOC(const char *json, std::size_t jsonSize, T *val) noexcept { } template -Result readOC(const char *json, std::size_t jsonLen) { +Result readOC(const char *json, std::size_t jsonLen) noexcept { T val; oxReturnError(readOC(json, jsonLen, &val)); return move(val); } template -Result readOC(const char *json) { +Result readOC(const char *json) noexcept { return readOC(json, ox_strlen(json)); } template -Result readOC(const Buffer &buff) { +Result readOC(const Buffer &buff) noexcept { return readOC(buff.data(), buff.size()); } diff --git a/deps/ox/src/ox/oc/write.cpp b/deps/ox/src/ox/oc/write.cpp index dba68c7e..6fa68a10 100644 --- a/deps/ox/src/ox/oc/write.cpp +++ b/deps/ox/src/ox/oc/write.cpp @@ -10,15 +10,15 @@ namespace ox { -OrganicClawWriter::OrganicClawWriter(int unionIdx): m_unionIdx(unionIdx) { +OrganicClawWriter::OrganicClawWriter(int unionIdx) noexcept: m_unionIdx(unionIdx) { } -OrganicClawWriter::OrganicClawWriter(Json::Value json, int unionIdx): +OrganicClawWriter::OrganicClawWriter(Json::Value json, int unionIdx) noexcept: m_json(json), m_unionIdx(unionIdx) { } -Error OrganicClawWriter::field(const char *key, int8_t *val) { +Error OrganicClawWriter::field(const char *key, const int8_t *val) noexcept { if (*val) { value(key) = *val; } @@ -26,7 +26,7 @@ Error OrganicClawWriter::field(const char *key, int8_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, int16_t *val) { +Error OrganicClawWriter::field(const char *key, const int16_t *val) noexcept { if (*val) { value(key) = *val; } @@ -34,7 +34,7 @@ Error OrganicClawWriter::field(const char *key, int16_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, int32_t *val) { +Error OrganicClawWriter::field(const char *key, const int32_t *val) noexcept { if (*val) { value(key) = *val; } @@ -42,7 +42,7 @@ Error OrganicClawWriter::field(const char *key, int32_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, int64_t *val) { +Error OrganicClawWriter::field(const char *key, const int64_t *val) noexcept { if (*val) { value(key) = *val; } @@ -51,7 +51,7 @@ Error OrganicClawWriter::field(const char *key, int64_t *val) { } -Error OrganicClawWriter::field(const char *key, uint8_t *val) { +Error OrganicClawWriter::field(const char *key, const uint8_t *val) noexcept { if (*val) { value(key) = *val; } @@ -59,7 +59,7 @@ Error OrganicClawWriter::field(const char *key, uint8_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, uint16_t *val) { +Error OrganicClawWriter::field(const char *key, const uint16_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -67,7 +67,7 @@ Error OrganicClawWriter::field(const char *key, uint16_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, uint32_t *val) { +Error OrganicClawWriter::field(const char *key, const uint32_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -75,7 +75,7 @@ Error OrganicClawWriter::field(const char *key, uint32_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, uint64_t *val) { +Error OrganicClawWriter::field(const char *key, const uint64_t *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -83,7 +83,7 @@ Error OrganicClawWriter::field(const char *key, uint64_t *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, bool *val) { +Error OrganicClawWriter::field(const char *key, const bool *val) noexcept { if (targetValid() && *val) { value(key) = *val; } @@ -91,7 +91,7 @@ Error OrganicClawWriter::field(const char *key, bool *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, String *val) { +Error OrganicClawWriter::field(const char *key, const String *val) noexcept { if (targetValid() && val->len()) { value(key) = val->c_str(); } @@ -99,7 +99,7 @@ Error OrganicClawWriter::field(const char *key, String *val) { return OxError(0); } -Error OrganicClawWriter::field(const char *key, SerStr val) { +Error OrganicClawWriter::field(const char *key, SerStr val) noexcept { if (targetValid() && val.len()) { value(key) = val.c_str(); } @@ -107,7 +107,7 @@ Error OrganicClawWriter::field(const char *key, SerStr val) { return OxError(0); } -Json::Value &OrganicClawWriter::value(const char *key) { +Json::Value &OrganicClawWriter::value(const char *key) noexcept { if (m_json.isArray()) { return m_json[m_fieldIt]; } else { diff --git a/deps/ox/src/ox/oc/write.hpp b/deps/ox/src/ox/oc/write.hpp index bd1fb622..da743d3d 100644 --- a/deps/ox/src/ox/oc/write.hpp +++ b/deps/ox/src/ox/oc/write.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,7 @@ namespace ox { class OrganicClawWriter { template - friend Result writeOC(T *val); + friend Result writeOC(T *val) noexcept; protected: Json::Value m_json; @@ -30,62 +31,62 @@ class OrganicClawWriter { int m_unionIdx = -1; public: - OrganicClawWriter(int unionIdx = -1); + explicit OrganicClawWriter(int unionIdx = -1) noexcept; - OrganicClawWriter(Json::Value json, int unionIdx = -1); + explicit OrganicClawWriter(Json::Value json, int unionIdx = -1) noexcept; - Error field(const char*, int8_t *val); - Error field(const char*, int16_t *val); - Error field(const char*, int32_t *val); - Error field(const char*, int64_t *val); + Error field(const char*, const int8_t *val) noexcept; + Error field(const char*, const int16_t *val) noexcept; + Error field(const char*, const int32_t *val) noexcept; + Error field(const char*, const int64_t *val) noexcept; - Error field(const char*, uint8_t *val); - Error field(const char*, uint16_t *val); - Error field(const char*, uint32_t *val); - Error field(const char*, uint64_t *val); + Error field(const char*, const uint8_t *val) noexcept; + Error field(const char*, const uint16_t *val) noexcept; + Error field(const char*, const uint32_t *val) noexcept; + Error field(const char*, const uint64_t *val) noexcept; - Error field(const char*, bool *val); + Error field(const char*, const bool *val) noexcept; template - Error field(const char*, T *val, std::size_t len); + Error field(const char*, T *val, std::size_t len) noexcept; template - Error field(const char*, UnionView val); + Error field(const char*, UnionView val) noexcept; template - Error field(const char*, HashMap *val); + Error field(const char*, const HashMap *val) noexcept; template - Error field(const char*, BString *val); + Error field(const char*, const BString *val) noexcept; - Error field(const char*, String *val); + Error field(const char*, const String *val) noexcept; - Error field(const char*, SerStr val); + Error field(const char*, SerStr val) noexcept; template - Error field(const char*, T *val); + Error field(const char*, T *val) noexcept; template - constexpr void setTypeInfo(const char* = T::TypeName, int = countFields()) { + constexpr void setTypeInfo(const char* = T::TypeName, int = countFields()) noexcept { } - static constexpr auto opType() { + static constexpr auto opType() noexcept { return OpType::Write; } private: [[nodiscard]] - constexpr bool targetValid() noexcept { + constexpr bool targetValid() const noexcept { return static_cast(m_fieldIt) == m_unionIdx || m_unionIdx == -1; } [[nodiscard]] - Json::Value &value(const char *key); + Json::Value &value(const char *key) noexcept; }; template -Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) { +Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcept { if (targetValid()) { OrganicClawWriter w((Json::Value(Json::arrayValue))); for (std::size_t i = 0; i < len; ++i) { @@ -98,12 +99,12 @@ Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) { } template -Error OrganicClawWriter::field(const char *key, BString *val) { +Error OrganicClawWriter::field(const char *key, const BString *val) noexcept { return field(key, SerStr(val->data(), val->cap())); } template -Error OrganicClawWriter::field(const char *key, T *val) { +Error OrganicClawWriter::field(const char *key, T *val) noexcept { if constexpr(isVector_v) { return field(key, val->data(), val->size()); } else if (val && targetValid()) { @@ -118,7 +119,7 @@ Error OrganicClawWriter::field(const char *key, T *val) { } template -Error OrganicClawWriter::field(const char *key, UnionView val) { +Error OrganicClawWriter::field(const char *key, UnionView val) noexcept { if (targetValid()) { OrganicClawWriter w(val.idx()); oxReturnError(model(&w, val.get())); @@ -131,7 +132,7 @@ Error OrganicClawWriter::field(const char *key, UnionView val) { } template -Error OrganicClawWriter::field(const char *key, HashMap *val) { +Error OrganicClawWriter::field(const char *key, const HashMap *val) noexcept { if (targetValid()) { const auto &keys = val->keys(); OrganicClawWriter w; @@ -146,8 +147,9 @@ Error OrganicClawWriter::field(const char *key, HashMap *val) { } template -Result writeOC(T *val) { +Result writeOC(T *val) noexcept { OrganicClawWriter writer; + writer.template setTypeInfo(); oxReturnError(model(&writer, val)); Json::StreamWriterBuilder jsonBuilder; const auto str = Json::writeString(jsonBuilder, writer.m_json);