rmp/encode/dec.rs
1use std::io::Write;
2
3use Marker;
4use encode::ValueWriteError;
5use super::{write_marker, write_data_f32, write_data_f64};
6
7/// Encodes and attempts to write an `f32` value as a 5-byte sequence into the given write.
8///
9/// The first byte becomes the `f32` marker and the others will represent the data itself.
10///
11/// # Errors
12///
13/// This function will return `ValueWriteError` on any I/O error occurred while writing either the
14/// marker or the data.
15pub fn write_f32<W: Write>(wr: &mut W, val: f32) -> Result<(), ValueWriteError> {
16 try!(write_marker(wr, Marker::F32));
17 try!(write_data_f32(wr, val));
18 Ok(())
19}
20
21/// Encodes and attempts to write an `f64` value as a 9-byte sequence into the given write.
22///
23/// The first byte becomes the `f64` marker and the others will represent the data itself.
24///
25/// # Errors
26///
27/// This function will return `ValueWriteError` on any I/O error occurred while writing either the
28/// marker or the data.
29pub fn write_f64<W: Write>(wr: &mut W, val: f64) -> Result<(), ValueWriteError> {
30 try!(write_marker(wr, Marker::F64));
31 try!(write_data_f64(wr, val));
32 Ok(())
33}