pub fn export(&self, metrics: &mut [&mut MMVWriter]) -> io::Result<()> {
        let mut ws = MMVWriterState::new();

        let mut mmv_ver = Version::V1;
        for m in metrics.iter() {
            if m.has_mmv2_string() {
                mmv_ver = Version::V2;
                break;
            }
        }

        for m in metrics.iter() {
            m.register(&mut ws, mmv_ver);
        }

        if ws.n_metrics > 0 {
            ws.n_toc += 2 /* Metric and Value TOC */;
        }

        if ws.n_strings > 0 {
            ws.n_toc += 1 /* String TOC */;
        }

        if ws.n_indoms > 0 {
            ws.n_toc += 2 /* Indom and Instance TOC */;
        }

        /*
            MMV layout:

            -- MMV Header
            
            -- Instance Domain TOC Block
            -- Instances TOC Block
            -- Metrics TOC Block
            -- Values TOC Block
            -- Strings TOC Block

            -- Instance Domain section
            -- Instances section
            -- Metrics section
            -- Values section
            -- Strings section
            
            After writing, every metric is given ownership
            of the respective memory-mapped slice that contains
            the metric's value. This is to ensure that the metric
            is *only* able to write to it's value's slice when updating
            it's value.
        */

        let hdr_toc_len = HDR_LEN + TOC_BLOCK_LEN*ws.n_toc;

        ws.indom_sec_off = hdr_toc_len;
        ws.instance_sec_off =
            ws.indom_sec_off
            + INDOM_BLOCK_LEN*ws.n_indoms;
        
        let (instance_blk_len, metric_blk_len) = match mmv_ver {
            Version::V1 => (INSTANCE_BLOCK_LEN_MMV1, METRIC_BLOCK_LEN_MMV1),
            Version::V2 => (INSTANCE_BLOCK_LEN_MMV2, METRIC_BLOCK_LEN_MMV2)
        };

        ws.metric_sec_off =
            ws.instance_sec_off
            + instance_blk_len*ws.n_instances;
        ws.value_sec_off =
            ws.metric_sec_off
            + metric_blk_len*ws.n_metrics;
        ws.string_sec_off =
            ws.value_sec_off
            + VALUE_BLOCK_LEN*ws.n_values;

        let mmv_size = (
            ws.string_sec_off
            + STRING_BLOCK_LEN*ws.n_strings
        ) as usize;

        let mut file = OpenOptions::new()
            .read(true)
            .write(true)
            .create(true)
            .truncate(true)
            .open(&self.mmv_path)?;

        file.write(&vec![0; mmv_size])?;

        ws.mmap_view = Some(
            Mmap::open(&file, Protection::ReadWrite)?.into_view_sync()
        );

        let mut mmap_view = unsafe { ws.mmap_view.as_mut().unwrap().clone() };
        let mut c = Cursor::new(unsafe { mmap_view.as_mut_slice() });

        ws.flags = self.flags.bits();
        ws.cluster_id = self.cluster_id;
        write_mmv_header(&mut ws, &mut c, mmv_ver)?;

        write_toc_block(1, ws.n_indoms as u32, ws.indom_sec_off, &mut c)?;
        write_toc_block(2, ws.n_instances as u32, ws.instance_sec_off, &mut c)?;
        write_toc_block(3, ws.n_metrics as u32, ws.metric_sec_off, &mut c)?;
        write_toc_block(4, ws.n_values as u32, ws.value_sec_off, &mut c)?;
        write_toc_block(5, ws.n_strings as u32, ws.string_sec_off, &mut c)?;

        for m in metrics.iter_mut() {
            m.write(&mut ws, &mut c, mmv_ver)?;
        }

        // unlock header; has to be done last
        c.set_position(ws.gen2_off);
        c.write_i64::<Endian>(ws.gen)?;
        
        Ok(())
    }
