vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
//! UTF-8 string encoder for the IR wire format.

use super::put_len_u32;
use crate::ir::serial::wire::MAX_STRING_LEN;

/// Append a bounded length-prefixed UTF-8 string.
///
/// # Errors
///
/// Returns an actionable error when the string exceeds the wire-format maximum
/// length or the length cannot fit in the encoded field.
#[inline]
pub fn put_string(out: &mut Vec<u8>, value: &str) -> Result<(), String> {
    if value.len() > MAX_STRING_LEN {
        return Err(format!(
            "Fix: string length {} exceeds IR wire-format limit {MAX_STRING_LEN}; shorten names/op ids before serialization.",
            value.len()
        ));
    }
    put_len_u32(out, value.len(), "string length")?;
    out.extend_from_slice(value.as_bytes());
    Ok(())
}