#serde #scale #serialization #substrate

serde-scale

Serde serializer and deserializer for the SCALE encoding

4 releases

0.2.2 Oct 15, 2020
0.2.1 Oct 8, 2020
0.2.0 Oct 8, 2020
0.1.0 Oct 7, 2020

#632 in Encoding

Download history 112/week @ 2021-10-02 105/week @ 2021-10-09 3/week @ 2021-10-16 7/week @ 2021-10-23 3/week @ 2021-10-30 75/week @ 2021-11-06 47/week @ 2021-11-13 107/week @ 2021-11-20 131/week @ 2021-11-27 58/week @ 2021-12-04 123/week @ 2021-12-11 85/week @ 2021-12-18 155/week @ 2022-01-01 117/week @ 2022-01-08 166/week @ 2022-01-15

465 downloads per month
Used in serde-scale-wrap

Zlib license

52KB
1.5K SLoC

Overview

Serializer and deserializer for the SCALE encoding based on serde.

Example

use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct Point {
    x: i8,
    y: i8,
}

let point = Point { x: 3, y: 4 };
let deserialized = serde_scale::from_slice(&serde_scale::to_vec(&point).unwrap()).unwrap();
assert_eq!(point, deserialized);

Conformance

Option<bool> is serialized as a single byte according to the SCALE encoding.

Features

no_std is supported by disabling default features.

  • std: Support for std. It is enabled by default.
  • alloc: Support for the alloc crate.

๐Ÿ”– Features enabled in build dependencies and proc-macros are also enabled for normal dependencies, which may cause serde to have its std feature on when it is not desired. Nightly cargo prevents this from happening with -Z features=host_dep or the following in .cargo/config:

[unstable]
features = ["host_dep"]

For example, this issue arises when depending on parity-scale-codec-derive.

Test

Most tests live in the serde-scale-tests crate (part of the workspace) in order to avoid dependencies enabling serde features.

cargo test --workspace

Contribute

All contributions shall be licensed under the zlib license.

Related projects

parity-scale-codec: Reference Rust implementation

Dependencies

~0.4โ€“1MB
~23K SLoC

โทˆ_