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

Function encode

atomic-objects/src/sync.rs:304–307  ·  view source on GitHub ↗

Serialize `value` with postcard and zstd-compress it into a wire body. Deterministic for a given value (postcard field order is fixed and zstd is deterministic at a fixed level), which keeps request bodies reproducible for tests and caches.

(value: &T)

Source from the content-addressed store, hash-verified

302/// deterministic at a fixed level), which keeps request bodies reproducible for
303/// tests and caches.
304pub fn encode<T: Serialize>(value: &T) -> Result<Vec<u8>, SyncError> {
305 let raw = postcard::to_allocvec(value).map_err(SyncError::Codec)?;
306 zstd::encode_all(raw.as_slice(), DEFAULT_ZSTD_LEVEL).map_err(SyncError::Compression)
307}
308
309/// Decompress and deserialize a wire body, bounded by
310/// [`DEFAULT_MAX_DECOMPRESSED`]. Use [`decode_with_limit`] to set a tighter cap

Callers 1

encodeMethod · 0.70

Calls 1

as_sliceMethod · 0.45

Tested by

no test coverage detected