pub fn read_mmap(mmap: &Mmap, checked: bool) -> io::Result<Self> {
        let u32_len = mem::size_of::<u32>();
        let g1_len = mem::size_of::<<E::G1Affine as CurveAffine>::Uncompressed>();
        let g2_len = mem::size_of::<<E::G2Affine as CurveAffine>::Uncompressed>();

        let read_g1 = |mmap: &Mmap, offset: &mut usize| -> io::Result<E::G1Affine> {
            let ptr = &mmap[*offset..*offset + g1_len];
            *offset += g1_len;
            // Safety: this operation is safe, because it's simply
            // casting to a known struct at the correct offset, given
            // the structure of the on-disk data.
            let repr: <E::G1Affine as CurveAffine>::Uncompressed = unsafe {
                *(ptr as *const [u8] as *const <E::G1Affine as CurveAffine>::Uncompressed)
            };

            if checked {
                repr.into_affine()
            } else {
                repr.into_affine_unchecked()
            }
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
            .and_then(|e| {
                if e.is_zero() {
                    Err(io::Error::new(
                        io::ErrorKind::InvalidData,
                        "point at infinity",
                    ))
                } else {
                    Ok(e)
                }
            })
        };

        let read_g2 = |mmap: &Mmap, offset: &mut usize| -> io::Result<E::G2Affine> {
            let ptr = &mmap[*offset..*offset + g2_len];
            *offset += g2_len;
            // Safety: this operation is safe, because it's simply
            // casting to a known struct at the correct offset, given
            // the structure of the on-disk data.
            let repr: <E::G2Affine as CurveAffine>::Uncompressed = unsafe {
                *(ptr as *const [u8] as *const <E::G2Affine as CurveAffine>::Uncompressed)
            };

            if checked {
                repr.into_affine()
            } else {
                repr.into_affine_unchecked()
            }
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
            .and_then(|e| {
                if e.is_zero() {
                    Err(io::Error::new(
                        io::ErrorKind::InvalidData,
                        "point at infinity",
                    ))
                } else {
                    Ok(e)
                }
            })
        };

        let read_length = |mmap: &Mmap, offset: &mut usize| -> Result<usize, std::io::Error> {
            let mut raw_len = &mmap[*offset..*offset + u32_len];
            *offset += u32_len;

            match raw_len.read_u32::<BigEndian>() {
                Ok(len) => Ok(len as usize),
                Err(err) => Err(err),
            }
        };

        let get_g1s = |mmap: &Mmap,
                       offset: &mut usize,
                       param: &mut Vec<E::G1Affine>|
         -> Result<(), std::io::Error> {
            let len = read_length(&mmap, &mut *offset)?;
            for _ in 0..len {
                (*param).push(read_g1(&mmap, &mut *offset)?);
            }

            Ok(())
        };

        let get_g2s = |mmap: &Mmap,
                       offset: &mut usize,
                       param: &mut Vec<E::G2Affine>|
         -> Result<(), std::io::Error> {
            let len = read_length(&mmap, &mut *offset)?;
            for _ in 0..len {
                (*param).push(read_g2(&mmap, &mut *offset)?);
            }

            Ok(())
        };

        let mut offset: usize = 0;
        let vk = VerifyingKey::<E>::read_mmap(&mmap, &mut offset)?;

        let mut h = vec![];
        let mut l = vec![];
        let mut a = vec![];
        let mut b_g1 = vec![];
        let mut b_g2 = vec![];

        get_g1s(&mmap, &mut offset, &mut h)?;
        get_g1s(&mmap, &mut offset, &mut l)?;
        get_g1s(&mmap, &mut offset, &mut a)?;
        get_g1s(&mmap, &mut offset, &mut b_g1)?;
        get_g2s(&mmap, &mut offset, &mut b_g2)?;

        Ok(Parameters {
            vk,
            h: Arc::new(h),
            l: Arc::new(l),
            a: Arc::new(a),
            b_g1: Arc::new(b_g1),
            b_g2: Arc::new(b_g2),
        })
    }
