pub trait Encode {
// Provided methods
fn size_hint(&self) -> usize { ... }
fn encode_to<T>(&self, dest: &mut T)
where T: Output + ?Sized { ... }
fn encode(&self) -> Vec<u8, Global> ⓘ { ... }
fn using_encoded<R, F>(&self, f: F) -> R
where F: FnOnce(&[u8]) -> R { ... }
fn encoded_size(&self) -> usize { ... }
}
Expand description
Trait that allows zero-copy write of value-references to slices in LE format.
Implementations should override using_encoded
for value types and encode_to
and size_hint
for allocating types.
Wrapper types should override all methods.
Provided Methods§
fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding.
This method is used inside default implementation of encode
to avoid re-allocations.
fn encode_to<T>(&self, dest: &mut T)where
T: Output + ?Sized,
fn encode_to<T>(&self, dest: &mut T)where T: Output + ?Sized,
Convert self to a slice and append it to the destination.
fn using_encoded<R, F>(&self, f: F) -> Rwhere
F: FnOnce(&[u8]) -> R,
fn using_encoded<R, F>(&self, f: F) -> Rwhere F: FnOnce(&[u8]) -> R,
Convert self to a slice and then invoke the given closure with it.
fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size.
Should be used when the encoded data isn’t required.
Note
This works by using a special [Output
] that only tracks the size. So, there are no allocations inside the
output. However, this can not prevent allocations that some types are doing inside their own encoding.
Implementations on Foreign Types§
source§impl Encode for TransactionalError
impl Encode for TransactionalError
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for MultiSigner
impl Encode for MultiSigner
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<AccountId, AccountIndex> Encode for MultiAddress<AccountId, AccountIndex>where
AccountId: Encode,
AccountIndex: HasCompact,
impl<AccountId, AccountIndex> Encode for MultiAddress<AccountId, AccountIndex>where AccountId: Encode, AccountIndex: HasCompact,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for OpaqueExtrinsic
impl Encode for OpaqueExtrinsic
source§impl<Address, Call, Signature, Extra> Encode for UncheckedExtrinsic<Address, Call, Signature, Extra>where
Address: Encode,
Signature: Encode,
Call: Encode,
Extra: SignedExtension,
impl<Address, Call, Signature, Extra> Encode for UncheckedExtrinsic<Address, Call, Signature, Extra>where Address: Encode, Signature: Encode, Call: Encode, Extra: SignedExtension,
source§impl<Block> Encode for SignedBlock<Block>where
Block: Encode,
impl<Block> Encode for SignedBlock<Block>where Block: Encode,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<Block> Encode for BlockId<Block>where
Block: Block,
<Block as Block>::Hash: Encode,
<<Block as Block>::Header as Header>::Number: Encode,
impl<Block> Encode for BlockId<Block>where Block: Block, <Block as Block>::Hash: Encode, <<Block as Block>::Header as Header>::Number: Encode,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<Info> Encode for DispatchErrorWithPostInfo<Info>where
Info: Eq + PartialEq<Info> + Clone + Copy + Encode + Decode + Printable,
impl<Info> Encode for DispatchErrorWithPostInfo<Info>where Info: Eq + PartialEq<Info> + Clone + Copy + Encode + Decode + Printable,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<Xt> Encode for ExtrinsicWrapper<Xt>where
Xt: Encode,
impl<Xt> Encode for ExtrinsicWrapper<Xt>where Xt: Encode,
source§impl Encode for TokenError
impl Encode for TokenError
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for TransactionSource
impl Encode for TransactionSource
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<Call, Extra> Encode for TestXt<Call, Extra>where
Option<(u64, Extra)>: Encode,
Call: Encode,
impl<Call, Extra> Encode for TestXt<Call, Extra>where Option<(u64, Extra)>: Encode, Call: Encode,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for AnySignature
impl Encode for AnySignature
source§impl<Xt> Encode for Block<Xt>where
Vec<Xt, Global>: Encode,
impl<Xt> Encode for Block<Xt>where Vec<Xt, Global>: Encode,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for UnknownTransaction
impl Encode for UnknownTransaction
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for TestSignature
impl Encode for TestSignature
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<B> Encode for BlockAndTimeDeadline<B>where
B: BlockNumberProvider,
<B as BlockNumberProvider>::BlockNumber: Encode,
impl<B> Encode for BlockAndTimeDeadline<B>where B: BlockNumberProvider, <B as BlockNumberProvider>::BlockNumber: Encode,
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for ModuleError
impl Encode for ModuleError
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl Encode for BadOrigin
impl Encode for BadOrigin
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )where __CodecOutputEdqy: Output + ?Sized,
source§impl<Call, Extra> Encode for SignedPayload<Call, Extra>where
Call: Encode,
Extra: SignedExtension,
impl<Call, Extra> Encode for SignedPayload<Call, Extra>where Call: Encode, Extra: SignedExtension,
source§fn using_encoded<R, F>(&self, f: F) -> Rwhere
F: FnOnce(&[u8]) -> R,
fn using_encoded<R, F>(&self, f: F) -> Rwhere F: FnOnce(&[u8]) -> R,
Get an encoded version of this payload.
Payloads longer than 256 bytes are going to be blake2_256
-hashed.