#![cfg_attr(not(feature = "std"), no_std)]
#[doc(hidden)]
pub use parity_scale_codec as codec;
#[macro_export]
macro_rules! impl_uint_codec {
($name: ident, $len: expr) => {
impl $crate::codec::Encode for $name {
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
let mut bytes = [0u8; $len * 8];
self.to_little_endian(&mut bytes);
bytes.using_encoded(f)
}
}
impl $crate::codec::EncodeLike for $name {}
impl $crate::codec::Decode for $name {
fn decode<I: $crate::codec::Input>(input: &mut I) -> core::result::Result<Self, $crate::codec::Error> {
<[u8; $len * 8] as $crate::codec::Decode>::decode(input).map(|b| $name::from_little_endian(&b))
}
}
impl $crate::codec::MaxEncodedLen for $name {
fn max_encoded_len() -> usize {
::core::mem::size_of::<$name>()
}
}
};
}
#[macro_export]
macro_rules! impl_fixed_hash_codec {
($name: ident, $len: expr) => {
impl $crate::codec::Encode for $name {
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.0.using_encoded(f)
}
}
impl $crate::codec::EncodeLike for $name {}
impl $crate::codec::Decode for $name {
fn decode<I: $crate::codec::Input>(input: &mut I) -> core::result::Result<Self, $crate::codec::Error> {
<[u8; $len] as $crate::codec::Decode>::decode(input).map($name)
}
}
impl $crate::codec::MaxEncodedLen for $name {
fn max_encoded_len() -> usize {
::core::mem::size_of::<$name>()
}
}
};
}