Serialize the provenance graph to bytes. Format: `[MAGIC: 4 bytes][postcard payload]` The hash is computed over the entire serialized output.
(&self)
| 254 | /// |
| 255 | /// The hash is computed over the entire serialized output. |
| 256 | pub fn serialize(&self) -> Result<Vec<u8>, ProvenanceGraphError> { |
| 257 | let payload = postcard::to_allocvec(self).map_err(|e| ProvenanceGraphError::Codec { |
| 258 | reason: format!("postcard serialize failed: {}", e), |
| 259 | })?; |
| 260 | |
| 261 | let mut buf = Vec::with_capacity(MAGIC.len() + payload.len()); |
| 262 | buf.extend_from_slice(MAGIC); |
| 263 | buf.extend_from_slice(&payload); |
| 264 | Ok(buf) |
| 265 | } |
| 266 | |
| 267 | /// Deserialize a provenance graph from bytes, returning the graph and its hash. |
| 268 | /// |