Update to parity-scale-codec (#3232)

* WIP: update codec

* WIP

* compiling

* WIP

* rename parity-scale-codec to codec

* WIP

* fix

* remove old comments

* use published crates

* fix expected error msg

* bump version

* fmt and fix

* remove old comment

* fix wrong decoding impl

* implement encode like for structures

* undo removal of old pending changes

* trailingzeroinput

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* update codec

* fmt

* version is 1.0.0

* show more error

* fmt
This commit is contained in:
thiolliere
2019-08-06 19:36:23 +02:00
committed by Bastian Köcher
parent a0d442333f
commit 4ed67e03a4
211 changed files with 867 additions and 682 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }
rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false }
primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false }
@@ -13,7 +13,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives",
[features]
default = ["std"]
std = [
"parity-codec/std",
"codec/std",
"rstd/std",
"primitives/std",
"serde",
+15 -7
View File
@@ -25,8 +25,8 @@
#[cfg(feature = "std")]
use serde::Serialize;
#[cfg(feature = "std")]
use parity_codec::{Decode, Input};
use parity_codec::{Encode, Output};
use codec::{Decode, Input, Error};
use codec::{Encode, Output};
use rstd::vec::Vec;
#[cfg(feature = "std")]
@@ -59,11 +59,13 @@ impl<B, O> Encode for DecodeDifferent<B, O> where B: Encode + 'static, O: Encode
}
}
impl<B, O> codec::EncodeLike for DecodeDifferent<B, O> where B: Encode + 'static, O: Encode + 'static {}
#[cfg(feature = "std")]
impl<B, O> Decode for DecodeDifferent<B, O> where B: 'static, O: Decode + 'static {
fn decode<I: Input>(input: &mut I) -> Option<Self> {
<O>::decode(input).and_then(|val| {
Some(DecodeDifferent::Decoded(val))
fn decode<I: Input>(input: &mut I) -> Result<Self, Error> {
<O>::decode(input).map(|val| {
DecodeDifferent::Decoded(val)
})
}
}
@@ -144,6 +146,8 @@ impl<E: Encode> Encode for FnEncode<E> {
}
}
impl<E: Encode> codec::EncodeLike for FnEncode<E> {}
impl<E: Encode + PartialEq> PartialEq for FnEncode<E> {
fn eq(&self, other: &Self) -> bool {
self.0().eq(&other.0())
@@ -223,6 +227,8 @@ impl Encode for DefaultByteGetter {
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
@@ -333,10 +339,12 @@ impl Encode for RuntimeMetadataDeprecated {
fn encode_to<W: Output>(&self, _dest: &mut W) {}
}
impl codec::EncodeLike for RuntimeMetadataDeprecated {}
#[cfg(feature = "std")]
impl Decode for RuntimeMetadataDeprecated {
fn decode<I: Input>(_input: &mut I) -> Option<Self> {
unimplemented!()
fn decode<I: Input>(_input: &mut I) -> Result<Self, Error> {
Err("Decoding is not supported".into())
}
}