// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
impl UnconditionalCoder<()> for String { type Nonserialized = Empty; fn read_unconditional(
_: &(),
br: &mut BitReader,
nonserialized: &Self::Nonserialized,
) -> Result<String, Error> { let len = u32::read_unconditional(
&U32Coder::Select(
U32::Val(0),
U32::Bits(4),
U32::BitsOffset { n: 5, off: 16 },
U32::BitsOffset { n: 10, off: 48 },
),
br,
nonserialized,
)?; letmut ret = String::new();
ret.reserve(len as usize); for _ in0..len { match br.read_noinline(8) {
Ok(c) => ret.push(c as u8 as char),
Err(Error::OutOfBounds(n)) => { // Use saturating arithmetic to prevent underflow on malformed input // ret.len()+1 cannot overflow since ret.len() <= isize::MAX let remaining = (len as usize)
.saturating_add(n)
.saturating_sub(ret.len() + 1); return Err(Error::OutOfBounds(remaining));
}
Err(e) => return Err(e),
}
}
Ok(ret)
}
}
impl UnconditionalCoder<()> for Permutation { type Nonserialized = PermutationNonserialized; fn read_unconditional(
_: &(),
br: &mut BitReader,
nonserialized: &Self::Nonserialized,
) -> Result<Permutation, Error> { // TODO: This is quadratic when incrementally parsing byte by byte, // we might want to find a better way of reading the permutation. let ret = if nonserialized.permuted { let size = nonserialized.num_entries; let num_contexts = 8; let histograms = Histograms::decode(num_contexts, br, /*allow_lz77=*/ true)?; letmut reader = SymbolReader::new(&histograms, br, None)?;
Permutation::decode(size, 0, &histograms, br, &mut reader)
} else {
Ok(Permutation::default())
};
br.jump_to_byte_boundary()?;
ret
}
}
// TODO(veluca93): this will likely need to be implemented differently if // there are extensions. #[derive(Debug, PartialEq, Default, Clone)] pubstruct Extensions {}
impl UnconditionalCoder<()> for Extensions { type Nonserialized = Empty; fn read_unconditional(
_: &(),
br: &mut BitReader,
_: &Self::Nonserialized,
) -> Result<Extensions, Error> { let selector = u64::read_unconditional(&(), br, &Empty {})?; letmut total_size: u64 = 0; for i in0..64 { if (selector & (1u64 << i)) != 0 { let size = u64::read_unconditional(&(), br, &Empty {})?; let sum = total_size.checked_add(size); iflet Some(s) = sum {
total_size = s;
} else { return Err(Error::SizeOverflow);
}
}
} let total_size = usize::try_from(total_size); iflet Ok(ts) = total_size {
br.skip_bits(ts)?;
} else { return Err(Error::SizeOverflow);
}
Ok(Extensions {})
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.