| Crates.io | scale-serialization |
| lib.rs | scale-serialization |
| version | 1.0.0-beta2 |
| created_at | 2021-10-04 13:17:13.1885+00 |
| updated_at | 2022-05-03 17:44:30.871366+00 |
| description | SCALE Serialization |
| homepage | |
| repository | https://github.com/virto-network/scales |
| max_upload_size | |
| id | 460121 |
| size | 77,858 |
Making use of type information this library allows conversion to/from SCALE encoded data, specially useful when conversion is for dynamic types like JSON.
scales::Value wraps the raw SCALE binary data and the type id within type registry
giving you an object that can be serialized to any compatible format.
let value = scales::Value::new(scale_binary_data, type_id, &type_registry);
serde_json::to_string(value)?;
Public methods from the scales::serializer::* module(feature experimental-serializer)
allow for a best effort conversion of dynamic types(e.g. serde_json::Value) to SCALE
binary format. The serializer tries to be smart when interpreting the input and convert it
to the desired format dictated by the provided type in the registry.
// simple conversion
let scale_data = to_vec(some_serializable_input); // or to_bytes(&mut bytes, input);
// with type info
let scale_data = to_vec_with_info(input, Some((®istry, type_id)));
// from an unordered list of properties that make an object
let input = vec![("prop_b", 123), ("prop_a", 456)];
let scale_data = to_vec_from_iter(input, (®istry, type_id));