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/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin",
)?;
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(), (86016, Some(86016)));
let first_value = decoded.next();
assert_eq!(first_value.map(|f| f.is_nan()), Some(true));
let non_nan_value = decoded.find(|f| !f.is_nan());
assert_eq!(non_nan_value.map(|f| f.round()), Some(1.0_f32));
let last_value = decoded.last();
assert_eq!(last_value.map(|f| f.is_nan()), Some(true));
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/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin",
)?;
let mut f = std::io::BufReader::new(f);
let mut buf = Vec::new();
f.read_to_end(&mut buf)?;
let decoder = Grib2SubmessageDecoder::new(
86016,
buf[0x0000008f..0x000000a6].to_vec(),
buf[0x000000a6..0x000000ac].to_vec(),
buf[0x000000ac..0x0000061b].to_vec(),
)?;
let mut decoded = decoder.dispatch()?;
assert_eq!(decoded.size_hint(), (86016, Some(86016)));
let first_value = decoded.next();
assert_eq!(first_value.map(|f| f.is_nan()), Some(true));
let non_nan_value = decoded.find(|f| !f.is_nan());
assert_eq!(non_nan_value.map(|f| f.round()), Some(1.0_f32));
let last_value = decoded.last();
assert_eq!(last_value.map(|f| f.is_nan()), Some(true));
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