// Copyright (c) 2025 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef MP_PROXY_TYPE_NUMBER_H #define MP_PROXY_TYPE_NUMBER_H #include namespace mp { template LocalType BuildPrimitive(InvokeContext& invoke_context, const Value& value, TypeList, typename std::enable_if::value>::type* enable = nullptr) { using E = std::make_unsigned_t>; using T = std::make_unsigned_t; static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "mismatched integral/enum types"); return static_cast(value); } template LocalType BuildPrimitive(InvokeContext& invoke_context, const Value& value, TypeList, typename std::enable_if::value, int>::type* enable = nullptr) { static_assert( std::numeric_limits::lowest() <= std::numeric_limits::lowest(), "mismatched integral types"); static_assert( std::numeric_limits::max() >= std::numeric_limits::max(), "mismatched integral types"); return value; } template LocalType BuildPrimitive(InvokeContext& invoke_context, const Value& value, TypeList, typename std::enable_if::value>::type* enable = nullptr) { static_assert(std::is_same::value, "mismatched floating point types. please fix message.capnp type declaration to match wrapped interface"); return value; } template decltype(auto) CustomReadField(TypeList, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest, typename std::enable_if::value>::type* enable = 0) { return read_dest.construct(static_cast(input.get())); } template decltype(auto) CustomReadField(TypeList, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest, typename std::enable_if::value>::type* enable = nullptr) { auto value = input.get(); if (value < std::numeric_limits::min() || value > std::numeric_limits::max()) { throw std::range_error("out of bound int received"); } return read_dest.construct(static_cast(value)); } template decltype(auto) CustomReadField(TypeList, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest, typename std::enable_if::value>::type* enable = 0) { auto value = input.get(); static_assert(std::is_same::value, "floating point type mismatch"); return read_dest.construct(value); } } // namespace mp #endif // MP_PROXY_TYPE_NUMBER_H