/// Parse the provided buffer as if it implements the [logger/syslog wire format].
///
/// Note that this is distinct from the parsing we perform for the debuglog log, which aslo
/// takes a `&[u8]` and is why we don't implement this as `TryFrom`.
///
/// [logger/syslog wire format]: https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/ulib/syslog/include/lib/syslog/wire_format.h
Parse the provided buffer as if it implements the [logger/syslog wire format].
Note that this is distinct from the parsing we perform for the debuglog log, which aslo
takes a `&[u8]` and is why we don't implement this as `TryFrom`.


Parse the provided buffer as if it implements the [ logger / syslog wire format ] . Note that this is distinct from the parsing we perform for the debuglog log which aslo takes a ` & [ u8 ] ` and is why we don ' t implement this as ` TryFrom ` .
pub(super) fn from_logger(bytes: &[u8]) -> Result<Self, StreamError> {
        if bytes.len() < MIN_PACKET_SIZE {
            return Err(StreamError::ShortRead { len: bytes.len() });
        }
        let terminator = bytes[bytes.len() - 1];
        if terminator != 0 {
            return Err(StreamError::NotNullTerminated { terminator });
        }
        let pid = LittleEndian::read_u64(&bytes[..8]);
        let tid = LittleEndian::read_u64(&bytes[8..16]);
        let time = zx::Time::from_nanos(LittleEndian::read_i64(&bytes[16..24]));
        let severity = LittleEndian::read_i32(&bytes[24..28]);
        let dropped_logs = LittleEndian::read_u32(&bytes[28..METADATA_SIZE]) as usize;
        // start reading tags after the header
        let mut cursor = METADATA_SIZE;
        let mut tag_len = bytes[cursor] as usize;
        let mut tags = Vec::new();
        while tag_len != 0 {
            if tags.len() == MAX_TAGS {
                return Err(StreamError::TooManyTags);
            }
            if tag_len > MAX_TAG_LEN - 1 {
                return Err(StreamError::TagTooLong { index: tags.len(), len: tag_len });
            }
            if (cursor + tag_len + 1) > bytes.len() {
                return Err(StreamError::OutOfBounds);
            }
            let tag_start = cursor + 1;
            let tag_end = tag_start + tag_len;
            let tag = str::from_utf8(&bytes[tag_start..tag_end])?;
            tags.push(tag.to_owned());
            cursor = tag_end;
            tag_len = bytes[cursor] as usize;
        }
        let msg_start = cursor + 1;
        let mut msg_end = cursor + 1;
        while msg_end < bytes.len() {
            if bytes[msg_end] == 0 {
                let contents = str::from_utf8(&bytes[msg_start..msg_end])?.to_owned();
                return Ok(Self {
                    size: cursor + contents.len() + 1,
                    tags,
                    contents,
                    pid,
                    tid,
                    time,
                    severity,
                    dropped_logs,
                });
            }
            msg_end += 1;
        }
        Err(StreamError::OutOfBounds)
    }
pub ( super ) fn from_logger ( bytes : & [ u8 ] ) -> Result < Self , StreamError > { if bytes . len ( ) < MIN_PACKET_SIZE { return Err ( StreamError :: ShortRead { len : bytes . len ( ) } ) ; } let terminator = bytes [ bytes . len ( ) - 1 ] ; if terminator != 0 { return Err ( StreamError :: NotNullTerminated { terminator } ) ; } let pid = LittleEndian :: read_u64 ( & bytes [ .. 8 ] ) ; let tid = LittleEndian :: read_u64 ( & bytes [ 8 .. 16 ] ) ; let time = zx :: Time :: from_nanos ( LittleEndian :: read_i64 ( & bytes [ 16 .. 24 ] ) ) ; let severity = LittleEndian :: read_i32 ( & bytes [ 24 .. 28 ] ) ; let dropped_logs = LittleEndian :: read_u32 ( & bytes [ 28 .. METADATA_SIZE ] ) as usize ; // start reading tags after the header let mut cursor = METADATA_SIZE ; let mut tag_len = bytes [ cursor ] as usize ; let mut tags = Vec :: new ( ) ; while tag_len != 0 { if tags . len ( ) == MAX_TAGS { return Err ( StreamError :: TooManyTags ) ; } if tag_len > MAX_TAG_LEN - 1 { return Err ( StreamError :: TagTooLong { index : tags . len ( ) , len : tag_len } ) ; } if ( cursor + tag_len + 1 ) > bytes . len ( ) { return Err ( StreamError :: OutOfBounds ) ; } let tag_start = cursor + 1 ; let tag_end = tag_start + tag_len ; let tag = str :: from_utf8 ( & bytes [ tag_start .. tag_end ] ) ? ; tags . push ( tag . to_owned ( ) ) ; cursor = tag_end ; tag_len = bytes [ cursor ] as usize ; } let msg_start = cursor + 1 ; let mut msg_end = cursor + 1 ; while msg_end < bytes . len ( ) { if bytes [ msg_end ] == 0 { let contents = str :: from_utf8 ( & bytes [ msg_start .. msg_end ] ) ? . to_owned ( ) ; return Ok ( Self { size : cursor + contents . len ( ) + 1 , tags , contents , pid , tid , time , severity , dropped_logs , } ) ; } msg_end += 1 ; } Err ( StreamError :: OutOfBounds ) }
Parse the provided buffer as if it implements the [logger/syslog wire format].
Parse the provided buffer as if it implements the [ logger / syslog wire format ] .
bytes
&[u8]