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

Method read_blob

atomic-core/src/operation/codec.rs:950–969  ·  view source on GitHub ↗
(&mut self, field: &str)

Source from the content-addressed store, hash-verified

948 }
949
950 fn read_blob(&mut self, field: &str) -> Result<Vec<u8>, OperationCodecError> {
951 let len = self.read_u32()? as usize;
952 if len > MAX_OPERATION_OBJECT_BYTES {
953 return Err(OperationCodecError::new(format!(
954 "{field} has {len} bytes, maximum is {MAX_OPERATION_OBJECT_BYTES}"
955 )));
956 }
957 let end = self
958 .offset
959 .checked_add(len)
960 .ok_or_else(|| OperationCodecError::new("canonical byte-string length overflow"))?;
961 let bytes = self.bytes.get(self.offset..end).ok_or_else(|| {
962 OperationCodecError::new(format!(
963 "canonical object is truncated at byte {} while reading {field}",
964 self.offset
965 ))
966 })?;
967 self.offset = end;
968 Ok(bytes.to_vec())
969 }
970
971 fn read_hash(&mut self) -> Result<Hash, OperationCodecError> {
972 Ok(Hash::from_bytes(self.read_exact()?))

Callers 1

read_metadata_valueMethod · 0.80

Calls 2

read_u32Method · 0.80
getMethod · 0.65

Tested by

no test coverage detected