MCPcopy Create free account
hub / github.com/apache/arrow-rs / decode

Method decode

arrow-json/src/reader/tape.rs:341–526  ·  view source on GitHub ↗
(&mut self, buf: &[u8])

Source from the content-addressed store, hash-verified

339 }
340
341 pub fn decode(&mut self, buf: &[u8]) -> Result<usize, ArrowError> {
342 let mut iter = BufIter::new(buf);
343
344 while !iter.is_empty() {
345 let state = match self.stack.last_mut() {
346 Some(l) => l,
347 None => {
348 iter.skip_whitespace();
349 if iter.is_empty() || self.cur_row >= self.batch_size {
350 break;
351 }
352
353 // Start of row
354 self.cur_row += 1;
355 self.stack.push(DecoderState::Value);
356 self.stack.last_mut().unwrap()
357 }
358 };
359
360 match state {
361 // Decoding an object
362 DecoderState::Object(start_idx) => {
363 iter.advance_until(|b| !json_whitespace(b) && b != b',');
364 match next!(iter) {
365 b'"' => {
366 self.stack.push(DecoderState::Value);
367 self.stack.push(DecoderState::Colon);
368 self.stack.push(DecoderState::String);
369 }
370 b'}' => {
371 let start_idx = *start_idx;
372 let end_idx = self.elements.len() as u32;
373 self.elements[start_idx as usize] = TapeElement::StartObject(end_idx);
374 self.elements.push(TapeElement::EndObject(start_idx));
375 self.stack.pop();
376 }
377 b => return Err(err(b, "parsing object")),
378 }
379 }
380 // Decoding a list
381 DecoderState::List(start_idx) => {
382 iter.advance_until(|b| !json_whitespace(b) && b != b',');
383 match iter.peek() {
384 Some(b']') => {
385 iter.next();
386 let start_idx = *start_idx;
387 let end_idx = self.elements.len() as u32;
388 self.elements[start_idx as usize] = TapeElement::StartList(end_idx);
389 self.elements.push(TapeElement::EndList(start_idx));
390 self.stack.pop();
391 }
392 Some(_) => self.stack.push(DecoderState::Value),
393 None => break,
394 }
395 }
396 // Decoding a string
397 DecoderState::String => {
398 let s = iter.skip_chrs(b'\\', b'"');

Callers 3

test_basicFunction · 0.45
test_invalidFunction · 0.45
test_invalid_surrogatesFunction · 0.45

Calls 15

json_whitespaceFunction · 0.85
errFunction · 0.85
LiteralEnum · 0.85
parse_hexFunction · 0.85
write_charFunction · 0.85
char_from_surrogate_pairFunction · 0.85
skip_whitespaceMethod · 0.80
advance_untilMethod · 0.80
skip_chrsMethod · 0.80
extend_from_sliceMethod · 0.80
zipMethod · 0.80
elementMethod · 0.80

Tested by 3

test_basicFunction · 0.36
test_invalidFunction · 0.36
test_invalid_surrogatesFunction · 0.36