gistools/readers/grib2/sections/_0/mod.rs
1mod tables;
2
3use crate::parsers::Reader;
4use alloc::string::String;
5use tables::Grib2Table0_0 as Discipline;
6pub use tables::*;
7
8/// # SECTION 0 - INDICATOR SECTION
9///
10/// ## Description
11/// This section serves to identify the start of the record in a human readable form,
12/// indicate the total length of the message, and indicate the Edition number of GRIB used
13/// to construct or encode the message. For GRIB2, this section is always 16 octets long.
14///
15/// ## Links
16/// - [Docs](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect0.shtml)
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct Grib2IndicatorSection {
19 /// Number of GRIB section
20 pub section_number: u8,
21 /// Length of GRIB section (Always 16 for Section 0)
22 pub length: u8,
23 /// GRIB string encoded
24 pub grib_encoded: String,
25 /// Discipline [Table 0.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table0-0.shtml)
26 pub discipline: Discipline,
27 /// Edition number - 2 for GRIB2
28 pub grib_edition: u8,
29 /// Total length of GRIB message in octets (All sections)
30 pub grib_length: u64,
31}
32impl Grib2IndicatorSection {
33 /// Create a new Grib2IndicatorSection
34 ///
35 /// ## Parameters
36 /// - `section`: the 16 byte metadata section
37 ///
38 /// ## Returns
39 /// A parsed explination of the file
40 pub fn new<T: Reader>(section: &T) -> Grib2IndicatorSection {
41 Grib2IndicatorSection {
42 section_number: 0,
43 length: 16,
44 grib_encoded: section.parse_string(Some(0), Some(4)),
45 discipline: section.uint8(Some(6)).into(),
46 grib_edition: section.uint8(Some(7)),
47 grib_length: section.uint64_be(Some(8)),
48 }
49 }
50}