Kagome
Polkadot Runtime Engine in C++17
arithmetic_error.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_PRIMITIVES_ARITHMETIC_ERROR_HPP
7 #define KAGOME_CORE_PRIMITIVES_ARITHMETIC_ERROR_HPP
8 
9 #include <cstdint>
10 
11 #include "outcome/outcome.hpp"
12 
13 namespace kagome::primitives {
14 
15  enum class ArithmeticError : uint8_t {
17  Underflow = 1,
19  Overflow,
22  };
23 
24  template <class Stream,
25  typename = std::enable_if_t<Stream::is_encoder_stream>>
27  // index shift is required for compatibility with rust implementation.
28  // std::error_code policy preserves 0 index for success cases.
29  return s << static_cast<uint8_t>(v) - 1;
30  }
31 
32  template <class Stream,
33  typename = std::enable_if_t<Stream::is_decoder_stream>>
34  Stream &operator>>(Stream &s, ArithmeticError &v) {
35  uint8_t value = 0u;
36  s >> value;
37  // index shift is required for compatibility with rust implementation.
38  // std::error_code policy preserves 0 index for success cases.
39  ++value;
40  v = static_cast<ArithmeticError>(value);
41  return s;
42  }
43 
44 } // namespace kagome::primitives
45 
47 
48 #endif // KAGOME_CORE_PRIMITIVES_ARITHMETIC_ERROR_HPP
Stream & operator>>(Stream &s, ArithmeticError &v)
OUTCOME_HPP_DECLARE_ERROR(kagome::primitives, ArithmeticError)
Stream & operator<<(Stream &s, const ArithmeticError &v)
libp2p::connection::Stream Stream