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