atm0s_media_server_protocol/
lib.rs

1pub mod media_event_logs {
2    use prost::Message;
3    use std::vec;
4
5    pub type MediaEndpointLogEvent = media_endpoint_log_request::Event;
6    pub type MediaSessionEvent = session_event::Event;
7
8    include!(concat!(env!("OUT_DIR"), "/atm0s.media_endpoint_log.rs"));
9    impl From<MediaEndpointLogRequest> for Vec<u8> {
10        fn from(val: MediaEndpointLogRequest) -> Self {
11            val.encode_to_vec()
12        }
13    }
14
15    impl TryFrom<&[u8]> for MediaEndpointLogRequest {
16        type Error = prost::DecodeError;
17
18        fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
19            Self::decode(value)
20        }
21    }
22
23    impl TryFrom<Vec<u8>> for MediaEndpointLogRequest {
24        type Error = prost::DecodeError;
25
26        fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
27            Self::decode(value.as_slice())
28        }
29    }
30
31    impl From<MediaEndpointLogEvent> for Vec<u8> {
32        fn from(val: MediaEndpointLogEvent) -> Self {
33            let mut buf = vec![];
34            val.encode(&mut buf);
35            buf
36        }
37    }
38
39    impl From<f32> for F32p2 {
40        fn from(val: f32) -> Self {
41            Self { value: (val * 100.0) as u32 }
42        }
43    }
44
45    impl From<F32p2> for f32 {
46        fn from(value: F32p2) -> Self {
47            value.value as f32 / 100.0
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::media_event_logs::*;
55
56    #[test]
57    fn test_f32p2_conversion() {
58        let value: f32 = 3.14;
59        let f32p2_value: F32p2 = value.into();
60        let converted_value: f32 = f32p2_value.into();
61
62        assert_eq!(value, converted_value);
63    }
64}