// Glaze Library // For the license information refer to glaze.hpp #pragma once #include #include "glaze/cbor/read.hpp" #include "glaze/cbor/write.hpp" #include "glaze/core/custom.hpp" #include "glaze/core/opts.hpp" #include "glaze/core/wrappers.hpp" namespace glz { template struct from { template GLZ_ALWAYS_INLINE static void op(auto&& value, auto&&... args) { parse::op>(value.val, args...); } }; template struct to { template GLZ_ALWAYS_INLINE static void op(auto&& value, is_context auto&& ctx, auto&&... args) { serialize::op>(value.val, ctx, args...); } }; // max_length wrapper for limiting string/array sizes when reading template struct from> { private: template static consteval auto make_limited_opts() { if constexpr (str_t) { if constexpr (requires { Opts.max_string_length; }) { auto ret = Opts; ret.max_string_length = MaxLen; return ret; } else { struct extended : std::decay_t { size_t max_string_length = MaxLen; }; return extended{Opts}; } } else if constexpr (readable_array_t) { if constexpr (requires { Opts.max_array_size; }) { auto ret = Opts; ret.max_array_size = MaxLen; return ret; } else { struct extended : std::decay_t { size_t max_array_size = MaxLen; }; return extended{Opts}; } } else { return Opts; } } public: template GLZ_ALWAYS_INLINE static void op(auto&& wrapper, is_context auto&& ctx, auto&& it, auto end) { constexpr auto limited = make_limited_opts(); from::template op(wrapper.val, ctx, it, end); } }; // max_length wrapper for writing (just passes through without modification) template struct to> { template GLZ_ALWAYS_INLINE static void op(auto&& wrapper, is_context auto&& ctx, auto&&... args) { to::template op(wrapper.val, ctx, args...); } }; }