clasp_journal/entry.rs
1//! Journal entry types
2
3use clasp_core::{SignalType, Value};
4use serde::{Deserialize, Serialize};
5
6/// A single journal entry representing a state change or event
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct JournalEntry {
9 /// Monotonic sequence number (assigned by the journal)
10 pub seq: u64,
11 /// Wall clock timestamp (microseconds since epoch)
12 pub timestamp: u64,
13 /// Author of this entry (entity or session ID)
14 pub author: String,
15 /// CLASP address this entry applies to
16 pub address: String,
17 /// Signal type of the entry
18 pub signal_type: SignalType,
19 /// The value that was set or published
20 pub value: Value,
21 /// Param revision (for SET operations)
22 pub revision: Option<u64>,
23 /// Original message type code (0x20=PUBLISH, 0x21=SET, etc.)
24 pub msg_type: u8,
25}
26
27impl JournalEntry {
28 /// Create a new journal entry for a SET operation
29 pub fn from_set(
30 address: String,
31 value: Value,
32 revision: u64,
33 author: String,
34 timestamp: u64,
35 ) -> Self {
36 Self {
37 seq: 0, // Assigned by journal
38 timestamp,
39 author,
40 address,
41 signal_type: SignalType::Param,
42 value,
43 revision: Some(revision),
44 msg_type: 0x21, // SET
45 }
46 }
47
48 /// Create a new journal entry for a PUBLISH operation
49 pub fn from_publish(
50 address: String,
51 signal_type: SignalType,
52 value: Value,
53 author: String,
54 timestamp: u64,
55 ) -> Self {
56 Self {
57 seq: 0, // Assigned by journal
58 timestamp,
59 author,
60 address,
61 signal_type,
62 value,
63 revision: None,
64 msg_type: 0x20, // PUBLISH
65 }
66 }
67}
68
69/// Serializable snapshot of param state for persistence
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ParamSnapshot {
72 pub address: String,
73 pub value: Value,
74 pub revision: u64,
75 pub writer: String,
76 pub timestamp: u64,
77}