[ox/oc] Fix Linux build

This commit is contained in:
Gary Talent 2024-09-27 02:44:25 -05:00
parent bdfb5e972a
commit e8a1ff0643

View File

@ -24,9 +24,8 @@ namespace ox {
class OrganicClawWriter {
template<typename T>
friend Result<T> writeOC(const auto &val) noexcept
requires(ox::is_same_v<T, ox::Buffer> || ox::is_same_v<T, ox::String>);
friend Result<ox::Buffer> writeOC(const auto &val) noexcept;
friend Result<ox::String> writeOCString(const auto &val) noexcept;
protected:
Json::Value m_json{Json::Value(Json::objectValue)};
@ -249,16 +248,26 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
return OxError(0);
}
template<typename T = ox::Buffer>
Result<T> writeOC(const auto &val) noexcept
requires(ox::is_same_v<T, ox::Buffer> || ox::is_same_v<T, ox::String>) {
Result<ox::Buffer> writeOC(const auto &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
oxReturnError(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<T> buff;
buff.value.resize(str.size() + ox::is_same_v<T, ox::Buffer>);
Result<Buffer> buff;
buff.value.resize(str.size() + 1);
memcpy(buff.value.data(), str.data(), str.size() + 1);
return buff;
}
Result<ox::String> writeOCString(const auto &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
oxReturnError(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<ox::String> buff;
buff.value.resize(str.size());
memcpy(buff.value.data(), str.data(), str.size() + 1);
return buff;
}