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