解析原始字节为 SIP 消息文本 将原始 TCP 字节流中的数据转换为 UTF-8 字符串, 然后尝试解析为 rsip::SipMessage。
(data: &[u8])
| 13 | /// 将原始 TCP 字节流中的数据转换为 UTF-8 字符串, |
| 14 | /// 然后尝试解析为 rsip::SipMessage。 |
| 15 | pub fn parse_sip_message(data: &[u8]) -> Result<rsip::SipMessage> { |
| 16 | let text = std::str::from_utf8(data).map_err(|e| anyhow!("SIP 消息 UTF-8 解码失败: {}", e))?; |
| 17 | let msg: rsip::SipMessage = text |
| 18 | .to_string() |
| 19 | .try_into() |
| 20 | .map_err(|e: rsip::Error| anyhow!("SIP 消息解析失败: {}", e))?; |
| 21 | Ok(msg) |
| 22 | } |
| 23 | |
| 24 | /// 将 SIP 消息序列化为字节 |
| 25 | pub fn serialize_message(msg: &rsip::SipMessage) -> Vec<u8> { |
nothing calls this directly
no outgoing calls
no test coverage detected