Deserialize buffer from a byte array. # Errors If `buf` does not represent a valid serialization of `BlockBuffer`.
(buf: &SerializedBuffer<BS, K>)
| 336 | /// # Errors |
| 337 | /// If `buf` does not represent a valid serialization of `BlockBuffer`. |
| 338 | pub fn deserialize(buf: &SerializedBuffer<BS, K>) -> Result<Self, Error> { |
| 339 | let (pos, block) = buf.split_at(1); |
| 340 | let pos = usize::from(pos[0]); |
| 341 | |
| 342 | if !<K as sealed::Sealed>::invariant(pos, BS::USIZE) { |
| 343 | return Err(Error); |
| 344 | } |
| 345 | |
| 346 | let (data, tail) = block.split_at(pos); |
| 347 | |
| 348 | if tail.iter().any(|&b| b != 0) { |
| 349 | return Err(Error); |
| 350 | } |
| 351 | |
| 352 | let mut res = Self::default(); |
| 353 | unsafe { res.set_data_unchecked(data) }; |
| 354 | Ok(res) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | impl<BS: BlockSizes> BlockBuffer<BS, Eager> { |
nothing calls this directly
no test coverage detected