diff --git a/analyzeme/src/event.rs b/analyzeme/src/event.rs index 2c548c0..0c0567b 100644 --- a/analyzeme/src/event.rs +++ b/analyzeme/src/event.rs @@ -1,13 +1,28 @@ use crate::timestamp::Timestamp; -use memchr::memchr; use std::borrow::Cow; use std::time::Duration; +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +pub struct Argument<'a> { + pub name: Option>, + pub value: Cow<'a, str>, +} + +impl<'a> Argument<'a> { + pub fn new(value: &'a str) -> Self { + Self { name: None, value: Cow::from(value) } + } + + pub fn new_named(name: &'a str, value: &'a str) -> Self { + Self { name: Some(Cow::from(name)), value: Cow::from(value) } + } +} + #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct Event<'a> { pub event_kind: Cow<'a, str>, pub label: Cow<'a, str>, - pub additional_data: Vec>, + pub additional_data: Vec>, pub timestamp: Timestamp, pub thread_id: u32, } @@ -38,7 +53,7 @@ impl<'a> Event<'a> { } } - pub(crate) fn parse_event_id(event_id: Cow<'a, str>) -> (Cow<'a, str>, Vec>) { + pub(crate) fn parse_event_id(event_id: Cow<'a, str>) -> (Cow<'a, str>, Vec>) { let event_id = match event_id { Cow::Owned(s) => Cow::Owned(s.into_bytes()), Cow::Borrowed(s) => Cow::Borrowed(s.as_bytes()), @@ -75,52 +90,58 @@ struct Parser<'a> { pos: usize, } -const SEPARATOR_BYTE: u8 = measureme::event_id::SEPARATOR_BYTE.as_bytes()[0]; +const ARGUMENT_VALUE_TAG_BYTE: u8 = measureme::event_id::ARGUMENT_VALUE_TAG_BYTE.as_bytes()[0]; +const ARGUMENT_NAME_TAG_BYTE: u8 = measureme::event_id::ARGUMENT_NAME_TAG_BYTE.as_bytes()[0]; impl<'a> Parser<'a> { fn new(full_text: Cow<'a, [u8]>) -> Parser<'a> { Parser { full_text, pos: 0 } } - fn peek(&self) -> u8 { - self.full_text[self.pos] - } - fn parse_label(&mut self) -> Result, String> { assert!(self.pos == 0); - self.parse_separator_terminated_text() + let text = self.parse_text()?; + if text.is_empty() { + return self.err("