forked from qdrvm/kagome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunused.hpp
66 lines (54 loc) · 1.64 KB
/
unused.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <cstdint>
#include <qtils/enum_error_code.hpp>
#include "common/empty.hpp"
#include "common/tagged.hpp"
namespace kagome {
enum UnusedError : uint8_t {
AttemptToEncodeUnused = 1,
AttemptToDecodeUnused,
};
Q_ENUM_ERROR_CODE(UnusedError) {
using E = decltype(e);
switch (e) {
case E::AttemptToEncodeUnused:
return "AttemptToEncodeUnused";
case E::AttemptToDecodeUnused:
return "AttemptToDecodeUnused";
}
abort();
}
/// Number-based marker-type for using as tag
template <size_t Num>
struct NumTag {
private:
static constexpr size_t tag = Num;
};
/// Special zero-size-type for some things
/// (e.g., dummy types of variant, unsupported or experimental).
template <size_t N>
using Unused = Tagged<Empty, NumTag<N>>;
template <size_t N>
constexpr bool operator==(const Unused<N> &, const Unused<N> &) {
return true;
}
/// To raise failure while attempt to encode unused entity
template <size_t N>
inline ::scale::ScaleEncoderStream &operator<<(::scale::ScaleEncoderStream &s,
const Unused<N> &) {
::scale::raise(UnusedError::AttemptToEncodeUnused);
return s;
}
/// To raise failure while attempt to decode unused entity
template <size_t N>
inline ::scale::ScaleDecoderStream &operator>>(::scale::ScaleDecoderStream &s,
const Unused<N> &) {
::scale::raise(UnusedError::AttemptToDecodeUnused);
return s;
}
} // namespace kagome