MCPcopy Create free account
hub / github.com/619dev/minghe / parse_sip_message

Function parse_sip_message

src/sip/parser.rs:15–22  ·  view source on GitHub ↗

解析原始字节为 SIP 消息文本 将原始 TCP 字节流中的数据转换为 UTF-8 字符串, 然后尝试解析为 rsip::SipMessage。

(data: &[u8])

Source from the content-addressed store, hash-verified

13/// 将原始 TCP 字节流中的数据转换为 UTF-8 字符串,
14/// 然后尝试解析为 rsip::SipMessage。
15pub 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 消息序列化为字节
25pub fn serialize_message(msg: &rsip::SipMessage) -> Vec<u8> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected