/// Converts a sequence of trytes into bytes
Converts a sequence of trytes into bytes
Converts a sequence of trytes into bytes
pub fn trytes_to_bytes(input: &str, buf: &mut [u8]) -> std::result::Result<(), TrytesToBytesError> {
    // We have to add one here because the input may contain an uneven amount of trytes
    assert!(
        buf.len() * 2 + 1 >= input.len(),
        "Buffer to short (buffer length: {}, number of trytes: {})",
        buf.len(),
        input.len()
    );
    for (idx, pair) in input
        .chars()
        .collect::<Vec<char>>()
        .chunks(2)
        .filter(|pair| pair.len() == 2)
        .enumerate()
    {
        let first = tryte_to_val(pair[0])?;
        let second = tryte_to_val(pair[1])?;
        let decimal = first + second * 27;
        buf[idx] = decimal
            .try_into()
            .map_err(|_| TrytesToBytesError::InvalidTrytePair)?;
    }
    Ok(())
}
pub fn trytes_to_bytes ( input : & str , buf : & mut [ u8 ] ) -> std :: result :: Result < ( ) , TrytesToBytesError > { // We have to add one here because the input may contain an uneven amount of trytes assert ! ( buf len ( ) 2 1 input len ( ) " " buf len ( ) input len ( ) ) ; for ( idx , pair ) in input . chars ( ) . collect :: < Vec < char > > ( ) . chunks ( 2 ) . filter ( | pair | pair . len ( ) == 2 ) . enumerate ( ) { let first = tryte_to_val ( pair [ 0 ] ) ? ; let second = tryte_to_val ( pair [ 1 ] ) ? ; let decimal = first + second * 27 ; buf [ idx ] = decimal . try_into ( ) . map_err ( | _ | TrytesToBytesError :: InvalidTrytePair ) ? ; } Ok ( ( ) ) }
Converts a sequence of trytes into bytes
Converts a sequence of trytes into bytes
input
&str
buf
&mut [u8]