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
minicbor— re-exported as-is; this is the workspace’s single source of truth for CBOR.flat— Rust port of the Haskell flat reference implementation, used for Plutus Core scripts.utils— round-trip-friendly helper types (utils::KeepRaw,utils::KeyValuePairs,utils::MaybeIndefArray,utils::NonEmptySet,utils::Nullable,utils::PositiveCoin, …) reused by the higher-level era types.Fragmenttrait — blanket-implemented for any type that is bothminicbor::Encodeandminicbor::Decode; used as a bound where the workspace wants “any CBOR-roundtrippable type”.codec_by_datatype!macro — derives a tag-free CBOR codec for enums whose variants are distinguished by their data-type rather than a discriminant.
§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
minicborDecode/Encodeimplementation for an enum by dispatching on the incoming CBOR datatype.