use super::traits::AsCPacketView;
use crate::define::TH_ESStreamInfo;
pub struct CPacketViewRela<'a> {
    data: &'a [u8],
    info: &'a TH_ESStreamInfo,
}
impl<'a> CPacketViewRela<'a> {
    pub fn new(data: &'a [u8], info: &'a TH_ESStreamInfo) -> Self {
        Self { data, info }
    }
    pub fn stream_type(&self) -> u32 {
        self.info.streamType
    }
    pub fn as_slice(&self) -> &[u8] {
        self.data
    }
    pub fn info(&self) -> &TH_ESStreamInfo {
        &self.info
    }
}

impl<'a> AsCPacketView for CPacketViewRela<'a> {
    fn get_info(&self) -> &TH_ESStreamInfo {
        self.info()
    }

    fn get_data(&self) -> &[u8] {
        self.as_slice()
    }
}
#[cfg(test)]
mod tests {
    use crate::{define::TH_VIDEOCODECTYPE_TH_VCT_H264, helper::packet::packet_view::CPacketView};

    use super::*;
    #[test]
    fn test_case_cpacket_view_rela() {
        let data_es: Vec<u8> = vec![1, 2, 3];
        let base_info = TH_ESStreamInfo {
            streamType: 0,
            vCodecType: TH_VIDEOCODECTYPE_TH_VCT_H264,
            ..Default::default()
        };
        let packet_rela = CPacketViewRela::new(&data_es, &base_info);

        let packet_view = CPacketView::from(&packet_rela);
        assert_eq!(packet_view.info().streamType, 0);
        assert!(packet_view.relas().is_empty());
    }
}