/// Exports metrics to an MMV file at `mmv_path`
///
/// If an MMV file is already present at `mmv_path`, it's overwritten
/// with the newer metrics.
Exports metrics to an MMV file at `mmv_path`
If an MMV file is already present at `mmv_path`, it's overwritten
with the newer metrics.
Exports metrics to an MMV file at ` mmv_path ` If an MMV file is already present at ` mmv_path ` it ' s overwritten with the newer metrics .
pub fn export(&self, metrics: &mut [&mut MMVWriter]) -> io::Result<()> {
        let mut ws = MMVWriterState::new();
        let mut mmv_ver = Version::V1;
        for m in metrics.iter() {
            if m.has_mmv2_string() {
                mmv_ver = Version::V2;
                break;
            }
        }
        for m in metrics.iter() {
            m.register(&mut ws, mmv_ver);
        }
        if ws.n_metrics > 0 {
            ws.n_toc += 2 /* Metric and Value TOC */;
        }
        if ws.n_strings > 0 {
            ws.n_toc += 1 /* String TOC */;
        }
        if ws.n_indoms > 0 {
            ws.n_toc += 2 /* Indom and Instance TOC */;
        }
        /*
            MMV layout:
            -- MMV Header
            -- Instance Domain TOC Block
            -- Instances TOC Block
            -- Metrics TOC Block
            -- Values TOC Block
            -- Strings TOC Block
            -- Instance Domain section
            -- Instances section
            -- Metrics section
            -- Values section
            -- Strings section
            After writing, every metric is given ownership
            of the respective memory-mapped slice that contains
            the metric's value. This is to ensure that the metric
            is *only* able to write to it's value's slice when updating
            it's value.
        */
        let hdr_toc_len = HDR_LEN + TOC_BLOCK_LEN*ws.n_toc;
        ws.indom_sec_off = hdr_toc_len;
        ws.instance_sec_off =
            ws.indom_sec_off
            + INDOM_BLOCK_LEN*ws.n_indoms;
        let (instance_blk_len, metric_blk_len) = match mmv_ver {
            Version::V1 => (INSTANCE_BLOCK_LEN_MMV1, METRIC_BLOCK_LEN_MMV1),
            Version::V2 => (INSTANCE_BLOCK_LEN_MMV2, METRIC_BLOCK_LEN_MMV2)
        };
        ws.metric_sec_off =
            ws.instance_sec_off
            + instance_blk_len*ws.n_instances;
        ws.value_sec_off =
            ws.metric_sec_off
            + metric_blk_len*ws.n_metrics;
        ws.string_sec_off =
            ws.value_sec_off
            + VALUE_BLOCK_LEN*ws.n_values;
        let mmv_size = (
            ws.string_sec_off
            + STRING_BLOCK_LEN*ws.n_strings
        ) as usize;
        let mut file = OpenOptions::new()
            .read(true)
            .write(true)
            .create(true)
            .truncate(true)
            .open(&self.mmv_path)?;
        file.write(&vec![0; mmv_size])?;
        ws.mmap_view = Some(
            Mmap::open(&file, Protection::ReadWrite)?.into_view_sync()
        );
        let mut mmap_view = unsafe { ws.mmap_view.as_mut().unwrap().clone() };
        let mut c = Cursor::new(unsafe { mmap_view.as_mut_slice() });
        ws.flags = self.flags.bits();
        ws.cluster_id = self.cluster_id;
        write_mmv_header(&mut ws, &mut c, mmv_ver)?;
        write_toc_block(1, ws.n_indoms as u32, ws.indom_sec_off, &mut c)?;
        write_toc_block(2, ws.n_instances as u32, ws.instance_sec_off, &mut c)?;
        write_toc_block(3, ws.n_metrics as u32, ws.metric_sec_off, &mut c)?;
        write_toc_block(4, ws.n_values as u32, ws.value_sec_off, &mut c)?;
        write_toc_block(5, ws.n_strings as u32, ws.string_sec_off, &mut c)?;
        for m in metrics.iter_mut() {
            m.write(&mut ws, &mut c, mmv_ver)?;
        }
        // unlock header; has to be done last
        c.set_position(ws.gen2_off);
        c.write_i64::<Endian>(ws.gen)?;
        Ok(())
    }
