srcdmp 0.1.0-alpha.1

Amazing code snapshot tool and library
Documentation
use crate::raw::error::SdmpError;

/// Encode a string as raw UTF-8 bytes (passthrough, no compression).
///
/// This is the SDMP-8 codec: the output is identical to the input's
/// UTF-8 byte representation.
///
/// # Examples
///
/// ```rust
/// use srcdmp::raw::codec::sdmp8::encode;
///
/// assert_eq!(encode("hello"), b"hello");
/// ```
#[must_use]
pub fn encode(input: &str) -> Vec<u8> {
    input.as_bytes().to_vec()
}

/// Decode raw UTF-8 bytes back into a string (SDMP-8 passthrough).
///
/// # Errors
///
/// Returns [`SdmpError::InvalidUtf8`] if the byte sequence is not
/// valid UTF-8.
///
/// # Examples
///
/// ```rust
/// use srcdmp::raw::codec::sdmp8::decode;
///
/// assert_eq!(decode(b"hello").unwrap(), "hello");
/// assert!(decode(b"\xff\xfe").is_err());
/// ```
pub fn decode(input: &[u8]) -> Result<String, SdmpError> {
    String::from_utf8(input.to_vec()).map_err(|_| SdmpError::InvalidUtf8)
}