flow-abi 0.1.0

The value encoding at the host boundary: type-directed JSON encoding and decoding, the canonical form and its hash, JSON Schemas, and Tool declaration fingerprints.
Documentation
//! The limits a decoded value is held to (`execution.md`, *Limits*).

/// How large a decoded value may be on this host.
///
/// A value past any of these does not decode, like any other value that does
/// not match its type: in a Tool reply that is `BadReply`, which the program
/// can handle, never a fault (`abi.md`, *Decoding*).
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Limits {
    /// How deeply the decoded value may nest: a scalar is 0 deep, and a
    /// list, set, dictionary, tuple, record or enum value one deeper than its
    /// deepest part, as the evaluator counts.
    pub depth: usize,
    /// How many bits an `Int` may take, sign excluded, and so the integer
    /// any number's significant digits make, which bounds a `Decimal`'s
    /// coefficient.
    pub int_bits: u64,
    /// How many bytes one `Text` or `Bytes` may hold, and how many digits a
    /// number may take written in plain decimal notation.
    pub text_bytes: usize,
}

impl Limits {
    /// The minimums every implementation supports.
    pub const MINIMUM: Limits = Limits {
        depth: 256,
        int_bits: 4096,
        text_bytes: 16 * 1024 * 1024,
    };

    /// How deeply JSON arrays and objects may nest before decoding refuses
    /// the text unread.
    ///
    /// A JSON level makes at least half a level of value — an enum with a
    /// named payload is two objects around one value — so text nested deeper
    /// than this could not decode within [`Limits::depth`] in any case.
    pub(crate) fn json_depth(&self) -> usize {
        self.depth.saturating_mul(2).saturating_add(1)
    }
}

impl Default for Limits {
    fn default() -> Self {
        Limits::MINIMUM
    }
}