Enum scrypto::prelude::radix_engine_common::prelude::representations::serde_serialization::SerializationMode
source · pub enum SerializationMode {
Programmatic,
Model,
Natural,
}
Variants§
Programmatic
The “(Annotated) Programmatic” encoding is a default invertible API format which captures the SBOR value model, and supports optional name annotations from a schema.
SBOR values are generally wrapped in an object with a “kind” field. Fields are output as an array to faithfully represent the ordering in the SBOR value.
If a schema is available, variant names, type names and field names are added to the output.
If value/type data is included in the parent (Vecs and Map entries), it is still duplicated on the child object for simplicity.
Model
==THIS FORMAT IS DEPRECATED - BUT KEPT FOR THE TIME BEING FOR NODE COMPATIBILITY==
This “Model” encoding is intended to exactly capture the content of the scrypto value, in a way which can be inverted back into a scrypto value.
SBOR values are generally wrapped in an object with a “kind” field. Fields are output as an array to faithfully represent the ordering in the SBOR value.
It is more compact than the Programmatic format, but more complex to describe, because children of arrays/maps are not wrapped in a JSON object with the kind field.
If value/type data is included in the parent (Vecs and Map entries), it is not duplicated on the values. This avoids duplication in the output. In these cases, child tuples and single values lose their wrapper object, to keep the output concise. Other values keep their wrapper object, as there are other fields to convey.
If a schema is available, variant names, type names and field names are added to the output.
Natural
==THIS FORMAT IS NOT INTENDED TO BE USED YET==
An API format designed for elegantly reading values with a well-known schema - intended for eg DApp Builders writing their front-ends.
It outputs values in a “JSON-native” manner - designed primary for use with a schema, and for mapping into models like you’d find on an Open API schema.
Its JSON schema is dependent on its SBOR schema, and it’s not intended to be invertible without the SBOR schema. We could even consider generating an Open API schema for a given SBOR schema (eg for a blueprint) and allow developers to have a strongly-typed API to their blueprint.
Compared with Programmatic, it is more compact, but doesn’t include type names / enum variant names.
It should favour simplicity for human comprehension, in particular:
- It uses a JSON object rather than an array where possible, even if this loses field ordering EG for structs, and for maps with string keys.
- If the concept which is being represented (eg number/amount or address) is clear to a human, information about the value kind is dropped.
- It prefers to use the JSON number type where the number can be confirmed to be <= JS max safe int.
Trait Implementations§
source§impl Clone for SerializationMode
impl Clone for SerializationMode
source§fn clone(&self) -> SerializationMode
fn clone(&self) -> SerializationMode
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SerializationMode
impl Debug for SerializationMode
source§impl PartialEq for SerializationMode
impl PartialEq for SerializationMode
source§fn eq(&self, other: &SerializationMode) -> bool
fn eq(&self, other: &SerializationMode) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for SerializationMode
impl Eq for SerializationMode
impl StructuralPartialEq for SerializationMode
Auto Trait Implementations§
impl RefUnwindSafe for SerializationMode
impl Send for SerializationMode
impl Sync for SerializationMode
impl Unpin for SerializationMode
impl UnwindSafe for SerializationMode
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.