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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::Error;

macro_rules! build_codec_enum {
    {$( $val:expr => $var:ident, )*} => {
        #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
        pub enum Codec {
            $( $var, )*
        }

        use Codec::*;

        impl Codec {
            /// Convert a number to the matching codec
            pub fn from(raw: u64) -> Result<Codec, Error> {
                match raw {
                    $( $val => Ok($var), )*
                    _ => Err(Error::UnknownCodec),
                }
            }
        }

        impl From<Codec> for u64 {
            /// Convert to the matching integer code
            fn from(codec: Codec) -> u64 {
                match codec {
                    $( $var => $val, )*

                }
            }
        }
    }
}

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,
    0x101 => FilCommitmentUnsealed,
    0x102 => FilCommitmentSealed,
    0x0129 => DagJSON,
}