[ox/oc] Add option for writeOC to return a string
This commit is contained in:
parent
5373b63cca
commit
396fecab5b
15
deps/ox/src/ox/oc/write.hpp
vendored
15
deps/ox/src/ox/oc/write.hpp
vendored
@ -24,7 +24,9 @@ namespace ox {
|
||||
|
||||
class OrganicClawWriter {
|
||||
|
||||
friend Result<Buffer> writeOC(const auto &val) noexcept;
|
||||
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>);
|
||||
|
||||
protected:
|
||||
Json::Value m_json{Json::Value(Json::objectValue)};
|
||||
@ -247,14 +249,17 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Result<Buffer> writeOC(const auto &val) noexcept {
|
||||
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>) {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> 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<T> buff;
|
||||
buff.value.resize(str.size() + ox::is_same_v<T, ox::Buffer>);
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user