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

1mod tables;
2
3use crate::parsers::{BufferReader, Reader};
4use tables::Grib2Table6_0 as BitMapIndicator;
5pub use tables::*;
6
7/// # Bit-Map Section
8///
9/// ## Links
10/// - [Consult with this page to understand their purpose.](https://confluence.ecmwf.int/display/UDOC/What+is+the+GRIB+bitmap+-+ecCodes+GRIB+FAQ).
11/// - [Docs](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect6.shtml).
12#[derive(Debug, Clone, PartialEq)]
13pub struct Grib2BitMapSection {
14    /// Number of GRIB section
15    pub section_number: u8,
16    /// Length of GRIB section
17    pub length: u32,
18    /// Bit-map indicator (See [Table 6.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table6-0.shtml))
19    pub bit_map_indicator: BitMapIndicator,
20    /// Bit-map
21    pub bit_map: Option<BufferReader>,
22}
23impl Grib2BitMapSection {
24    /// Create a new Grib2BitMapSection
25    ///
26    /// ## Parameters
27    /// - `section`: The byte block to understan how to parse bit-map data
28    ///
29    /// ## Returns
30    /// Parsed bit-map section
31    pub fn new<T: Reader>(section: &T) -> Grib2BitMapSection {
32        let indicator = section.uint8(Some(5));
33        Grib2BitMapSection {
34            section_number: section.uint8(Some(4)),
35            length: section.uint32_be(Some(0)),
36            bit_map_indicator: indicator.into(),
37            bit_map: if indicator == 0 {
38                Some(BufferReader::new(section.slice(Some(6), None)))
39            } else {
40                None
41            },
42        }
43    }
44}