// This method is provided as a proof of concept, but isn't
// advantageous to use (can be called by read_cached_params in
// rust-fil-proofs repo).  It's equivalent to the existing read
// method, in that it loads all parameters to RAM.
This method is provided as a proof of concept, but isn't
advantageous to use (can be called by read_cached_params in
rust-fil-proofs repo).  It's equivalent to the existing read
method, in that it loads all parameters to RAM.
This method is provided as a proof of concept but isn ' t advantageous to use ( can be called by read_cached_params in rust - fil - proofs repo ) . It ' s equivalent to the existing read method in that it loads all parameters to RAM .
pub fn read_mmap(mmap: &Mmap, checked: bool) -> io::Result<Self> {
        let u32_len = mem::size_of::<u32>();
        let g1_len = mem::size_of::<<E::G1Affine as CurveAffine>::Uncompressed>();
        let g2_len = mem::size_of::<<E::G2Affine as CurveAffine>::Uncompressed>();
        let read_g1 = |mmap: &Mmap, offset: &mut usize| -> io::Result<E::G1Affine> {
            let ptr = &mmap[*offset..*offset + g1_len];
            *offset += g1_len;
            // Safety: this operation is safe, because it's simply
            // casting to a known struct at the correct offset, given
            // the structure of the on-disk data.
            let repr: <E::G1Affine as CurveAffine>::Uncompressed = unsafe {
                *(ptr as *const [u8] as *const <E::G1Affine as CurveAffine>::Uncompressed)
            };
            if checked {
                repr.into_affine()
            } else {
                repr.into_affine_unchecked()
            }
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
            .and_then(|e| {
                if e.is_zero() {
                    Err(io::Error::new(
                        io::ErrorKind::InvalidData,
                        "point at infinity",
                    ))
                } else {
                    Ok(e)
                }
            })
        };
        let read_g2 = |mmap: &Mmap, offset: &mut usize| -> io::Result<E::G2Affine> {
            let ptr = &mmap[*offset..*offset + g2_len];
            *offset += g2_len;
            // Safety: this operation is safe, because it's simply
            // casting to a known struct at the correct offset, given
            // the structure of the on-disk data.
            let repr: <E::G2Affine as CurveAffine>::Uncompressed = unsafe {
                *(ptr as *const [u8] as *const <E::G2Affine as CurveAffine>::Uncompressed)
            };
            if checked {
                repr.into_affine()
            } else {
                repr.into_affine_unchecked()
            }
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
            .and_then(|e| {
                if e.is_zero() {
                    Err(io::Error::new(
                        io::ErrorKind::InvalidData,
                        "point at infinity",
                    ))
                } else {
                    Ok(e)
                }
            })
        };
        let read_length = |mmap: &Mmap, offset: &mut usize| -> Result<usize, std::io::Error> {
            let mut raw_len = &mmap[*offset..*offset + u32_len];
            *offset += u32_len;
            match raw_len.read_u32::<BigEndian>() {
                Ok(len) => Ok(len as usize),
                Err(err) => Err(err),
            }
        };
        let get_g1s = |mmap: &Mmap,
                       offset: &mut usize,
                       param: &mut Vec<E::G1Affine>|
         -> Result<(), std::io::Error> {
            let len = read_length(&mmap, &mut *offset)?;
            for _ in 0..len {
                (*param).push(read_g1(&mmap, &mut *offset)?);
            }
            Ok(())
        };
        let get_g2s = |mmap: &Mmap,
                       offset: &mut usize,
                       param: &mut Vec<E::G2Affine>|
         -> Result<(), std::io::Error> {
            let len = read_length(&mmap, &mut *offset)?;
            for _ in 0..len {
                (*param).push(read_g2(&mmap, &mut *offset)?);
            }
            Ok(())
        };
        let mut offset: usize = 0;
        let vk = VerifyingKey::<E>::read_mmap(&mmap, &mut offset)?;
        let mut h = vec![];
        let mut l = vec![];
        let mut a = vec![];
        let mut b_g1 = vec![];
        let mut b_g2 = vec![];
        get_g1s(&mmap, &mut offset, &mut h)?;
        get_g1s(&mmap, &mut offset, &mut l)?;
        get_g1s(&mmap, &mut offset, &mut a)?;
        get_g1s(&mmap, &mut offset, &mut b_g1)?;
        get_g2s(&mmap, &mut offset, &mut b_g2)?;
        Ok(Parameters {
            vk,
            h: Arc::new(h),
            l: Arc::new(l),
            a: Arc::new(a),
            b_g1: Arc::new(b_g1),
            b_g2: Arc::new(b_g2),
        })
    }
