| 480 | } |
| 481 | |
| 482 | template <typename Stream, typename I> void Unser(Stream& s, I& v) |
| 483 | { |
| 484 | using U = typename std::conditional<std::is_enum<I>::value, std::underlying_type<I>, std::common_type<I>>::type::type; |
| 485 | static_assert(std::numeric_limits<U>::max() >= MAX && std::numeric_limits<U>::min() <= 0, "Assigned type too small"); |
| 486 | uint64_t raw = 0; |
| 487 | if (BigEndian) { |
| 488 | s.read({BytePtr(&raw) + 8 - Bytes, Bytes}); |
| 489 | v = static_cast<I>(be64toh(raw)); |
| 490 | } else { |
| 491 | s.read({BytePtr(&raw), Bytes}); |
| 492 | v = static_cast<I>(le64toh(raw)); |
| 493 | } |
| 494 | } |
| 495 | }; |
| 496 | |
| 497 | template<int Bytes> using BigEndianFormatter = CustomUintFormatter<Bytes, true>; |