algokit_transact

Trait AlgorandMsgpack

Source
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§

Source

const PREFIX: &'static [u8] = b""

Domain separation prefix used during encoding.

This prefix is prepended to the encoded data to distinguish different types of Algorand objects. For example, transactions use “TX” as their prefix. An empty prefix means no domain separation is applied.

Provided Methods§

Source

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.

Source

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.

Source

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.

Implementors§