Decode a versioned canonical sorted multi-head value.
(bytes: &[u8])
| 216 | |
| 217 | /// Decode a versioned canonical sorted multi-head value. |
| 218 | pub fn decode_operation_heads(bytes: &[u8]) -> Result<OperationHeads, OperationCodecError> { |
| 219 | let mut decoder = Decoder::new(bytes)?; |
| 220 | decoder.expect_version(OPERATION_HEADS_VERSION, "operation heads")?; |
| 221 | let count = decoder.read_count("operation heads")?; |
| 222 | let mut heads = Vec::with_capacity(count); |
| 223 | for _ in 0..count { |
| 224 | heads.push(decoder.read_operation_id()?); |
| 225 | } |
| 226 | decoder.finish()?; |
| 227 | let heads = OperationHeads::from_canonical(heads)?; |
| 228 | if encode_operation_heads(&heads)? != bytes { |
| 229 | return Err(OperationCodecError::new( |
| 230 | "operation heads are not canonically encoded", |
| 231 | )); |
| 232 | } |
| 233 | Ok(heads) |
| 234 | } |
| 235 | |
| 236 | /// Encode a fixed-width operation-head scope key. |
| 237 | pub fn encode_operation_scope(scope: OperationScope) -> [u8; 17] { |
no test coverage detected