[ox/{mc,oc}] Improve noexcept correctness
This commit is contained in:
parent
24ca5623e8
commit
55f14eb548
31
deps/ox/src/ox/mc/read.cpp
vendored
31
deps/ox/src/ox/mc/read.cpp
vendored
@ -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<ArrayLength> MetalClawReader::arrayLength(const char*, bool pass) {
|
||||
Result<ArrayLength> 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<ArrayLength> 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<ArrayLength> 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;
|
||||
}
|
||||
|
||||
|
79
deps/ox/src/ox/mc/read.hpp
vendored
79
deps/ox/src/ox/mc/read.hpp
vendored
@ -10,7 +10,9 @@
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/optype.hpp>
|
||||
#include <ox/model/typenamecatcher.hpp>
|
||||
#include <ox/model/types.hpp>
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/byteswap.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/trace.hpp>
|
||||
@ -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<typename T>
|
||||
Error field(const char*, T *val, std::size_t len);
|
||||
Error field(const char*, T *val, std::size_t len) noexcept;
|
||||
|
||||
// map handler
|
||||
template<typename T>
|
||||
Error field(const char*, HashMap<String, T> *val);
|
||||
Error field(const char*, HashMap<String, T> *val) noexcept;
|
||||
|
||||
// array handler, with callback to allow handling individual elements
|
||||
template<typename T, typename Handler>
|
||||
Error field(const char*, Handler handler);
|
||||
Error field(const char*, Handler handler) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, T *val);
|
||||
Error field(const char*, T *val) noexcept;
|
||||
|
||||
template<typename U>
|
||||
Error field(const char*, UnionView<U> val);
|
||||
Error field(const char*, UnionView<U> val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char*, BString<L> *val);
|
||||
Error field(const char*, const BString<L> *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> arrayLength(const char *name, bool pass = true);
|
||||
Result<ArrayLength> 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<typename T = std::nullptr_t>
|
||||
void setTypeInfo(const char *name = T::TypeName, int fields = countFields<T>());
|
||||
void setTypeInfo(const char *name = getModelTypeName<T>(), int fields = countFields<T>()) 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<typename I>
|
||||
Error readInteger(I *val);
|
||||
Error readInteger(I *val) noexcept;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Error MetalClawReader::field(const char *name, T *val) {
|
||||
Error MetalClawReader::field(const char *name, T *val) noexcept {
|
||||
if constexpr(isVector_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
|
||||
@ -142,7 +147,7 @@ Error MetalClawReader::field(const char *name, T *val) {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
Error MetalClawReader::field(const char*, UnionView<U> val) {
|
||||
Error MetalClawReader::field(const char*, UnionView<U> 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<U> val) {
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error MetalClawReader::field(const char *name, BString<L> *val) {
|
||||
Error MetalClawReader::field(const char *name, const BString<L> *val) noexcept {
|
||||
return field(name, SerStr(val->data(), val->cap()));
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
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<typename T>
|
||||
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<typename T>
|
||||
Error MetalClawReader::field(const char*, HashMap<String, T> *val) {
|
||||
Error MetalClawReader::field(const char*, HashMap<String, T> *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<String, T> *val) {
|
||||
}
|
||||
|
||||
template<typename T, typename Handler>
|
||||
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<typename T>
|
||||
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<int>(m_buffIt));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
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<uint8_t*>(buff), buffLen);
|
||||
return model(&reader, val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result<T> readMC(const char *buff, std::size_t buffLen) {
|
||||
Result<T> readMC(const char *buff, std::size_t buffLen) noexcept {
|
||||
T val;
|
||||
oxReturnError(readMC(buff, buffLen, &val));
|
||||
return move(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result<T> readMC(const Vector<char> &buff) {
|
||||
Result<T> readMC(const Buffer &buff) noexcept {
|
||||
return readMC<T>(buff.data(), buff.size());
|
||||
}
|
||||
|
||||
|
18
deps/ox/src/ox/mc/write.cpp
vendored
18
deps/ox/src/ox/mc/write.cpp
vendored
@ -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));
|
||||
}
|
||||
|
46
deps/ox/src/ox/mc/write.hpp
vendored
46
deps/ox/src/ox/mc/write.hpp
vendored
@ -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<typename T>
|
||||
Error field(const char*, T *val, std::size_t len);
|
||||
Error field(const char*, T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, HashMap<String, T> *val);
|
||||
Error field(const char*, HashMap<String, T> *val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char*, BString<L> *val) noexcept;
|
||||
@ -66,17 +66,19 @@ class MetalClawWriter {
|
||||
Error field(const char*, SerStr val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, T *val);
|
||||
Error field(const char*, T *val) noexcept;
|
||||
|
||||
template<typename U>
|
||||
Error field(const char*, UnionView<U> val);
|
||||
Error field(const char*, UnionView<U> val) noexcept;
|
||||
|
||||
template<typename T = std::nullptr_t>
|
||||
void setTypeInfo(const char *name = T::TypeName, int fields = countFields<T>());
|
||||
void setTypeInfo(const char *name = T::TypeName, int fields = countFields<T>()) 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<L> *val) noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error MetalClawWriter::field(const char*, T *val) {
|
||||
Error MetalClawWriter::field(const char*, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
return field(nullptr, val->data(), val->size());
|
||||
} else {
|
||||
@ -112,7 +114,7 @@ Error MetalClawWriter::field(const char*, T *val) {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
Error MetalClawWriter::field(const char*, UnionView<U> val) {
|
||||
Error MetalClawWriter::field(const char*, UnionView<U> 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<U> val) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
Error MetalClawWriter::field(const char*, HashMap<String, T> *val) {
|
||||
Error MetalClawWriter::field(const char*, HashMap<String, T> *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<typename T>
|
||||
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<typename T>
|
||||
Result<Buffer> writeMC(T *val) {
|
||||
Result<Buffer> writeMC(T *val) noexcept {
|
||||
Buffer buff(10 * units::MB);
|
||||
MetalClawWriter writer(bit_cast<uint8_t*>(buff.data()), buff.size());
|
||||
oxReturnError(model(&writer, val));
|
||||
@ -233,7 +235,7 @@ Result<Buffer> writeMC(T *val) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
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<uint8_t*>(buff), buffLen);
|
||||
auto err = model(&writer, val);
|
||||
if (sizeOut) {
|
||||
|
33
deps/ox/src/ox/oc/read.cpp
vendored
33
deps/ox/src/ox/oc/read.cpp
vendored
@ -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<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) {
|
||||
Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) noexcept {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
return 0;
|
||||
@ -219,7 +219,8 @@ Result<std::size_t> 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<std::size_t> 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 {
|
||||
|
66
deps/ox/src/ox/oc/read.hpp
vendored
66
deps/ox/src/ox/oc/read.hpp
vendored
@ -12,6 +12,7 @@
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/optype.hpp>
|
||||
#include <ox/model/typenamecatcher.hpp>
|
||||
#include <ox/model/types.hpp>
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/byteswap.hpp>
|
||||
@ -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<typename T>
|
||||
Error field(const char *key, T *val, std::size_t len);
|
||||
Error field(const char *key, T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, HashMap<String, T> *val);
|
||||
Error field(const char*, HashMap<String, T> *val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char *key, T *val);
|
||||
Error field(const char *key, T *val) noexcept;
|
||||
|
||||
template<typename U>
|
||||
Error field(const char *key, UnionView<U> val);
|
||||
Error field(const char *key, UnionView<U> val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BasicString<L> *val) noexcept;
|
||||
@ -69,49 +70,48 @@ class OrganicClawReader {
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BString<L> *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<std::size_t> arrayLength(const char *key, bool pass = true);
|
||||
Result<std::size_t> 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<typename T = void>
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = countFields<T>()) {
|
||||
constexpr void setTypeInfo(const char* = getModelTypeName<T>(), int = countFields<T>()) 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<typename T>
|
||||
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<T>) {
|
||||
return field(key, val->data(), val->size());
|
||||
@ -129,7 +129,7 @@ Error OrganicClawReader::field(const char *key, T *val) {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
Error OrganicClawReader::field(const char *key, UnionView<U> val) {
|
||||
Error OrganicClawReader::field(const char *key, UnionView<U> val) noexcept {
|
||||
auto err = OxError(0);
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
@ -162,13 +162,13 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error OrganicClawReader::field(const char *name, BString<L> *val) noexcept {
|
||||
return field(name, SerStr(val->data(), val->cap()));
|
||||
Error OrganicClawReader::field(const char *key, BString<L> *val) noexcept {
|
||||
return field(key, SerStr(val->data(), val->cap()));
|
||||
}
|
||||
|
||||
// array handler
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) {
|
||||
Error OrganicClawReader::field(const char *key, HashMap<String, T> *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<typename T>
|
||||
Result<T> readOC(const char *json, std::size_t jsonLen) {
|
||||
Result<T> readOC(const char *json, std::size_t jsonLen) noexcept {
|
||||
T val;
|
||||
oxReturnError(readOC(json, jsonLen, &val));
|
||||
return move(val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result<T> readOC(const char *json) {
|
||||
Result<T> readOC(const char *json) noexcept {
|
||||
return readOC<T>(json, ox_strlen(json));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result<T> readOC(const Buffer &buff) {
|
||||
Result<T> readOC(const Buffer &buff) noexcept {
|
||||
return readOC<T>(buff.data(), buff.size());
|
||||
}
|
||||
|
||||
|
28
deps/ox/src/ox/oc/write.cpp
vendored
28
deps/ox/src/ox/oc/write.cpp
vendored
@ -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 {
|
||||
|
60
deps/ox/src/ox/oc/write.hpp
vendored
60
deps/ox/src/ox/oc/write.hpp
vendored
@ -13,6 +13,7 @@
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/optype.hpp>
|
||||
#include <ox/model/types.hpp>
|
||||
#include <ox/model/typenamecatcher.hpp>
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
@ -22,7 +23,7 @@ namespace ox {
|
||||
class OrganicClawWriter {
|
||||
|
||||
template<typename T>
|
||||
friend Result<Buffer> writeOC(T *val);
|
||||
friend Result<Buffer> 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<typename T>
|
||||
Error field(const char*, T *val, std::size_t len);
|
||||
Error field(const char*, T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename U>
|
||||
Error field(const char*, UnionView<U> val);
|
||||
Error field(const char*, UnionView<U> val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, HashMap<String, T> *val);
|
||||
Error field(const char*, const HashMap<String, T> *val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char*, BString<L> *val);
|
||||
Error field(const char*, const BString<L> *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<typename T>
|
||||
Error field(const char*, T *val);
|
||||
Error field(const char*, T *val) noexcept;
|
||||
|
||||
template<typename T = void>
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = countFields<T>()) {
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = countFields<T>()) 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<int>(m_fieldIt) == m_unionIdx || m_unionIdx == -1;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Json::Value &value(const char *key);
|
||||
Json::Value &value(const char *key) noexcept;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
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<std::size_t L>
|
||||
Error OrganicClawWriter::field(const char *key, BString<L> *val) {
|
||||
Error OrganicClawWriter::field(const char *key, const BString<L> *val) noexcept {
|
||||
return field(key, SerStr(val->data(), val->cap()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, T *val) {
|
||||
Error OrganicClawWriter::field(const char *key, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
return field(key, val->data(), val->size());
|
||||
} else if (val && targetValid()) {
|
||||
@ -118,7 +119,7 @@ Error OrganicClawWriter::field(const char *key, T *val) {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
Error OrganicClawWriter::field(const char *key, UnionView<U> val) {
|
||||
Error OrganicClawWriter::field(const char *key, UnionView<U> val) noexcept {
|
||||
if (targetValid()) {
|
||||
OrganicClawWriter w(val.idx());
|
||||
oxReturnError(model(&w, val.get()));
|
||||
@ -131,7 +132,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U> val) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, HashMap<String, T> *val) {
|
||||
Error OrganicClawWriter::field(const char *key, const HashMap<String, T> *val) noexcept {
|
||||
if (targetValid()) {
|
||||
const auto &keys = val->keys();
|
||||
OrganicClawWriter w;
|
||||
@ -146,8 +147,9 @@ Error OrganicClawWriter::field(const char *key, HashMap<String, T> *val) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result<Buffer> writeOC(T *val) {
|
||||
Result<Buffer> writeOC(T *val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
writer.template setTypeInfo<T>();
|
||||
oxReturnError(model(&writer, val));
|
||||
Json::StreamWriterBuilder jsonBuilder;
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
|
Loading…
Reference in New Issue
Block a user