1#![cfg_attr(not(feature = "std"), no_std)]
12
13#[doc(hidden)]
14pub extern crate susy_codec as codec;
15
16#[macro_export]
18macro_rules! impl_uint_codec {
19 ($name: ident, $len: expr) => {
20 impl $crate::codec::Encode for $name {
21 fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
22 let mut bytes = [0u8; $len * 8];
23 self.to_little_endian(&mut bytes);
24 bytes.using_encoded(f)
25 }
26 }
27
28 impl $crate::codec::Decode for $name {
29 fn decode<I: $crate::codec::Input>(input: &mut I) -> Option<Self> {
30 <[u8; $len * 8] as $crate::codec::Decode>::decode(input)
31 .map(|b| $name::from_little_endian(&b))
32 }
33 }
34 }
35}
36
37#[macro_export]
39macro_rules! impl_fixed_hash_codec {
40 ($name: ident, $len: expr) => {
41 impl $crate::codec::Encode for $name {
42 fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
43 self.0.using_encoded(f)
44 }
45 }
46 impl $crate::codec::Decode for $name {
47 fn decode<I: $crate::codec::Input>(input: &mut I) -> Option<Self> {
48 <[u8; $len] as $crate::codec::Decode>::decode(input).map($name)
49 }
50 }
51 }
52}