pdk-serde-fixint 1.9.2

PDK serde codec, byte-compatible with the bincode 1.3 default format
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

//! Error type for the fixint codec.

use serde::{de, ser};
use std::fmt::{self, Display};

/// Errors produced while serializing or deserializing with the fixint codec.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// A `serde` (de)serialization error carrying a message.
    #[error("{0}")]
    Message(String),

    /// Reached the end of the input buffer before a value was fully read.
    #[error("unexpected end of input")]
    Eof,

    /// A byte that must encode a `bool` was neither 0 nor 1.
    #[error("invalid bool encoding: {0}")]
    InvalidBool(u8),

    /// The tag byte of an `Option` was neither 0 nor 1.
    #[error("invalid option tag: {0}")]
    InvalidOptionTag(u8),

    /// A `char`/`str` payload was not valid UTF-8.
    #[error("invalid utf-8 while decoding")]
    InvalidUtf8,

    /// A `char` payload did not contain exactly one scalar value.
    #[error("invalid char encoding")]
    InvalidChar,

    /// The codec was asked to decode a self-describing value, which this
    /// non-self-describing format cannot support.
    #[error("deserialize_any is not supported by the fixint format")]
    NotSupported,

    /// Trailing bytes remained after a value was fully decoded.
    #[error("{0} trailing byte(s) after decoded value")]
    TrailingBytes(usize),
}

/// Convenience alias for codec results.
pub type Result<T> = std::result::Result<T, Error>;

impl ser::Error for Error {
    fn custom<T: Display>(msg: T) -> Self {
        Error::Message(msg.to_string())
    }
}

impl de::Error for Error {
    fn custom<T: Display>(msg: T) -> Self {
        Error::Message(msg.to_string())
    }
}

impl From<fmt::Error> for Error {
    fn from(_: fmt::Error) -> Self {
        Error::Message("formatting error".to_string())
    }
}