Module soroban_sdk::xdr
source · Expand description
Convert values to and from Bytes.
All types that are convertible to and from Val implement the ToXdr and FromXdr traits, and serialize to the ScVal XDR form.
Examples
use soroban_sdk::{
xdr::{FromXdr, ToXdr},
Env, Bytes, IntoVal, TryFromVal,
};
let env = Env::default();
let value: u32 = 5;
let bytes = value.to_xdr(&env);
assert_eq!(bytes.len(), 8);
let roundtrip = u32::from_xdr(&env, &bytes);
assert_eq!(roundtrip, Ok(value));
Modules
Structs
DepthLimitedRead
wraps aRead
object and enforces a depth limit to recursive read operations. It maintains adepth_remaining
state tracking remaining allowed recursion depth.DepthLimitedWrite
wraps aWrite
object and enforces a depth limit to recursive write operations. It maintains adepth_remaining
state tracking remaining allowed recursion depth.
Enums
- Error contains all errors returned by functions in this crate. It can be compared via
PartialEq
, however any contained IO errors will only be compared on theirErrorKind
.
Constants
- Defines the maximum depth for recursive calls in
Read/WriteXdr
to prevent stack overflow. XDR_FILES_SHA256
is a list of pairs of source files and their SHA256 hashes.
Traits
DepthLimiter
is a trait designed for managing the depth of recursive operations. It provides a mechanism to limit recursion depth, and defines the behavior upon entering and leaving a recursion level.- Discriminant defines types that may contain a one-of value determined according to the discriminant, and exposes the value of the discriminant for that type, such as in an XDR union.
- Implemented by types that can be deserialized from Bytes.
- Name defines types that assign a static name to their value, such as the name given to an identifier in an XDR enum, or the name given to the case in a union.
- Implemented by types that can be serialized to Bytes.
- Iter defines types that have variants that can be iterated.