fn deserialize_cell<T>(
    src: &mut T,
    ref_size: usize,
    cell_index: usize,
    cells_count: usize, 
    cell_size_opt: Option<usize>
) -> Result<RawCell> where T: Read {

    let d1 = src.read_byte()? as usize;
    let level = (d1 >> 5) as u8; // level // TODO not foget about level mask
    let hashes = (d1 & 16) == 16; // with hashes
    let exotic = (d1 & 8) == 8; // exotic
    let refs = d1 & 7;	// refs count
    let absent = refs == 7 && hashes;

    if absent {
        // TODO ABSENT CELLS are NOT serialized right way. 
        // Need to rewrite as soon as right way will be known.
        //
        // For absent cells (i.e., external references), only d1 is present, always equal to 23 + 32l.
        let data_size = SHA256_SIZE * ((LevelMask::with_mask(level).level() + 1) as usize);
        let mut cell_data = [0; 128];
        src.read_exact(&mut cell_data[..data_size])?;
        cell_data[data_size] = 0x80;

        return Ok(RawCell { 
            data: SmallVec::from_slice(&cell_data[0..data_size + 1]),
            refs: SmallVec::new(),
            level,
            cell_type: CellType::Ordinary,
            hashes: None,
            depths: None, 
        });
    }
    
    if refs > 4 {
        fail!("refs count has to be less or equal 4, actual value: {}", refs)
    }

    let d2 = src.read_byte()?;
    let data_size = ((d2 >> 1) + if d2 & 1 != 0 { 1 } else { 0 }) as usize;	
    let no_completion_tag = d2 & 1 == 0;		
    let full_cell_size = ref_size * refs + 2 + data_size +
                            if hashes { (1 + level as usize) * (SHA256_SIZE + DEPTH_SIZE) } else { 0 };
    
    if let Some(cell_size) = cell_size_opt {
        if full_cell_size != cell_size {
            fail!("cell sizes have to be same, expected: {}, real: {}", full_cell_size, cell_size)
        }
    }
    
    let (hashes_opt, depths_opt) = if hashes {
        let mut hashes = [UInt256::default(), UInt256::default(), UInt256::default(), UInt256::default()];
        let mut depths = [0; 4];
        let mut u256 = [0; SHA256_SIZE];
        let level = LevelMask::with_mask(level).level() as usize;
        for hash in hashes.iter_mut().take(level + 1) {
            src.read_exact(&mut u256)?;
            *hash = UInt256::from(u256);
        }
        for depth in depths.iter_mut().take(level + 1) {
            *depth = src.read_be_uint(DEPTH_SIZE)? as u16;
        }
        (Some(hashes), Some(depths))
    } else {
        (None, None)
    };

    let cell_size = data_size + if no_completion_tag { 1 } else { 0 };
    let mut cell_data = [0; 128];
    src.read_exact(&mut cell_data[..data_size])?;

    // If complition tag was not serialized, we must add it (it is need for SliceData)
    if no_completion_tag {
        cell_data[data_size] = 0x80; 
    }
    
    let cell_type = if !exotic { CellType::Ordinary } else { CellType::from(cell_data[0]) };

    //println!("{} l={} h={} s={} r={}", cell_type, level, hashes, exotic, refs);

    let mut references = SmallVec::with_capacity(refs);
    for _ in 0..refs {
        let i = src.read_be_uint(ref_size)?;
        if i > cells_count || i <= cell_index {
            fail!("reference out of range, {} < (value: {}) <= {}", cells_count, i, cell_index)
        } else {
            references.push(i as u32);
        }
    }

    Ok(RawCell { 
        data: SmallVec::from_slice(&cell_data[0..cell_size]),
        refs: references,
        level,
        cell_type,
        hashes: hashes_opt,
        depths: depths_opt, 
    })
}
/*
Deserialization separately data and referensed cells indexes.
Returns cell data, their refs (as indexes), and total read data size.
*/
Deserialization separately data and referensed cells indexes.
Returns cell data, their refs (as indexes), and total read data size.
Deserialization separately data and referensed cells indexes . Returns cell data their refs ( as indexes ) and total read data size .
fn deserialize_cell<T>(
    src: &mut T,
    ref_size: usize,
    cell_index: usize,
    cells_count: usize, 
    cell_size_opt: Option<usize>
) -> Result<RawCell> where T: Read {
    let d1 = src.read_byte()? as usize;
    let level = (d1 >> 5) as u8; // level // TODO not foget about level mask
    let hashes = (d1 & 16) == 16; // with hashes
    let exotic = (d1 & 8) == 8; // exotic
    let refs = d1 & 7;	// refs count
    let absent = refs == 7 && hashes;
    if absent {
        // TODO ABSENT CELLS are NOT serialized right way. 
        // Need to rewrite as soon as right way will be known.
        //
        // For absent cells (i.e., external references), only d1 is present, always equal to 23 + 32l.
        let data_size = SHA256_SIZE * ((LevelMask::with_mask(level).level() + 1) as usize);
        let mut cell_data = [0; 128];
        src.read_exact(&mut cell_data[..data_size])?;
        cell_data[data_size] = 0x80;
        return Ok(RawCell { 
            data: SmallVec::from_slice(&cell_data[0..data_size + 1]),
            refs: SmallVec::new(),
            level,
            cell_type: CellType::Ordinary,
            hashes: None,
            depths: None, 
        });
    }
    if refs > 4 {
        fail!("refs count has to be less or equal 4, actual value: {}", refs)
    }
    let d2 = src.read_byte()?;
    let data_size = ((d2 >> 1) + if d2 & 1 != 0 { 1 } else { 0 }) as usize;	
    let no_completion_tag = d2 & 1 == 0;		
    let full_cell_size = ref_size * refs + 2 + data_size +
                            if hashes { (1 + level as usize) * (SHA256_SIZE + DEPTH_SIZE) } else { 0 };
    if let Some(cell_size) = cell_size_opt {
        if full_cell_size != cell_size {
            fail!("cell sizes have to be same, expected: {}, real: {}", full_cell_size, cell_size)
        }
    }
    let (hashes_opt, depths_opt) = if hashes {
        let mut hashes = [UInt256::default(), UInt256::default(), UInt256::default(), UInt256::default()];
        let mut depths = [0; 4];
        let mut u256 = [0; SHA256_SIZE];
        let level = LevelMask::with_mask(level).level() as usize;
        for hash in hashes.iter_mut().take(level + 1) {
            src.read_exact(&mut u256)?;
            *hash = UInt256::from(u256);
        }
        for depth in depths.iter_mut().take(level + 1) {
            *depth = src.read_be_uint(DEPTH_SIZE)? as u16;
        }
        (Some(hashes), Some(depths))
    } else {
        (None, None)
    };
    let cell_size = data_size + if no_completion_tag { 1 } else { 0 };
    let mut cell_data = [0; 128];
    src.read_exact(&mut cell_data[..data_size])?;
    // If complition tag was not serialized, we must add it (it is need for SliceData)
    if no_completion_tag {
        cell_data[data_size] = 0x80; 
    }
    let cell_type = if !exotic { CellType::Ordinary } else { CellType::from(cell_data[0]) };
    //println!("{} l={} h={} s={} r={}", cell_type, level, hashes, exotic, refs);
    let mut references = SmallVec::with_capacity(refs);
    for _ in 0..refs {
        let i = src.read_be_uint(ref_size)?;
        if i > cells_count || i <= cell_index {
            fail!("reference out of range, {} < (value: {}) <= {}", cells_count, i, cell_index)
        } else {
            references.push(i as u32);
        }
    }
    Ok(RawCell { 
        data: SmallVec::from_slice(&cell_data[0..cell_size]),
        refs: references,
        level,
        cell_type,
        hashes: hashes_opt,
        depths: depths_opt, 
    })
}
fn deserialize_cell < T > ( src : & mut T , ref_size : usize , cell_index : usize , cells_count : usize , cell_size_opt : Option < usize > ) -> Result < RawCell > where T : Read { let d1 = src . read_byte ( ) ? as usize ; let level = ( d1 >> 5 ) as u8 ; // level // TODO not foget about level mask let hashes = ( d1 & 16 ) == 16 ; // with hashes let exotic = ( d1 & 8 ) == 8 ; // exotic let refs = d1 & 7 ; // refs count let absent = refs == 7 && hashes ; if absent { // TODO ABSENT CELLS are NOT serialized right way.  // Need to rewrite as soon as right way will be known. // // For absent cells (i.e., external references), only d1 is present, always equal to 23 + 32l. let data_size = SHA256_SIZE * ( ( LevelMask :: with_mask ( level ) . level ( ) + 1 ) as usize ) ; let mut cell_data = [ 0 ; 128 ] ; src . read_exact ( & mut cell_data [ .. data_size ] ) ? ; cell_data [ data_size ] = 0x80 ; return Ok ( RawCell { data : SmallVec :: from_slice ( & cell_data [ 0 .. data_size + 1 ] ) , refs : SmallVec :: new ( ) , level , cell_type : CellType :: Ordinary , hashes : None , depths : None , } ) ; } if refs > 4 { fail ! ( " " refs ) } let d2 = src . read_byte ( ) ? ; let data_size = ( ( d2 >> 1 ) + if d2 & 1 != 0 { 1 } else { 0 } ) as usize ; let no_completion_tag = d2 & 1 == 0 ; let full_cell_size = ref_size * refs + 2 + data_size + if hashes { ( 1 + level as usize ) * ( SHA256_SIZE + DEPTH_SIZE ) } else { 0 } ; if let Some ( cell_size ) = cell_size_opt { if full_cell_size != cell_size { fail ! ( " " full_cell_size cell_size ) } } let ( hashes_opt , depths_opt ) = if hashes { let mut hashes = [ UInt256 :: default ( ) , UInt256 :: default ( ) , UInt256 :: default ( ) , UInt256 :: default ( ) ] ; let mut depths = [ 0 ; 4 ] ; let mut u256 = [ 0 ; SHA256_SIZE ] ; let level = LevelMask :: with_mask ( level ) . level ( ) as usize ; for hash in hashes . iter_mut ( ) . take ( level + 1 ) { src . read_exact ( & mut u256 ) ? ; * hash = UInt256 :: from ( u256 ) ; } for depth in depths . iter_mut ( ) . take ( level + 1 ) { * depth = src . read_be_uint ( DEPTH_SIZE ) ? as u16 ; } ( Some ( hashes ) , Some ( depths ) ) } else { ( None , None ) } ; let cell_size = data_size + if no_completion_tag { 1 } else { 0 } ; let mut cell_data = [ 0 ; 128 ] ; src . read_exact ( & mut cell_data [ .. data_size ] ) ? ; // If complition tag was not serialized, we must add it (it is need for SliceData) if no_completion_tag { cell_data [ data_size ] = 0x80 ; } let cell_type = if ! exotic { CellType :: Ordinary } else { CellType :: from ( cell_data [ 0 ] ) } ; //println!("{} l={} h={} s={} r={}", cell_type, level, hashes, exotic, refs); let mut references = SmallVec :: with_capacity ( refs ) ; for _ in 0 .. refs { let i = src . read_be_uint ( ref_size ) ? ; if i > cells_count || i <= cell_index { fail ! ( " " cells_count i cell_index ) } else { references . push ( i as u32 ) ; } } Ok ( RawCell { data : SmallVec :: from_slice ( & cell_data [ 0 .. cell_size ] ) , refs : references , level , cell_type , hashes : hashes_opt , depths : depths_opt , } ) }
Deserialization separately data and referensed cells indexes.
Deserialization separately data and referensed cells indexes .
src
&mut T
ref_size
usize
cell_index
usize
cells_count
usize
cell_size_opt
Option<usize>
src
&mut T
ref_size
usize
cell_index
usize
cells_count
usize
cell_size_opt
Option<usize>