entrenar/monitor/inference/serialization/
format.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum TraceFormat {
8 Binary,
12
13 Json,
15
16 JsonLines,
18}
19
20pub const APRT_MAGIC: [u8; 4] = [0x41, 0x50, 0x52, 0x54]; pub const APRT_VERSION: u8 = 1;
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28#[repr(u8)]
29pub enum PathType {
30 Linear = 0,
31 Tree = 1,
32 Forest = 2,
33 KNN = 3,
34 Neural = 4,
35 Custom = 255,
36}
37
38impl From<u8> for PathType {
39 fn from(value: u8) -> Self {
40 match value {
41 0 => PathType::Linear,
42 1 => PathType::Tree,
43 2 => PathType::Forest,
44 3 => PathType::KNN,
45 4 => PathType::Neural,
46 5..=255 => PathType::Custom,
47 }
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_path_type_from_u8_all_variants() {
57 let cases: &[(u8, PathType)] = &[
58 (0, PathType::Linear),
59 (1, PathType::Tree),
60 (2, PathType::Forest),
61 (3, PathType::KNN),
62 (4, PathType::Neural),
63 (5, PathType::Custom),
64 (128, PathType::Custom),
65 (255, PathType::Custom),
66 ];
67
68 for &(input, expected) in cases {
69 let result = PathType::from(input);
70 let label = match input {
72 0 => PathType::Linear,
73 1 => PathType::Tree,
74 2 => PathType::Forest,
75 3 => PathType::KNN,
76 4 => PathType::Neural,
77 5..=255 => PathType::Custom,
78 };
79 assert_eq!(result, expected);
80 assert_eq!(result, label);
81 }
82 }
83
84 #[test]
85 fn test_trace_format_variants() {
86 let _binary = TraceFormat::Binary;
87 let _json = TraceFormat::Json;
88 let _jsonl = TraceFormat::JsonLines;
89 }
90
91 #[test]
92 fn test_aprt_constants() {
93 assert_eq!(APRT_MAGIC, [0x41, 0x50, 0x52, 0x54]);
94 assert_eq!(APRT_VERSION, 1);
95 }
96}