pub struct Grib2SubmessageDecoder { /* private fields */ }
Expand description
Decoder for grid point values of GRIB2 submessages.
§Examples
use grib::Grib2SubmessageDecoder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let f =
std::fs::File::open("testdata/CMC_glb_TMP_ISBL_1_latlon.24x.24_2021051800_P000.grib2")?;
let f = std::io::BufReader::new(f);
let grib2 = grib::from_reader(f)?;
let (_index, first_submessage) = grib2.iter().next().unwrap();
let decoder = Grib2SubmessageDecoder::from(first_submessage)?;
let mut decoded = decoder.dispatch()?;
assert_eq!(decoded.size_hint(), (1126500, Some(1126500)));
let first_value = decoded.next();
assert_eq!(first_value.map(|f| f.round()), Some(236.0_f32));
let last_value = decoded.nth(1126498);
assert_eq!(last_value.map(|f| f.round()), Some(286.0_f32));
let next_to_last_value = decoded.next();
assert_eq!(next_to_last_value, None);
Ok(())
}
If the byte sequences for Sections 5, 6, and 7 of the GRIB2 data are known,
and the number of grid points (described in Section 3) is also known, it is
also possible to create a decoder instance by passing them to
Grib2SubmessageDecoder::new
. The example above is equivalent to the
following:
use std::io::Read;
use grib::Grib2SubmessageDecoder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let f =
std::fs::File::open("testdata/CMC_glb_TMP_ISBL_1_latlon.24x.24_2021051800_P000.grib2")?;
let mut f = std::io::BufReader::new(f);
let mut buf = Vec::new();
f.read_to_end(&mut buf)?;
let decoder = Grib2SubmessageDecoder::new(
1126500,
buf[0x0000008f..0x000000a6].to_vec(),
buf[0x000000a6..0x000000ac].to_vec(),
buf[0x000000ac..0x0003d6c7].to_vec(),
)?;
let mut decoded = decoder.dispatch()?;
assert_eq!(decoded.size_hint(), (1126500, Some(1126500)));
let first_value = decoded.next();
assert_eq!(first_value.map(|f| f.round()), Some(236.0_f32));
let last_value = decoded.nth(1126498);
assert_eq!(last_value.map(|f| f.round()), Some(286.0_f32));
let next_to_last_value = decoded.next();
assert_eq!(next_to_last_value, None);
Ok(())
}
Implementations§
Source§impl Grib2SubmessageDecoder
impl Grib2SubmessageDecoder
Sourcepub fn new(
num_points_total: usize,
sect5_bytes: Vec<u8>,
sect6_bytes: Vec<u8>,
sect7_bytes: Vec<u8>,
) -> Result<Self, GribError>
pub fn new( num_points_total: usize, sect5_bytes: Vec<u8>, sect6_bytes: Vec<u8>, sect7_bytes: Vec<u8>, ) -> Result<Self, GribError>
Creates an instance from the number of grid points (described in Section 3) and byte sequences for Sections 5, 6, and 7 of the GRIB2 data.
For code examples, refer to the description of this struct
.
Auto Trait Implementations§
impl Freeze for Grib2SubmessageDecoder
impl RefUnwindSafe for Grib2SubmessageDecoder
impl Send for Grib2SubmessageDecoder
impl Sync for Grib2SubmessageDecoder
impl Unpin for Grib2SubmessageDecoder
impl UnwindSafe for Grib2SubmessageDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more