[][src]Crate serde_scale

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. ⚠ It must be enabled if the serde/std feature is enabled by any crate in the dependency tree.
  • alloc: Support for the alloc crate.

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

Structs

Deserializer

Deserializer for the SCALE encoding

EndOfInput

Error indicating that the end of the input was reached and not enough bytes were read

Serializer

Serializer for the SCALE encoding

Enums

Bytes

Bytes borrowed from the deserializer or valid only for the duration of the call to read_map

Error

Serialization errors

Traits

Read

Interface to read bytes

SuperError

Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>. Errors must describe themselves through the Display and Debug traits, and may provide cause chain information:

Write

Interface to write bytes

Functions

from_slice

Deserializes a value encoded with SCALE

to_vec

Serializes a value using the SCALE encoding