MCPcopy Index your code
hub / github.com/RustPython/RustPython / deserialize_value_depth

Function deserialize_value_depth

crates/compiler-core/src/marshal.rs:499–537  ·  view source on GitHub ↗
(
    rdr: &mut R,
    bag: Bag,
    depth: usize,
    refs: &mut Vec<Option<Bag::Value>>,
)

Source from the content-addressed store, hash-verified

497}
498
499fn deserialize_value_depth<R: Read, Bag: MarshalBag>(
500 rdr: &mut R,
501 bag: Bag,
502 depth: usize,
503 refs: &mut Vec<Option<Bag::Value>>,
504) -> Result<Bag::Value> {
505 if depth == 0 {
506 return Err(MarshalError::InvalidBytecode);
507 }
508 let raw = rdr.read_u8()?;
509 let flag = raw & FLAG_REF != 0;
510 let type_code = raw & !FLAG_REF;
511
512 // TYPE_REF: return previously stored object
513 if type_code == Type::Ref as u8 {
514 let idx = rdr.read_u32()? as usize;
515 return refs
516 .get(idx)
517 .and_then(|v| v.clone())
518 .ok_or(MarshalError::InvalidBytecode);
519 }
520
521 // Reserve ref slot before reading (matches write order)
522 let slot = if flag {
523 let idx = refs.len();
524 refs.push(None);
525 Some(idx)
526 } else {
527 None
528 };
529
530 let typ = Type::try_from(type_code)?;
531 let value = deserialize_value_typed(rdr, bag, depth, refs, typ)?;
532
533 if let Some(idx) = slot {
534 refs[idx] = Some(value.clone());
535 }
536 Ok(value)
537}
538
539fn deserialize_value_typed<R: Read, Bag: MarshalBag>(
540 rdr: &mut R,

Callers 2

deserialize_valueFunction · 0.85
deserialize_value_typedFunction · 0.85

Calls 9

deserialize_value_typedFunction · 0.85
read_u8Method · 0.80
read_u32Method · 0.80
ErrClass · 0.50
SomeClass · 0.50
getMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected