pclass: Add value_caster specialization for json to bit integer

This commit is contained in:
Joshua Scott 2018-12-20 15:45:52 +00:00
parent b5559834ac
commit 2dad313885
1 changed files with 18 additions and 0 deletions

View File

@ -183,6 +183,24 @@ namespace detail
}
};
/**
* Caster implementation for casting from json to
* bit integers (bi<N> and bui<N>)
*/
template <uint8_t N, bool Unsigned>
struct value_caster<nlohmann::json, BitInteger<N, Unsigned>>
: value_caster_impl<nlohmann::json, BitInteger<N, Unsigned>>
{
using type = typename BitInteger<N, Unsigned>::type;
BitInteger<N, Unsigned> cast_value(const nlohmann::json &value) const override
{
return BitInteger<N, Unsigned>(
static_cast<type>(value)
);
}
};
/**
* Caster implementation for casting from json to a
* std::string.