1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
mod error;

pub use self::error::*;

use crate::{extract::Extract, Event, StateChange, TryExtract};
use std::mem::transmute;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Log started, ended or target changed.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LogEvent {
    /// Time of registering the event.
    pub time: u64,

    /// Server Unix timestamp.
    pub server_time: u32,

    /// Local Unix timestamp.
    pub local_time: u32,

    /// Target species id (or ArcDPS id `0x637261`).
    pub id: u64,
}

impl Extract for LogEvent {
    #[inline]
    unsafe fn extract(event: &Event) -> Self {
        Self {
            time: event.time,
            server_time: transmute(event.value),
            local_time: transmute(event.buff_dmg),
            id: event.src_agent,
        }
    }
}

impl TryExtract for LogEvent {
    #[inline]
    fn can_extract(event: &Event) -> bool {
        matches!(
            event.get_statechange(),
            StateChange::LogStart | StateChange::LogEnd | StateChange::LogNPCUpdate
        )
    }
}