/// Parses a raw debug log read from the kernel.  Returns the parsed message and
/// its size in memory on success, and None if parsing fails.
Parses a raw debug log read from the kernel.  Returns the parsed message and
its size in memory on success, and None if parsing fails.
Parses a raw debug log read from the kernel . Returns the parsed message and its size in memory on success and None if parsing fails .
pub fn convert_debuglog_to_log_message(buf: &[u8]) -> Option<Message> {
    if buf.len() < 32 {
        return None;
    }
    let data_len = LittleEndian::read_u16(&buf[4..6]) as usize;
    if buf.len() != 32 + data_len {
        return None;
    }
    let time = zx::Time::from_nanos(LittleEndian::read_i64(&buf[8..16]));
    let pid = LittleEndian::read_u64(&buf[16..24]);
    let tid = LittleEndian::read_u64(&buf[24..32]);
    let mut contents = match String::from_utf8(buf[32..(32 + data_len)].to_vec()) {
        Err(e) => {
            eprintln!("logger: invalid log record: {:?}", e);
            return None;
        }
        Ok(s) => s,
    };
    if let Some(b'\n') = contents.bytes().last() {
        contents.pop();
    }
    Some(Message {
        size: METADATA_SIZE + 5/*tag*/ + contents.len() + 1,
        time,
        pid,
        tid,
        severity: LogLevelFilter::Info as _,
        dropped_logs: 0,
        tags: vec![String::from("klog")],
        contents,
    })
}
pub fn convert_debuglog_to_log_message ( buf : & [ u8 ] ) -> Option < Message > { if buf . len ( ) < 32 { return None ; } let data_len = LittleEndian :: read_u16 ( & buf [ 4 .. 6 ] ) as usize ; if buf . len ( ) != 32 + data_len { return None ; } let time = zx :: Time :: from_nanos ( LittleEndian :: read_i64 ( & buf [ 8 .. 16 ] ) ) ; let pid = LittleEndian :: read_u64 ( & buf [ 16 .. 24 ] ) ; let tid = LittleEndian :: read_u64 ( & buf [ 24 .. 32 ] ) ; let mut contents = match String :: from_utf8 ( buf [ 32 .. ( 32 + data_len ) ] . to_vec ( ) ) { Err ( e ) => { eprintln ! ( " " e ) ; return None ; } Ok ( s ) => s , } ; if let Some ( b'\n' ) = contents . bytes ( ) . last ( ) { contents . pop ( ) ; } Some ( Message { size : METADATA_SIZE + 5 /*tag*/ + contents . len ( ) + 1 , time , pid , tid , severity : LogLevelFilter :: Info as _ , dropped_logs : 0 , tags : vec ! [ String from ( " " ) ] , contents , } ) }
Parses a raw debug log read from the kernel.
Parses a raw debug log read from the kernel .
buf
&[u8]