mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
Refactored Slicable (#324)
* Refactored Slicable * Docs * Wasm build * Wasm build * Renamed traits * Review nits * Renamed Slicable as well
This commit is contained in:
committed by
Gav Wood
parent
b45020175a
commit
1aeb2825af
@@ -31,7 +31,7 @@ use std::collections::hash_map::{HashMap, Entry};
|
||||
use std::hash::Hash;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use codec::{Slicable, Input};
|
||||
use codec::{Decode, Encode, Input, Output};
|
||||
|
||||
/// Context for the statement table.
|
||||
pub trait Context {
|
||||
@@ -97,44 +97,43 @@ enum StatementKind {
|
||||
Available = 4,
|
||||
}
|
||||
|
||||
impl<C: Slicable, D: Slicable> Slicable for Statement<C, D> {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
impl<C: Encode, D: Encode> Encode for Statement<C, D> {
|
||||
fn encode_to<T: Output>(&self, dest: &mut T) {
|
||||
match *self {
|
||||
Statement::Candidate(ref candidate) => {
|
||||
v.push(StatementKind::Candidate as u8);
|
||||
candidate.using_encoded(|s| v.extend(s));
|
||||
dest.push_byte(StatementKind::Candidate as u8);
|
||||
dest.push(candidate);
|
||||
}
|
||||
Statement::Valid(ref digest) => {
|
||||
v.push(StatementKind::Valid as u8);
|
||||
digest.using_encoded(|s| v.extend(s));
|
||||
dest.push_byte(StatementKind::Valid as u8);
|
||||
dest.push(digest);
|
||||
}
|
||||
Statement::Invalid(ref digest) => {
|
||||
v.push(StatementKind::Invalid as u8);
|
||||
digest.using_encoded(|s| v.extend(s));
|
||||
dest.push_byte(StatementKind::Invalid as u8);
|
||||
dest.push(digest);
|
||||
}
|
||||
Statement::Available(ref digest) => {
|
||||
v.push(StatementKind::Available as u8);
|
||||
digest.using_encoded(|s| v.extend(s));
|
||||
dest.push_byte(StatementKind::Available as u8);
|
||||
dest.push(digest);
|
||||
}
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Decode, D: Decode> Decode for Statement<C, D> {
|
||||
fn decode<I: Input>(value: &mut I) -> Option<Self> {
|
||||
match value.read_byte() {
|
||||
Some(x) if x == StatementKind::Candidate as u8 => {
|
||||
Slicable::decode(value).map(Statement::Candidate)
|
||||
Decode::decode(value).map(Statement::Candidate)
|
||||
}
|
||||
Some(x) if x == StatementKind::Valid as u8 => {
|
||||
Slicable::decode(value).map(Statement::Valid)
|
||||
Decode::decode(value).map(Statement::Valid)
|
||||
}
|
||||
Some(x) if x == StatementKind::Invalid as u8 => {
|
||||
Slicable::decode(value).map(Statement::Invalid)
|
||||
Decode::decode(value).map(Statement::Invalid)
|
||||
}
|
||||
Some(x) if x == StatementKind::Available as u8 => {
|
||||
Slicable::decode(value).map(Statement::Available)
|
||||
Decode::decode(value).map(Statement::Available)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user