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

Method read_string

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

Source from the content-addressed store, hash-verified

923 }
924
925 fn read_string(&mut self, field: &str) -> Result<String, OperationCodecError> {
926 let len = self.read_u32()? as usize;
927 if len == 0 {
928 return Err(OperationCodecError::new(format!("{field} cannot be empty")));
929 }
930 if len > MAX_OPERATION_STRING_BYTES {
931 return Err(OperationCodecError::new(format!(
932 "{field} has {len} UTF-8 bytes, maximum is {MAX_OPERATION_STRING_BYTES}"
933 )));
934 }
935 let end = self
936 .offset
937 .checked_add(len)
938 .ok_or_else(|| OperationCodecError::new("canonical string length overflow"))?;
939 let bytes = self.bytes.get(self.offset..end).ok_or_else(|| {
940 OperationCodecError::new(format!(
941 "canonical object is truncated at byte {} while reading {field}",
942 self.offset
943 ))
944 })?;
945 self.offset = end;
946 String::from_utf8(bytes.to_vec())
947 .map_err(|_| OperationCodecError::new(format!("{field} is not valid UTF-8")))
948 }
949
950 fn read_blob(&mut self, field: &str) -> Result<Vec<u8>, OperationCodecError> {
951 let len = self.read_u32()? as usize;

Callers 8

read_metadata_targetMethod · 0.45
read_view_stateMethod · 0.45
read_git_headMethod · 0.45
read_git_ref_targetMethod · 0.45
read_actorMethod · 0.45
read_loss_noteMethod · 0.45
read_effect_targetMethod · 0.45

Calls 2

read_u32Method · 0.80
getMethod · 0.65

Tested by

no test coverage detected