Skip to main content

Crate pallas_codec

Crate pallas_codec 

Source
Expand description

The encoding foundation the rest of the Pallas workspace builds on.

Provides minicbor for CBOR (re-exported as-is) and a Rust port of the Plutus Core flat format. Most users won’t depend on this crate directly — they’ll get its types transitively through pallas-primitives, pallas-traverse, pallas-txbuilder, and so on. Reach for it when you need to define your own minicbor-encoded type, or when you need the round-trip helpers (utils::KeepRaw, utils::Nullable, utils::Set, …) used by the higher-level era types.

§Usage

use pallas_codec::minicbor;

#[derive(minicbor::Encode, minicbor::Decode, Debug, PartialEq)]
struct Pair(#[n(0)] u64, #[n(1)] String);

let bytes = minicbor::to_vec(Pair(1, "hi".into()))?;
let back: Pair = minicbor::decode(&bytes)?;
assert_eq!(back, Pair(1, "hi".into()));

§Overview

§Usage as part of pallas

When depending on the umbrella pallas crate, this crate is re-exported as pallas::codec.

Re-exports§

pub use minicbor;

Modules§

flat
Flat encoding/decoding for Plutus Core.
utils
Round-trip friendly common helper structs (Bytes, Nullable, Set, …).

Macros§

codec_by_datatype
Derive a minicbor Decode/Encode implementation for an enum by dispatching on the incoming CBOR datatype.

Traits§

Fragment
Blanket trait for any type that can be CBOR-encoded and decoded with minicbor. Implemented automatically for every such type.