gistools/readers/grib2/sections/_7/
mod.rs

1mod tables;
2mod templates;
3
4use crate::{
5    parsers::{BufferReader, Reader},
6    readers::Grib2Sections,
7};
8use alloc::vec::Vec;
9pub use tables::*;
10pub use templates::*;
11
12/// Data Section
13///
14/// [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect7.shtml)
15#[derive(Debug, Clone, PartialEq)]
16pub struct Grib2DataSection {
17    /// Number of GRIB section
18    pub section_number: u8,
19    /// Length of GRIB section
20    pub length: u32,
21    /// data that has yet to be decoded
22    pub raw_data: BufferReader,
23}
24impl Grib2DataSection {
25    /// Create a new instance of Grib2DataSection
26    ///
27    /// ## Parameters
28    /// - `section`: The raw section data to parse
29    /// - `sections`: The other sections that have been parsed (1-6)
30    ///
31    /// ## Returns
32    /// Parsed Data Information with a function to decode the data
33    pub fn new<T: Reader>(section: &T) -> Self {
34        Self {
35            section_number: section.uint8(Some(4)),
36            length: section.uint32_be(Some(0)),
37            raw_data: BufferReader::new(section.slice(Some(5), None)),
38        }
39    }
40
41    /// Data in a format described by data Template 7.X, where X is the data representation
42    /// template number given in octets 10-11 of [Section 5](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect5.shtml).
43    ///
44    /// ## Returns
45    /// The raw parsed data
46    pub fn data(&self, sections: &Grib2Sections) -> Vec<f64> {
47        grib2_template_7_decoder(&self.raw_data, sections)
48    }
49}