1use alloc::{vec, vec::Vec};
11
12use super::RbspData;
13
14#[derive(Debug, PartialEq, Eq)]
16pub struct UserDataUnregistered {
17 pub uuid: [u8; 16],
18 pub payload: Vec<u8>,
19}
20
21impl UserDataUnregistered {
22 pub fn new(uuid: [u8; 16], payload: Vec<u8>) -> Self {
23 Self { uuid, payload }
24 }
25 fn to_sei_payload(&self) -> Vec<u8> {
26 let mut result = self.uuid.to_vec();
27 result.extend(self.payload.clone());
28 result
29 }
30}
31
32#[derive(Debug, PartialEq, Eq)]
34#[non_exhaustive]
35pub enum SupplementalEnhancementInformation {
36 UserDataUnregistered(UserDataUnregistered),
38}
39
40impl SupplementalEnhancementInformation {
41 pub fn to_rbsp(&self) -> RbspData {
43 let (payload_type, payload) = match &self {
44 Self::UserDataUnregistered(udr) => (5u8, udr.to_sei_payload()),
45 };
46 let mut payload_size = payload.len();
47 let mut num_ff_bytes = 0;
48 while payload_size > 255 {
49 num_ff_bytes += 1;
50 payload_size -= 0xff;
51 }
52 let mut result = vec![0xff; num_ff_bytes + 2];
53 let size_idx = result.len() - 1;
54 result[0] = payload_type;
55 result[size_idx] = payload_size.try_into().unwrap();
56
57 result.extend(payload);
58 result.push(0x80); RbspData { data: result }
60 }
61}