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
use ckb_fixed_hash::H256;
use ckb_occupied_capacity::Capacity;
use numext_fixed_uint::U256;

use crate::{packed, prelude::*};

impl Pack<packed::Uint64> for Capacity {
    fn pack(&self) -> packed::Uint64 {
        self.as_u64().pack()
    }
}

impl<'r> Unpack<Capacity> for packed::Uint64Reader<'r> {
    fn unpack(&self) -> Capacity {
        Capacity::shannons(self.unpack())
    }
}
impl_conversion_for_entity_unpack!(Capacity, Uint64);

impl Pack<packed::Uint256> for U256 {
    fn pack(&self) -> packed::Uint256 {
        packed::Uint256::from_slice(&self.to_le_bytes()[..]).expect("impossible: fail to pack U256")
    }
}

impl<'r> Unpack<U256> for packed::Uint256Reader<'r> {
    fn unpack(&self) -> U256 {
        U256::from_little_endian(self.as_slice()).expect("internal error: fail to unpack U256")
    }
}
impl_conversion_for_entity_unpack!(U256, Uint256);

impl Pack<packed::Byte32> for H256 {
    fn pack(&self) -> packed::Byte32 {
        packed::Byte32::from_slice(self.as_bytes()).expect("impossible: fail to pack H256")
    }
}

impl<'r> Unpack<H256> for packed::Byte32Reader<'r> {
    fn unpack(&self) -> H256 {
        H256::from_slice(self.as_slice()).expect("internal error: fail to unpack H256")
    }
}
impl_conversion_for_entity_unpack!(H256, Byte32);

impl_conversion_for_option!(H256, Byte32Opt, Byte32OptReader);
impl_conversion_for_vector!(Capacity, Uint64Vec, Uint64VecReader);