//----------------------------------------------------------------------------- // ___ __ _ _ // / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __ // / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ / // / ___/ (_| | | \__ \ __/ /__| | | | | < // \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ . // //----------------------------------------------------------------------------- // Author: Kurt Sassenrath // Module: msgpack // // Extra functionality: fmt formatters for msgpack types. // // Copyright (c) 2023 Kurt Sassenrath. // // License TBD. //----------------------------------------------------------------------------- #ifndef msgpack_extra_formatters_d5fd427a7f749dcb #define msgpack_extra_formatters_d5fd427a7f749dcb #define FMT_VERSION #ifdef FMT_VERSION #include "parselink/msgpack/core/format.h" #include template <> struct fmt::formatter : fmt::formatter { template auto format(msgpack::nil const&, FormatContext& ctx) const noexcept { return fmt::format_to(ctx.out(), "{{msgpack::invalid}}"); }; }; template <> struct fmt::formatter : fmt::formatter { template auto format(msgpack::nil const&, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "{{msgpack::nil}}"); } }; template <> struct fmt::formatter : fmt::formatter { template auto format(msgpack::map_desc const& value, FormatContext& ctx) const { return fmt::format_to( ctx.out(), "{{msgpack::map_desc: {}}}", value.count); } }; template <> struct fmt::formatter : fmt::formatter { template auto format(msgpack::array_desc const& value, FormatContext& ctx) const { return fmt::format_to( ctx.out(), "{{msgpack::array_desc: {}}}", value.count); } }; #ifdef PARSELINK_MSGPACK_TOKEN_API template <> struct fmt::formatter { template constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { return ctx.begin(); } template auto format(msgpack::token const& v, FormatContext& ctx) const { using parselink::logging::themed_arg; auto out = fmt::format_to( ctx.out(), "()))); break; case msgpack::format::type::signed_int: out = fmt::format_to( out, "{}", themed_arg(*(v.get()))); break; case msgpack::format::type::boolean: out = fmt::format_to(out, "{}", themed_arg(*(v.get()))); break; case msgpack::format::type::string: out = fmt::format_to( out, "{}", themed_arg(*(v.get()))); break; case msgpack::format::type::binary: out = fmt::format_to(out, "{}", themed_arg(*(v.get>()))); break; case msgpack::format::type::map: out = fmt::format_to(out, "(arity: {})", themed_arg(v.get()->count)); break; case msgpack::format::type::array: out = fmt::format_to(out, "(arity: {})", themed_arg(v.get()->count)); break; case msgpack::format::type::nil: out = fmt::format_to(out, "(nil)"); break; case msgpack::format::type::invalid: out = fmt::format_to(out, "(invalid)"); break; default: break; } return fmt::format_to(out, ">"); } }; #endif // PARSELINK_MSGPACK_TOKEN_API #endif // FMT_VERSION #endif // msgpack_extra_formatters_d5fd427a7f749dcb