pub fn decoding_len_with_offset(
  buf: impl AsRef<Vec<u8>>,
  mut offset: usize,
) -> Result<usize> {
  let buf = buf.as_ref();
  let mut len = 0;
  let mut val = 0u64;

  while offset < buf.len() {
    let next = varint::decode(buf, &mut val);
    offset += next;
    let repeat = next & 1;

    let slice = if repeat > 0 {
      next - (next & 3) / 4
    } else {
      next / 2
    };

    len += slice;
    if repeat == 0 {
      offset += slice;
    }
  }

  ensure!(
    !offset > buf.len(),
    "Invalid RLE bitfield {} > {}",
    offset,
    buf.len()
  );

  Ok(len)
}
/// Returns how many bytes a decoded bitfield will use at a specific offset.
Returns how many bytes a decoded bitfield will use at a specific offset.
Returns how many bytes a decoded bitfield will use at a specific offset .
pub fn decoding_len_with_offset(
  buf: impl AsRef<Vec<u8>>,
  mut offset: usize,
) -> Result<usize> {
  let buf = buf.as_ref();
  let mut len = 0;
  let mut val = 0u64;
  while offset < buf.len() {
    let next = varint::decode(buf, &mut val);
    offset += next;
    let repeat = next & 1;
    let slice = if repeat > 0 {
      next - (next & 3) / 4
    } else {
      next / 2
    };
    len += slice;
    if repeat == 0 {
      offset += slice;
    }
  }
  ensure!(
    !offset > buf.len(),
    "Invalid RLE bitfield {} > {}",
    offset,
    buf.len()
  );
  Ok(len)
}
pub fn decoding_len_with_offset ( buf : impl AsRef < Vec < u8 > > , mut offset : usize , ) -> Result < usize > { let buf = buf . as_ref ( ) ; let mut len = 0 ; let mut val = 0u64 ; while offset < buf . len ( ) { let next = varint :: decode ( buf , & mut val ) ; offset += next ; let repeat = next & 1 ; let slice = if repeat > 0 { next - ( next & 3 ) / 4 } else { next / 2 } ; len += slice ; if repeat == 0 { offset += slice ; } } ensure ! ( offset buf len ( ) " " offset buf len ( ) ) ; Ok ( len ) }
Returns how many bytes a decoded bitfield will use at a specific offset.
Returns how many bytes a decoded bitfield will use at a specific offset .
buf
impl AsRef<Vec<u8>>
offset
usize
buf
impl AsRef<Vec<u8>>
offset
usize