pub fn export ( & self , metrics : & mut [ & mut MMVWriter ] ) -> io :: Result < ( ) > { let mut ws = MMVWriterState :: new ( ) ; let mut mmv_ver = Version :: V1 ; for m in metrics . iter ( ) { if m . has_mmv2_string ( ) { mmv_ver = Version :: V2 ; break ; } } for m in metrics . iter ( ) { m . register ( & mut ws , mmv_ver ) ; } if ws . n_metrics > 0 { ws . n_toc += 2 /* Metric and Value TOC */ ; } if ws . n_strings > 0 { ws . n_toc += 1 /* String TOC */ ; } if ws . n_indoms > 0 { ws . n_toc += 2 /* Indom and Instance TOC */ ; } /*
            MMV layout:

            -- MMV Header
            
            -- Instance Domain TOC Block
            -- Instances TOC Block
            -- Metrics TOC Block
            -- Values TOC Block
            -- Strings TOC Block

            -- Instance Domain section
            -- Instances section
            -- Metrics section
            -- Values section
            -- Strings section
            
            After writing, every metric is given ownership
            of the respective memory-mapped slice that contains
            the metric's value. This is to ensure that the metric
            is *only* able to write to it's value's slice when updating
            it's value.
        */ let hdr_toc_len = HDR_LEN + TOC_BLOCK_LEN * ws . n_toc ; ws . indom_sec_off = hdr_toc_len ; ws . instance_sec_off = ws . indom_sec_off + INDOM_BLOCK_LEN * ws . n_indoms ; let ( instance_blk_len , metric_blk_len ) = match mmv_ver { Version :: V1 => ( INSTANCE_BLOCK_LEN_MMV1 , METRIC_BLOCK_LEN_MMV1 ) , Version :: V2 => ( INSTANCE_BLOCK_LEN_MMV2 , METRIC_BLOCK_LEN_MMV2 ) } ; ws . metric_sec_off = ws . instance_sec_off + instance_blk_len * ws . n_instances ; ws . value_sec_off = ws . metric_sec_off + metric_blk_len * ws . n_metrics ; ws . string_sec_off = ws . value_sec_off + VALUE_BLOCK_LEN * ws . n_values ; let mmv_size = ( ws . string_sec_off + STRING_BLOCK_LEN * ws . n_strings ) as usize ; let mut file = OpenOptions :: new ( ) . read ( true ) . write ( true ) . create ( true ) . truncate ( true ) . open ( & self . mmv_path ) ? ; file . write ( & vec ! [ 0 mmv_size ] ) ? ; ws . mmap_view = Some ( Mmap :: open ( & file , Protection :: ReadWrite ) ? . into_view_sync ( ) ) ; let mut mmap_view = unsafe { ws . mmap_view . as_mut ( ) . unwrap ( ) . clone ( ) } ; let mut c = Cursor :: new ( unsafe { mmap_view . as_mut_slice ( ) } ) ; ws . flags = self . flags . bits ( ) ; ws . cluster_id = self . cluster_id ; write_mmv_header ( & mut ws , & mut c , mmv_ver ) ? ; write_toc_block ( 1 , ws . n_indoms as u32 , ws . indom_sec_off , & mut c ) ? ; write_toc_block ( 2 , ws . n_instances as u32 , ws . instance_sec_off , & mut c ) ? ; write_toc_block ( 3 , ws . n_metrics as u32 , ws . metric_sec_off , & mut c ) ? ; write_toc_block ( 4 , ws . n_values as u32 , ws . value_sec_off , & mut c ) ? ; write_toc_block ( 5 , ws . n_strings as u32 , ws . string_sec_off , & mut c ) ? ; for m in metrics . iter_mut ( ) { m . write ( & mut ws , & mut c , mmv_ver ) ? ; } // unlock header; has to be done last c . set_position ( ws . gen2_off ) ; c . write_i64 :: < Endian > ( ws . gen ) ? ; Ok ( ( ) ) }
Exports metrics to an MMV file at `mmv_path`
If an MMV file is already present at `mmv_path`, it's overwritten
with the newer metrics.
Exports metrics to an MMV file at ` mmv_path ` If an MMV file is already present at ` mmv_path ` it ' s overwritten with the newer metrics .
&self
metrics
&mut [&mut MMVWriter]