Encode for durable storage (one JSON document per file).
(&self)
| 181 | |
| 182 | /// Encode for durable storage (one JSON document per file). |
| 183 | pub fn to_json(&self) -> AgentResult<Vec<u8>> { |
| 184 | serde_json::to_vec_pretty(self) |
| 185 | .map(|mut bytes| { |
| 186 | bytes.push(b'\n'); |
| 187 | bytes |
| 188 | }) |
| 189 | .map_err(|e| crate::error::AgentError::RecordFailed { |
| 190 | session_id: self.session_id.clone(), |
| 191 | turn_number: self.turn, |
| 192 | reason: format!("Failed to encode commit capture: {}", e), |
| 193 | }) |
| 194 | } |
| 195 | |
| 196 | /// Decode a stored capture. |
| 197 | pub fn from_json(bytes: &[u8]) -> AgentResult<Self> { |