pub fn read_mmap ( mmap : & Mmap , checked : bool ) -> io :: Result < Self > { let u32_len = mem :: size_of :: < u32 > ( ) ; let g1_len = mem :: size_of :: < < E :: G1Affine as CurveAffine > :: Uncompressed > ( ) ; let g2_len = mem :: size_of :: < < E :: G2Affine as CurveAffine > :: Uncompressed > ( ) ; let read_g1 = | mmap : & Mmap , offset : & mut usize | -> io :: Result < E :: G1Affine > { let ptr = & mmap [ * offset .. * offset + g1_len ] ; * offset += g1_len ; // Safety: this operation is safe, because it's simply // casting to a known struct at the correct offset, given // the structure of the on-disk data. let repr : < E :: G1Affine as CurveAffine > :: Uncompressed = unsafe { * ( ptr as * const [ u8 ] as * const < E :: G1Affine as CurveAffine > :: Uncompressed ) } ; if checked { repr . into_affine ( ) } else { repr . into_affine_unchecked ( ) } . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) . and_then ( | e | { if e . is_zero ( ) { Err ( io :: Error :: new ( io :: ErrorKind :: InvalidData , " " , ) ) } else { Ok ( e ) } } ) } ; let read_g2 = | mmap : & Mmap , offset : & mut usize | -> io :: Result < E :: G2Affine > { let ptr = & mmap [ * offset .. * offset + g2_len ] ; * offset += g2_len ; // Safety: this operation is safe, because it's simply // casting to a known struct at the correct offset, given // the structure of the on-disk data. let repr : < E :: G2Affine as CurveAffine > :: Uncompressed = unsafe { * ( ptr as * const [ u8 ] as * const < E :: G2Affine as CurveAffine > :: Uncompressed ) } ; if checked { repr . into_affine ( ) } else { repr . into_affine_unchecked ( ) } . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) . and_then ( | e | { if e . is_zero ( ) { Err ( io :: Error :: new ( io :: ErrorKind :: InvalidData , " " , ) ) } else { Ok ( e ) } } ) } ; let read_length = | mmap : & Mmap , offset : & mut usize | -> Result < usize , std :: io :: Error > { let mut raw_len = & mmap [ * offset .. * offset + u32_len ] ; * offset += u32_len ; match raw_len . read_u32 :: < BigEndian > ( ) { Ok ( len ) => Ok ( len as usize ) , Err ( err ) => Err ( err ) , } } ; let get_g1s = | mmap : & Mmap , offset : & mut usize , param : & mut Vec < E :: G1Affine > | -> Result < ( ) , std :: io :: Error > { let len = read_length ( & mmap , & mut * offset ) ? ; for _ in 0 .. len { ( * param ) . push ( read_g1 ( & mmap , & mut * offset ) ? ) ; } Ok ( ( ) ) } ; let get_g2s = | mmap : & Mmap , offset : & mut usize , param : & mut Vec < E :: G2Affine > | -> Result < ( ) , std :: io :: Error > { let len = read_length ( & mmap , & mut * offset ) ? ; for _ in 0 .. len { ( * param ) . push ( read_g2 ( & mmap , & mut * offset ) ? ) ; } Ok ( ( ) ) } ; let mut offset : usize = 0 ; let vk = VerifyingKey :: < E > :: read_mmap ( & mmap , & mut offset ) ? ; let mut h = vec ! [ ] ; let mut l = vec ! [ ] ; let mut a = vec ! [ ] ; let mut b_g1 = vec ! [ ] ; let mut b_g2 = vec ! [ ] ; get_g1s ( & mmap , & mut offset , & mut h ) ? ; get_g1s ( & mmap , & mut offset , & mut l ) ? ; get_g1s ( & mmap , & mut offset , & mut a ) ? ; get_g1s ( & mmap , & mut offset , & mut b_g1 ) ? ; get_g2s ( & mmap , & mut offset , & mut b_g2 ) ? ; Ok ( Parameters { vk , h : Arc :: new ( h ) , l : Arc :: new ( l ) , a : Arc :: new ( a ) , b_g1 : Arc :: new ( b_g1 ) , b_g2 : Arc :: new ( b_g2 ) , } ) }
This method is provided as a proof of concept, but isn't
advantageous to use (can be called by read_cached_params in
rust-fil-proofs repo).
This method is provided as a proof of concept but isn ' t advantageous to use ( can be called by read_cached_params in rust - fil - proofs repo ) .
mmap
&Mmap
checked
bool
mmap
&Mmap
checked
bool