Function rosc::encoder::encode_into

source ·
pub fn encode_into<O: Output>(
    packet: &OscPacket,
    out: &mut O
) -> Result<usize, O::Err>
Expand description

Takes a reference to an OSC packet and writes the encoded bytes to the given output. On success, the number of bytes written will be returned. If an error occurs during encoding, encoding will stop and the error will be returned. Note that in that case, the output may have been partially written!

NOTE: The OSC encoder will write output in small pieces (as small as a single byte), so the output should be buffered if write calls have a large overhead (e.g. writing to a file).

Example

use rosc::{OscPacket,OscMessage,OscType};
use rosc::encoder;

let mut bytes = Vec::new();
let packet = OscPacket::Message(OscMessage{
        addr: "/greet/me".to_string(),
        args: vec![OscType::String("hi!".to_string())]
    }
);
assert!(encoder::encode_into(&packet, &mut bytes).is_ok())