6 #ifndef KAGOME_CORE_PRIMITIVES_COMMON_HPP 7 #define KAGOME_CORE_PRIMITIVES_COMMON_HPP 11 #include <fmt/format.h> 12 #include <boost/operators.hpp> 25 template <
typename Tag>
26 struct BlockInfoT :
public boost::equality_comparable<BlockInfoT<Tag>>,
27 public boost::less_than_comparable<BlockInfoT<Tag>> {
43 bool operator<(const BlockInfoT<Tag> &o)
const {
50 typename = std::enable_if_t<Stream::is_encoder_stream>>
51 Stream &operator<<(Stream &s, const BlockInfoT<Tag> &msg) {
52 return s << msg.hash << msg.number;
57 typename = std::enable_if_t<Stream::is_decoder_stream>>
67 template <
typename Tag>
68 struct fmt::formatter<
kagome::primitives::detail::BlockInfoT<Tag>> {
70 char presentation =
's';
73 constexpr
auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
75 auto it = ctx.begin(), end = ctx.end();
76 if (it != end && (*it ==
's' || *it ==
'l')) {
81 if (it != end && *it !=
'}') {
82 throw format_error(
"invalid format");
91 template <
typename FormatContext>
93 FormatContext &ctx) -> decltype(ctx.out()) {
96 if (presentation ==
's') {
97 static_assert(decltype(block_info.hash)::size() > 4);
100 "#{} (0x{:04x}…{:04x})",
103 htobe16(*reinterpret_cast<const uint16_t *>(block_info.hash.data())),
105 htobe16(*reinterpret_cast<const uint16_t *>(block_info.hash.data()
106 + block_info.hash.size()
107 -
sizeof(uint16_t))));
111 ctx.out(),
"#{} (0x{})", block_info.number, block_info.hash.toHex());
115 #endif // KAGOME_CORE_PRIMITIVES_COMMON_HPP
Stream & operator>>(Stream &s, BlockInfoT< Tag > &msg)
bool operator==(const BlockInfoT< Tag > &o) const
BlockInfoT(const BlockNumber &n, const BlockHash &h)
BlockInfoT(const BlockHash &h, const BlockNumber &n)
libp2p::connection::Stream Stream