From 396fecab5b836096ac7855bc0c16edc0ea2bf88f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 27 Sep 2024 02:31:08 -0500 Subject: [PATCH] [ox/oc] Add option for writeOC to return a string --- deps/ox/src/ox/oc/write.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/deps/ox/src/ox/oc/write.hpp b/deps/ox/src/ox/oc/write.hpp index 10489e39..105f272c 100644 --- a/deps/ox/src/ox/oc/write.hpp +++ b/deps/ox/src/ox/oc/write.hpp @@ -24,7 +24,9 @@ namespace ox { class OrganicClawWriter { - friend Result writeOC(const auto &val) noexcept; + template + friend Result writeOC(const auto &val) noexcept + requires(ox::is_same_v || ox::is_same_v); protected: Json::Value m_json{Json::Value(Json::objectValue)}; @@ -247,14 +249,17 @@ Error OrganicClawWriter::field(const char *key, UnionView val) noexcep return OxError(0); } -Result writeOC(const auto &val) noexcept { +template +Result writeOC(const auto &val) noexcept + requires(ox::is_same_v || ox::is_same_v) { OrganicClawWriter writer; ModelHandlerInterface handler(&writer); oxReturnError(model(&handler, &val)); - Json::StreamWriterBuilder jsonBuilder; + Json::StreamWriterBuilder const jsonBuilder; const auto str = Json::writeString(jsonBuilder, writer.m_json); - Buffer buff(str.size() + 1); - memcpy(buff.data(), str.c_str(), str.size() + 1); + Result buff; + buff.value.resize(str.size() + ox::is_same_v); + memcpy(buff.value.data(), str.data(), str.size() + 1); return buff; }