1use std;
2
3#[derive(Clone,Debug)]
4pub struct SystemExclusiveData {
5 sys_exclusive: Vec<u8>,
6}
7
8
9impl SystemExclusiveData {
10 pub fn newo<T: Into<Vec<u8>>>(systemid: u16, data: T) -> Self {
11 let mut data = data.into();
12 let syshigh: u8 = (systemid >> 8) as u8;
13 let syslow: u8 = (systemid & 0xff) as u8;
14 let mut header = vec![syshigh, syslow];
15 header.append(&mut data);
16 SystemExclusiveData { sys_exclusive: header }
17 }
18
19 pub fn len_bytes(&self) -> usize {
20 self.sys_exclusive.len()
21 }
22 pub fn get_system_id(&self) -> u16 {
23 if self.sys_exclusive.len() < 2 {
24 0
25 } else {
26 ((self.sys_exclusive[1] as u16) << 8) + (self.sys_exclusive[0] as u16)
27 }
28 }
29
30 pub fn get_data(&self) -> &[u8] {
31 if self.sys_exclusive.len() < 2 {
32 &self.sys_exclusive[0..0]
33 } else {
34 &self.sys_exclusive[2..]
35 }
36 }
37}
38
39
40impl std::convert::From<Vec<u8>> for SystemExclusiveData {
41 fn from(t: Vec<u8>) -> SystemExclusiveData {
42 SystemExclusiveData { sys_exclusive: t }
43 }
44}
45
46impl std::convert::From<SystemExclusiveData> for Vec<u8> {
47 fn from(t: SystemExclusiveData) -> Vec<u8> {
48 t.sys_exclusive
49 }
50}