pub fn encode_non_escaped(
        &self,
        source_stream: &[u8],
        dest_stream: &mut [u8],
    ) -> Result<usize, DleError> {
        let mut encoded_idx = 0;
        let mut source_idx = 0;
        let source_stream_len = source_stream.len();
        let max_dest_len = dest_stream.len();
        if self.add_stx_etx {
            if max_dest_len < 2 {
                return Err(DleError::StreamTooShort);
            }
            dest_stream[encoded_idx] = DLE_CHAR;
            encoded_idx += 1;
            dest_stream[encoded_idx] = STX_CHAR;
            encoded_idx += 1;
        }

        while encoded_idx < max_dest_len && source_idx < source_stream_len {
            let next_byte = source_stream[source_idx];
            if next_byte == DLE_CHAR {
                if encoded_idx + 1 >= max_dest_len {
                    return Err(DleError::StreamTooShort);
                } else {
                    dest_stream[encoded_idx] = DLE_CHAR;
                    encoded_idx += 1;
                    dest_stream[encoded_idx] = DLE_CHAR;
                }
            } else {
                dest_stream[encoded_idx] = next_byte;
            }
            encoded_idx += 1;
            source_idx += 1;
        }

        if source_idx == source_stream_len {
            if self.add_stx_etx {
                if encoded_idx + 2 >= max_dest_len {
                    return Err(DleError::StreamTooShort);
                }
                dest_stream[encoded_idx] = DLE_CHAR;
                encoded_idx += 1;
                dest_stream[encoded_idx] = ETX_CHAR;
                encoded_idx += 1;
            }
            Ok(encoded_idx)
        } else {
            Err(DleError::StreamTooShort)
        }
    }
/// This method encodes a given byte stream with ASCII based DLE encoding.
/// It explicitely does so in the non-escaped mode.
///
/// # Arguments
///
/// * `source_stream` - The stream to encode
/// * `dest_stream` - Encoded stream will be written here
///
/// # Example
///
/// ```
/// use dle_encoder::DleEncoder;
///
/// let dle_encoder = DleEncoder::default();
/// let mut encoding_buffer: [u8; 16] = [0; 16];
/// let example_array: [u8; 3] = [0, 0x02, 0x10];
///
/// let encode_result = dle_encoder.encode_non_escaped(
///     &example_array, &mut encoding_buffer
/// );
/// assert!(encode_result.is_ok());
/// let encoded_len = encode_result.unwrap();
/// assert_eq!(encoded_len, 8);
///
/// println!("Source buffer: {:?}", example_array);
/// println!("Encoded stream: {:?}", &encoding_buffer[ .. encoded_len])
/// ```
This method encodes a given byte stream with ASCII based DLE encoding.
It explicitely does so in the non-escaped mode.
This method encodes a given byte stream with ASCII based DLE encoding . It explicitely does so in the non - escaped mode .
pub fn encode_non_escaped(
        &self,
        source_stream: &[u8],
        dest_stream: &mut [u8],
    ) -> Result<usize, DleError> {
        let mut encoded_idx = 0;
        let mut source_idx = 0;
        let source_stream_len = source_stream.len();
        let max_dest_len = dest_stream.len();
        if self.add_stx_etx {
            if max_dest_len < 2 {
                return Err(DleError::StreamTooShort);
            }
            dest_stream[encoded_idx] = DLE_CHAR;
            encoded_idx += 1;
            dest_stream[encoded_idx] = STX_CHAR;
            encoded_idx += 1;
        }
        while encoded_idx < max_dest_len && source_idx < source_stream_len {
            let next_byte = source_stream[source_idx];
            if next_byte == DLE_CHAR {
                if encoded_idx + 1 >= max_dest_len {
                    return Err(DleError::StreamTooShort);
                } else {
                    dest_stream[encoded_idx] = DLE_CHAR;
                    encoded_idx += 1;
                    dest_stream[encoded_idx] = DLE_CHAR;
                }
            } else {
                dest_stream[encoded_idx] = next_byte;
            }
            encoded_idx += 1;
            source_idx += 1;
        }
        if source_idx == source_stream_len {
            if self.add_stx_etx {
                if encoded_idx + 2 >= max_dest_len {
                    return Err(DleError::StreamTooShort);
                }
                dest_stream[encoded_idx] = DLE_CHAR;
                encoded_idx += 1;
                dest_stream[encoded_idx] = ETX_CHAR;
                encoded_idx += 1;
            }
            Ok(encoded_idx)
        } else {
            Err(DleError::StreamTooShort)
        }
    }
pub fn encode_non_escaped ( & self , source_stream : & [ u8 ] , dest_stream : & mut [ u8 ] , ) -> Result < usize , DleError > { let mut encoded_idx = 0 ; let mut source_idx = 0 ; let source_stream_len = source_stream . len ( ) ; let max_dest_len = dest_stream . len ( ) ; if self . add_stx_etx { if max_dest_len < 2 { return Err ( DleError :: StreamTooShort ) ; } dest_stream [ encoded_idx ] = DLE_CHAR ; encoded_idx += 1 ; dest_stream [ encoded_idx ] = STX_CHAR ; encoded_idx += 1 ; } while encoded_idx < max_dest_len && source_idx < source_stream_len { let next_byte = source_stream [ source_idx ] ; if next_byte == DLE_CHAR { if encoded_idx + 1 >= max_dest_len { return Err ( DleError :: StreamTooShort ) ; } else { dest_stream [ encoded_idx ] = DLE_CHAR ; encoded_idx += 1 ; dest_stream [ encoded_idx ] = DLE_CHAR ; } } else { dest_stream [ encoded_idx ] = next_byte ; } encoded_idx += 1 ; source_idx += 1 ; } if source_idx == source_stream_len { if self . add_stx_etx { if encoded_idx + 2 >= max_dest_len { return Err ( DleError :: StreamTooShort ) ; } dest_stream [ encoded_idx ] = DLE_CHAR ; encoded_idx += 1 ; dest_stream [ encoded_idx ] = ETX_CHAR ; encoded_idx += 1 ; } Ok ( encoded_idx ) } else { Err ( DleError :: StreamTooShort ) } }
This method encodes a given byte stream with ASCII based DLE encoding.
This method encodes a given byte stream with ASCII based DLE encoding .
&self
source_stream
&[u8]
dest_stream
&mut [u8]
&self
source_stream
&[u8]
dest_stream
&mut [u8]
example
```
use dle_encoder::DleEncoder.



let encode_result = dle_encoder.encode_non_escaped(
&example_array, &mut encoding_buffer
);
assert!(encode_result.is_ok());
let encoded_len = encode_result.unwrap();
assert_eq!(encoded_len, 8).

println!("Source buffer: {:?}", example_array);
println!("Encoded stream: {:?}", &encoding_buffer[ ..
` ` ` use dle_encoder :: DleEncoder . let encode_result = dle_encoder . encode_non_escaped ( &example_array &mut encoding_buffer ) ; assert! ( encode_result . is_ok () ) ; let encoded_len = encode_result . unwrap () ; assert_eq! ( encoded_len 8 ) . println! ( " Source buffer : { : ? } " example_array ) ; println! ( " Encoded stream : { : ? } " &encoding_buffer [ ..