From 74f76ace81dc050a3dfd2cc0df282be103a5a0dc Mon Sep 17 00:00:00 2001 From: Borislav Stanimirov Date: Tue, 3 Dec 2024 16:32:58 +0200 Subject: [PATCH] feat(schema): support binary, ref #149 --- schema/code/ac/schema/IOVisitors.hpp | 9 +++++++++ schema/code/ac/schema/SchemaVisitor.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/schema/code/ac/schema/IOVisitors.hpp b/schema/code/ac/schema/IOVisitors.hpp index 3cade3b2..ed8048f6 100644 --- a/schema/code/ac/schema/IOVisitors.hpp +++ b/schema/code/ac/schema/IOVisitors.hpp @@ -39,6 +39,11 @@ struct ToDictVisitor { out = astl::move(value); } + template + static void writeToDict(Dict& out, Blob& value) { + out = ac::Dict::binary(std::move(Blob)); + } + template static void writeToDict(Dict& out, std::vector& value) { out = Dict::array(); @@ -88,6 +93,10 @@ struct FromDictVisitor { value = astl::move(in.get_ref()); } + static void readFromDict(Dict& in, Blob& value) { + value = Blob{std::move(in.get_binary())}; + } + template static void readFromDict(Dict& in, std::vector& value) { value.clear(); diff --git a/schema/code/ac/schema/SchemaVisitor.hpp b/schema/code/ac/schema/SchemaVisitor.hpp index 99b2fa18..0e3329ef 100644 --- a/schema/code/ac/schema/SchemaVisitor.hpp +++ b/schema/code/ac/schema/SchemaVisitor.hpp @@ -46,6 +46,9 @@ struct SchemaVisitor { T schema; schema.visitFields(v); } + else if constexpr (std::same_as) { + obj["type"] = "binary"; + } else { // assume array obj["type"] = "array";