MCPcopy Create free account
hub / github.com/awslabs/llrt / flush

Method flush

modules/llrt_string_decoder/src/string_decoder.rs:194–212  ·  view source on GitHub ↗
(&mut self, ctx: &Ctx<'_>)

Source from the content-addressed store, hash-verified

192 }
193
194 fn flush(&mut self, ctx: &Ctx<'_>) -> Result<String> {
195 let odd_utf16_byte =
196 matches!(self.encoder, Encoder::Utf16le) && self.buffered_bytes % 2 == 1;
197
198 if odd_utf16_byte {
199 // Ignore a single trailing byte, like the JS decoder does.
200 self.missing_bytes -= 1;
201 self.buffered_bytes -= 1;
202 }
203
204 if self.buffered_bytes == 0 {
205 return Ok(String::new());
206 }
207
208 let decode_len = self.buffer.len() - usize::from(odd_utf16_byte);
209
210 let mut res = self.make_string(ctx, &self.buffer[..decode_len])?;
211
212 if odd_utf16_byte && decode_len >= 2 {
213 let code_unit =
214 u16::from_le_bytes([self.buffer[decode_len - 2], self.buffer[decode_len - 1]]);
215 if (0xD800..=0xDBFF).contains(&code_unit) {

Callers 7

write_fileFunction · 0.45
serverFunction · 0.45
call_tcpFunction · 0.45
endMethod · 0.45
generate_bytecode_cacheFunction · 0.45
decompress_chunkMethod · 0.45

Calls 2

make_stringMethod · 0.80
clearMethod · 0.65

Tested by

no test coverage detected