Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/virto-network/scales
SCALE Serialization
https://github.com/virto-network/scales
Last synced: about 1 month ago
JSON representation
SCALE Serialization
- Host: GitHub
- URL: https://github.com/virto-network/scales
- Owner: virto-network
- License: apache-2.0
- Archived: true
- Created: 2021-06-18T13:09:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-17T17:18:49.000Z (11 months ago)
- Last Synced: 2024-03-18T15:14:53.837Z (9 months ago)
- Language: Rust
- Homepage:
- Size: 72.3 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-substrate - Scales - Serializing SCALE using type information from a type registry. (SCALE Codec)
- awesome-substrate - Scales - Serializing SCALE using type information from a type registry. (SCALE Codec)
README
> ⚠️ SCALES is moving to the [VirtoSDK](https://github.com/virto-network/virto-sdk)
# scales - SCALE Serialization
Making use of [type information](https://github.com/paritytech/scale-info) this library allows
conversion to/from [SCALE](https://github.com/paritytech/parity-scale-codec) encoded data,
specially useful when conversion is for dynamic types like JSON.### From SCALE
`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.```rust
let value = scales::Value::new(scale_binary_data, type_id, &type_registry);
serde_json::to_string(value)?;
```### To SCALE
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.```rust
// 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));
```