MCPcopy Create free account
hub / github.com/SoftbearStudios/bitcode / decode

Method decode

src/derive/mod.rs:94–104  ·  view source on GitHub ↗

Like [`decode`], but saves allocations between calls.

(&mut self, mut bytes: &'a [u8])

Source from the content-addressed store, hash-verified

92
93 /// Like [`decode`], but saves allocations between calls.
94 pub fn decode<'a, T: Decode<'a>>(&mut self, mut bytes: &'a [u8]) -> Result<T, Error> {
95 // Safety: Decoders have dangling pointers to `bytes` from previous calls which haven't been
96 // cleared. This isn't an issue in practice because they remain as pointers in FastSlice and
97 // aren't dereferenced. If we wanted to be safer we could clear all the decoders but this
98 // would result in lots of extra code to maintain and a performance/binary size hit.
99 // To detect misuse we run miri tests/cargo fuzz where bytes goes out of scope between calls.
100 let decoder = unsafe { self.registry.get_non_static::<T::Decoder>() };
101 decoder.populate(&mut bytes, 1)?;
102 expect_eof(bytes)?;
103 Ok(decode_inline_never(decoder))
104 }
105}
106
107#[cfg(test)]

Callers 4

decode_in_placeMethod · 0.45
decode_inline_neverFunction · 0.45
decode_in_placeMethod · 0.45
decode_in_placeMethod · 0.45

Calls 3

expect_eofFunction · 0.85
decode_inline_neverFunction · 0.85
populateMethod · 0.45

Tested by

no test coverage detected