[][src]Function atat::get_line

pub fn get_line<L: ArrayLength<u8>, I: ArrayLength<u8>>(
    buf: &mut Vec<u8, I>,
    needle: &[u8],
    line_term_char: u8,
    format_char: u8,
    trim_response: bool,
    reverse: bool
) -> Option<Vec<u8, L>>

Helper function to take a subsection from buf.

It searches for needle, either from the beginning of buf, or the end, depending on reverse. If the search finds a match, it continues forward as long as the next characters matches line_term_char or format_char. It then returns a substring, trimming it for whitespaces if trim_response is true, and leaves the remainder in buf.

Example:

use atat::get_line;
use heapless::{consts, Vec};

let mut buf: Vec<u8, consts::U128> =
    Vec::from_slice(b"+USORD: 3,16,\"16 bytes of data\"\r\nOK\r\nAT+GMR\r\r\n").unwrap();
let response: Option<Vec<u8, consts::U64>> =
    get_line(&mut buf, b"OK", b'\r', b'\n', false, false);
assert_eq!(
    response,
    Some(Vec::from_slice(b"+USORD: 3,16,\"16 bytes of data\"\r\nOK\r\n").unwrap())
);
assert_eq!(
    buf,
    Vec::<u8, consts::U128>::from_slice(b"AT+GMR\r\r\n").unwrap()
);