1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use std::io::Read; use Marker; use super::{read_marker, read_data_f32, read_data_f64, ValueReadError}; /// Attempts to read exactly 5 bytes from the given reader and to decode them as `f32` value. /// /// The first byte should be the marker and the others should represent the data itself. /// /// # Errors /// /// This function will return `ValueReadError` on any I/O error while reading either the marker or /// the data. /// /// It also returns `ValueReadError::TypeMismatch` if the actual type is not equal with the /// expected one, indicating you with the actual type. /// /// # Note /// /// This function will silently retry on every EINTR received from the underlying `Read` until /// successful read. pub fn read_f32<R: Read>(rd: &mut R) -> Result<f32, ValueReadError> { match try!(read_marker(rd)) { Marker::F32 => Ok(try!(read_data_f32(rd))), marker => Err(ValueReadError::TypeMismatch(marker)), } } /// Attempts to read exactly 9 bytes from the given reader and to decode them as `f64` value. /// /// The first byte should be the marker and the others should represent the data itself. /// /// # Errors /// /// This function will return `ValueReadError` on any I/O error while reading either the marker or /// the data. /// /// It also returns `ValueReadError::TypeMismatch` if the actual type is not equal with the /// expected one, indicating you with the actual type. /// /// # Note /// /// This function will silently retry on every EINTR received from the underlying `Read` until /// successful read. pub fn read_f64<R: Read>(rd: &mut R) -> Result<f64, ValueReadError> { match try!(read_marker(rd)) { Marker::F64 => Ok(try!(read_data_f64(rd))), marker => Err(ValueReadError::TypeMismatch(marker)), } }