// Copyright 2023 The Ray Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include // TODO(Larry Lian) Adapt on windows #ifndef _WIN32 namespace msgpack { namespace adaptor { template <> struct pack { template msgpack::packer &operator()(msgpack::packer &o, const std::any &v) const { const auto &any_type = v.type(); if (any_type == typeid(msgpack::type::nil_t)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(bool)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(uint64_t)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(int64_t)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(double)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(std::string)) { o.pack(std::any_cast(v)); } else if (any_type == typeid(std::vector)) { o.pack(std::any_cast>(v)); } else { throw msgpack::type_error(); } return o; } }; template <> struct convert { msgpack::object const &operator()(msgpack::object const &o, std::any &v) const { switch (o.type) { case type::NIL: v = o.as(); break; case type::BOOLEAN: v = o.as(); break; case type::POSITIVE_INTEGER: v = o.as(); break; case type::NEGATIVE_INTEGER: v = o.as(); break; case type::FLOAT32: case type::FLOAT64: v = o.as(); break; case type::STR: v = o.as(); break; case type::BIN: v = o.as>(); break; default: throw msgpack::type_error(); } return o; } }; } // namespace adaptor } // namespace msgpack #endif