5#ifndef MP_PROXY_TYPE_NUMBER_H
6#define MP_PROXY_TYPE_NUMBER_H
11template <
typename LocalType,
typename Value>
15 typename std::enable_if<std::is_enum<Value>::value>::type* enable =
nullptr)
17 using E = std::make_unsigned_t<std::underlying_type_t<Value>>;
18 using T = std::make_unsigned_t<LocalType>;
19 static_assert(std::numeric_limits<T>::max() >= std::numeric_limits<E>::max(),
"mismatched integral/enum types");
20 return static_cast<LocalType
>(value);
23template <
typename LocalType,
typename Value>
27 typename std::enable_if<std::is_integral<Value>::value,
int>::type* enable =
nullptr)
30 std::numeric_limits<LocalType>::lowest() <= std::numeric_limits<Value>::lowest(),
"mismatched integral types");
32 std::numeric_limits<LocalType>::max() >= std::numeric_limits<Value>::max(),
"mismatched integral types");
36template <
typename LocalType,
typename Value>
40 typename std::enable_if<std::is_floating_point<Value>::value>::type* enable =
nullptr)
42 static_assert(std::is_same<Value, LocalType>::value,
43 "mismatched floating point types. please fix message.capnp type declaration to match wrapped interface");
47template <
typename LocalType,
typename Input,
typename ReadDest>
53 typename std::enable_if<std::is_enum<LocalType>::value>::type* enable = 0)
55 return read_dest.construct(
static_cast<LocalType
>(input.get()));
58template <
typename LocalType,
typename Input,
typename ReadDest>
64 typename std::enable_if<std::is_integral<LocalType>::value>::type* enable =
nullptr)
66 auto value = input.get();
67 if (value < std::numeric_limits<LocalType>::min() || value > std::numeric_limits<LocalType>::max()) {
68 throw std::range_error(
"out of bound int received");
70 return read_dest.construct(
static_cast<LocalType
>(value));
73template <
typename LocalType,
typename Input,
typename ReadDest>
79 typename std::enable_if<std::is_floating_point<LocalType>::value>::type* enable = 0)
81 auto value = input.get();
82 static_assert(std::is_same<LocalType,
decltype(value)>::value,
"floating point type mismatch");
83 return read_dest.construct(value);
#define T(expected, seed, data)
Functions to serialize / deserialize common bitcoin types.
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
LocalType BuildPrimitive(InvokeContext &invoke_context, const Value &value, TypeList< LocalType >, typename std::enable_if< std::is_enum< Value >::value >::type *enable=nullptr)
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Generic utility functions used by capnp code.