MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / save_change_bytes

Method save_change_bytes

atomic-repository/src/repository/changes.rs:270–298  ·  view source on GitHub ↗

Save a change using pre-serialized ATOM bytes (hash-stable). This writes the exact bytes to disk after inspecting the explicit ATOM file-header version. Version 1 is legacy; version 2 requires the durable `change-format-vnext` repository capability before persistence. # Arguments `hash` - The content hash (from the original serialization) `change_bytes` - The exact ATOM bytes to write to disk `

(
        &self,
        hash: &Hash,
        change_bytes: &[u8],
        change: &Change,
    )

Source from the content-addressed store, hash-verified

268 /// * `change_bytes` - The exact ATOM bytes to write to disk
269 /// * `change` - The deserialized change used for capability checks
270 pub(crate) fn save_change_bytes(
271 &self,
272 hash: &Hash,
273 change_bytes: &[u8],
274 change: &Change,
275 ) -> Result<Hash, RepositoryError> {
276 let version = atom_change_file_version(change_bytes)?;
277 self.require_projected_semantic_storage_capability(change)?;
278 if version == ATOM_CHANGE_FILE_VERSION_SPAN {
279 let (decoded, actual_hash) =
280 Change::deserialize(&mut std::io::Cursor::new(change_bytes))
281 .map_err(|error| RepositoryError::Serialization(error.to_string()))?;
282 if actual_hash != *hash
283 || decoded.hashed != change.hashed
284 || decoded.contents != change.contents
285 {
286 return Err(RepositoryError::Serialization(
287 "span change bytes do not match the supplied change identity".into(),
288 ));
289 }
290 self.require_span_storage_capability()?;
291 }
292 if version == ATOM_CHANGE_FILE_VERSION_V2 || version == ATOM_CHANGE_FILE_VERSION_SPAN {
293 self.pristine
294 .require_repository_capability(CHANGE_FORMAT_VNEXT_CAPABILITY)
295 .map_err(RepositoryError::from)?;
296 }
297 self.save_change_bytes_after_capability_declaration(hash, change_bytes, change)
298 }
299
300 /// Write pre-serialized bytes after the caller has declared V2 capability
301 /// before opening its graph transaction.