digdigdig3_station/data/
three_line_break.rs1use digdigdig3::core::types::StreamEvent;
2use serde::{Deserialize, Serialize};
3
4use crate::series::DataPoint;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct ThreeLineBreakLinePoint {
28 pub ts_open: i64,
29 pub ts_close: i64,
30 pub open: f64,
32 pub close: f64,
35 pub volume: f64,
37 pub direction: u8,
39}
40
41const SIZE: usize = 48;
42
43impl DataPoint for ThreeLineBreakLinePoint {
44 const RECORD_SIZE: usize = SIZE;
45
46 fn encode(&self, out: &mut [u8]) {
47 out[0..8].copy_from_slice(&(self.ts_open as u64).to_le_bytes());
48 out[8..16].copy_from_slice(&(self.ts_close as u64).to_le_bytes());
49 out[16..24].copy_from_slice(&self.open.to_le_bytes());
50 out[24..32].copy_from_slice(&self.close.to_le_bytes());
51 out[32..40].copy_from_slice(&self.volume.to_le_bytes());
52 out[40] = self.direction;
53 }
55
56 fn decode(bytes: &[u8]) -> Option<Self> {
57 if bytes.len() != SIZE {
58 return None;
59 }
60 Some(Self {
61 ts_open: u64::from_le_bytes(bytes[0..8].try_into().ok()?) as i64,
62 ts_close: u64::from_le_bytes(bytes[8..16].try_into().ok()?) as i64,
63 open: f64::from_le_bytes(bytes[16..24].try_into().ok()?),
64 close: f64::from_le_bytes(bytes[24..32].try_into().ok()?),
65 volume: f64::from_le_bytes(bytes[32..40].try_into().ok()?),
66 direction: bytes[40],
67 })
68 }
69
70 fn timestamp_ms(&self) -> i64 {
71 self.ts_open
72 }
73
74 fn from_stream_event(_ev: &StreamEvent) -> Option<Self> {
75 None
76 }
77}