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

Function decode_operation_scope

atomic-core/src/operation/codec.rs:250–269  ·  view source on GitHub ↗

Decode and validate a fixed-width operation-head scope key.

(bytes: &[u8; 17])

Source from the content-addressed store, hash-verified

248
249/// Decode and validate a fixed-width operation-head scope key.
250pub fn decode_operation_scope(bytes: &[u8; 17]) -> Result<OperationScope, OperationCodecError> {
251 match bytes[0] {
252 OPERATION_SCOPE_REPOSITORY => {
253 if bytes[1..].iter().any(|byte| *byte != 0) {
254 return Err(OperationCodecError::new(
255 "repository operation scope contains non-zero payload bytes",
256 ));
257 }
258 Ok(OperationScope::Repository)
259 }
260 OPERATION_SCOPE_WORKING_COPY => Ok(OperationScope::WorkingCopy(WorkingCopyId::from_bytes(
261 bytes[1..]
262 .try_into()
263 .map_err(|_| OperationCodecError::new("invalid working-copy operation scope"))?,
264 ))),
265 tag => Err(OperationCodecError::new(format!(
266 "unsupported operation scope tag {tag}"
267 ))),
268 }
269}
270
271struct Encoder {
272 bytes: Vec<u8>,

Callers 2

list_operation_headsMethod · 0.85
list_operation_headsMethod · 0.85

Calls 2

WorkingCopyInterface · 0.85
iterMethod · 0.45

Tested by

no test coverage detected