pub trait AlgorandMsgpack: Serialize + for<'de> Deserialize<'de> {
const PREFIX: &'static [u8] = b"";
// Provided methods
fn encode_raw(&self) -> Result<Vec<u8>, AlgoKitTransactError> { ... }
fn decode(bytes: &[u8]) -> Result<Self, AlgoKitTransactError> { ... }
fn encode(&self) -> Result<Vec<u8>, AlgoKitTransactError> { ... }
}
Expand description
Trait for Algorand MessagePack encoding and decoding.
This trait defines methods for serializing and deserializing Algorand data structures to and from MessagePack format with the specific requirements of the Algorand protocol, including canonical sorting of map keys and domain separation prefixes.
Provided Associated Constants§
Provided Methods§
Sourcefn encode_raw(&self) -> Result<Vec<u8>, AlgoKitTransactError>
fn encode_raw(&self) -> Result<Vec<u8>, AlgoKitTransactError>
Encodes the object to MessagePack format without any prefix.
This method performs canonical encoding with sorted map keys and omitted empty fields, but does not include any domain separation prefix.
§Returns
The raw encoded bytes or an AlgoKitTransactError if serialization fails.
Sourcefn decode(bytes: &[u8]) -> Result<Self, AlgoKitTransactError>
fn decode(bytes: &[u8]) -> Result<Self, AlgoKitTransactError>
Decodes MessagePack bytes into an instance of this same type.
If the bytes start with the expected PREFIX for this type, the prefix is automatically removed before decoding.
§Parameters
bytes
- The MessagePack encoded bytes
§Returns
The decoded instance or an AlgoKitTransactError if the input is empty or deserialization fails.
Sourcefn encode(&self) -> Result<Vec<u8>, AlgoKitTransactError>
fn encode(&self) -> Result<Vec<u8>, AlgoKitTransactError>
Encodes the object to MessagePack format with the appropriate prefix.
This method performs canonical encoding and prepends the domain separation prefix defined by the PREFIX constant.
Use encode_raw()
if you want to encode without the prefix.
§Returns
The encoded bytes with prefix or an AlgoKitTransactError if serialization fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.