Encode a fixed-width operation-head scope key.
(scope: OperationScope)
| 235 | |
| 236 | /// Encode a fixed-width operation-head scope key. |
| 237 | pub fn encode_operation_scope(scope: OperationScope) -> [u8; 17] { |
| 238 | let mut key = [0u8; 17]; |
| 239 | match scope { |
| 240 | OperationScope::Repository => key[0] = OPERATION_SCOPE_REPOSITORY, |
| 241 | OperationScope::WorkingCopy(id) => { |
| 242 | key[0] = OPERATION_SCOPE_WORKING_COPY; |
| 243 | key[1..].copy_from_slice(id.as_bytes()); |
| 244 | } |
| 245 | } |
| 246 | key |
| 247 | } |
| 248 | |
| 249 | /// Decode and validate a fixed-width operation-head scope key. |
| 250 | pub fn decode_operation_scope(bytes: &[u8; 17]) -> Result<OperationScope, OperationCodecError> { |