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
67
68
69
70
71
72
73
use std::convert::TryFrom;
use crate::error::{Error, Result};
macro_rules! build_codec_enum {
{$( #[$attr:meta] $code:expr => $codec:ident, )*} => {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Hash)]
pub enum Codec {
$( #[$attr] $codec, )*
}
impl TryFrom<u64> for Codec {
type Error = Error;
fn try_from(raw: u64) -> Result<Codec> {
match raw {
$( $code => Ok(Self::$codec), )*
_ => Err(Error::UnknownCodec),
}
}
}
impl From<Codec> for u64 {
fn from(codec: Codec) -> u64 {
match codec {
$( Codec::$codec => $code, )*
}
}
}
}
}
build_codec_enum! {
0x55 => Raw,
0x70 => DagProtobuf,
0x71 => DagCBOR,
0x78 => GitRaw,
0x90 => EthereumBlock,
0x91 => EthereumBlockList,
0x92 => EthereumTxTrie,
0x93 => EthereumTx,
0x94 => EthereumTxReceiptTrie,
0x95 => EthereumTxReceipt,
0x96 => EthereumStateTrie,
0x97 => EthereumAccountSnapshot,
0x98 => EthereumStorageTrie,
0xb0 => BitcoinBlock,
0xb1 => BitcoinTx,
0xc0 => ZcashBlock,
0xc1 => ZcashTx,
0x0129 => DagJSON,
}