1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use super::DescriptorError;
use crate::descriptor::descriptor_len;
use smptera_format_identifiers_rust::FormatIdentifier;
use std::fmt;
pub struct RegistrationDescriptor<'buf> {
buf: &'buf [u8],
}
impl<'buf> RegistrationDescriptor<'buf> {
pub const TAG: u8 = 5;
pub fn new(tag: u8, buf: &'buf [u8]) -> Result<RegistrationDescriptor<'buf>, DescriptorError> {
descriptor_len(buf, tag, 4)?;
Ok(RegistrationDescriptor { buf })
}
pub fn format_identifier(&self) -> FormatIdentifier {
FormatIdentifier::from(&self.buf[0..4])
}
pub fn is_format(&self, id: FormatIdentifier) -> bool {
self.format_identifier() == id
}
pub fn additional_identification_info(&self) -> &[u8] {
&self.buf[4..]
}
}
impl<'buf> fmt::Debug for RegistrationDescriptor<'buf> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.debug_struct("RegistrationDescriptor")
.field("format_identifier", &self.format_identifier())
.field(
"additional_identification_info",
&format!("{:x?}", self.additional_identification_info()),
)
.finish()
}
}
#[cfg(test)]
mod test {
use super::super::{CoreDescriptors, Descriptor};
use assert_matches::assert_matches;
use hex_literal::*;
#[test]
fn descriptor() {
let data = hex!("050443554549");
let desc = CoreDescriptors::from_bytes(&data[..]).unwrap();
assert_matches!(desc, CoreDescriptors::Registration(reg) => {
let expected = smptera_format_identifiers_rust::FormatIdentifier::from(&b"CUEI"[..]);
assert_eq!(reg.format_identifier(), expected);
assert!(reg.is_format(expected));
assert!(!format!("{:?}", reg).is_empty())
});
}
}