Browse Source

Use type conversions where possible

tags/0.1.6
Andreas Linz 3 years ago
parent
commit
d113da7142
2 changed files with 21 additions and 21 deletions
  1. +2
    -2
      src/decoder.rs
  2. +19
    -19
      tests/encoder_test.rs

+ 2
- 2
src/decoder.rs View File

@@ -151,8 +151,8 @@ fn read_osc_arg(cursor: &mut io::Cursor<&[u8]>, tag: char) -> Result<OscType> {
't' => read_time_tag(cursor),
'b' => read_blob(cursor),
'r' => read_osc_color(cursor),
'T' => Ok(OscType::Bool(true)),
'F' => Ok(OscType::Bool(false)),
'T' => Ok(true.into()),
'F' => Ok(false.into()),
'N' => Ok(OscType::Nil),
'I' => Ok(OscType::Inf),
'c' => read_char(cursor),


+ 19
- 19
tests/encoder_test.rs View File

@@ -30,30 +30,30 @@ fn test_encode_message_wo_args() {
fn test_encode_message_with_args() {
let msg_packet = OscPacket::Message(OscMessage {
addr: "/another/address/1".to_string(),
args: Some(vec![OscType::Int(4),
OscType::Long(42),
OscType::Float(3.1415926),
OscType::Double(3.14159265359),
OscType::String("This is a string.".to_string()),
OscType::Blob(vec![1u8, 2u8, 3u8]),
OscType::Time(123, 456),
OscType::Char('c'),
OscType::Bool(false),
OscType::Bool(true),
args: Some(vec![4i32.into(),
42i64.into(),
3.1415926f32.into(),
3.14159265359f64.into(),
"This is a string.".to_string().into(),
vec![1u8, 2u8, 3u8].into(),
(123, 456).into(),
'c'.into(),
false.into(),
true.into(),
OscType::Nil,
OscType::Inf,
OscType::Midi(OscMidiMessage {
OscMidiMessage {
port: 4,
status: 41,
data1: 42,
data2: 129,
}),
OscType::Color(OscColor {
}.into(),
OscColor {
red: 255,
green: 192,
blue: 42,
alpha: 13,
})]),
}.into()]),
});

let enc_msg = encoder::encode(&msg_packet).unwrap();
@@ -81,26 +81,26 @@ fn test_encode_bundle() {

let msg1 = OscMessage {
addr: "/mixer/channel/1/amp".to_string(),
args: Some(vec![OscType::Float(0.9)]),
args: Some(vec![0.9f32.into()]),
};

let msg2 = OscMessage {
addr: "/osc/1/freq".to_string(),
args: Some(vec![OscType::Int(440)]),
args: Some(vec![440i32.into()]),
};

let msg3 = OscMessage {
addr: "/osc/1/phase".to_string(),
args: Some(vec![OscType::Float(-0.4)]),
args: Some(vec![(-0.4f32).into()]),
};

let bundle1 = OscBundle {
timetag: OscType::Time(5678, 8765),
timetag: (5678, 8765).into(),
content: vec![OscPacket::Message(msg2), OscPacket::Message(msg3)],
};

let root_bundle = OscPacket::Bundle(OscBundle {
timetag: OscType::Time(1234, 4321),
timetag: (1234, 4321).into(),
content: vec![OscPacket::Message(msg0),
OscPacket::Message(msg1),
OscPacket::Bundle(bundle1)],


Loading…
Cancel
Save