serde_osc/ser/
mod.rs

1use std::io::{Cursor, Write};
2use serde;
3use error::ResultE;
4
5#[macro_use]
6mod serializer_defaults;
7
8mod bundle_serializer;
9mod pkt_serializer;
10mod pkt_type_decoder;
11mod osc_writer;
12mod msg_serializer;
13mod timetag_ser;
14
15pub use self::pkt_serializer::PktSerializer as Serializer;
16
17/// Serialize `value` into an OSC packet, and write the contents into `write`.
18/// Note that serialization of structs is done only based on the ordering
19/// of fields; their names are not preserved in the output.
20pub fn to_write<S: ?Sized, W: Write>(write: &mut W, value: &S) -> ResultE<()>
21    where W: Write, S: serde::ser::Serialize
22{
23    let mut ser = Serializer::new(write.by_ref());
24    value.serialize(&mut ser)
25}
26
27/// Serializes `value` into a `Vec<u8>` type.
28/// This is a wrapper around the `to_write` function.
29pub fn to_vec<T: ?Sized>(value: &T) -> ResultE<Vec<u8>>
30    where T: serde::ser::Serialize
31{
32    let mut output = Cursor::new(Vec::new());
33    to_write(&mut output, value)?;
34    Ok(output.into_inner())
35}