Decode and validate a fixed-width operation-head scope key.
(bytes: &[u8; 17])
| 248 | |
| 249 | /// Decode and validate a fixed-width operation-head scope key. |
| 250 | pub 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 | |
| 271 | struct Encoder { |
| 272 | bytes: Vec<u8>, |
no test coverage detected