-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsdpConnectionData.go
64 lines (53 loc) · 1.1 KB
/
sdpConnectionData.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package siprocket
/*
RFC4566 - https://tools.ietf.org/html/rfc4566#section-5.7
5.7. Connection Data ("c=")
c=<nettype> <addrtype> <connection-address>
c=IN IP4 88.215.55.98
*/
type sdpConnData struct {
//NetType []byte // Network Type
AddrType []byte // Address Type
ConnAddr []byte // Connection Address
Src []byte // Full source if needed
}
func parseSdpConnectionData(v []byte, out *sdpConnData) {
pos := 0
state := FIELD_BASE
// Init the output area
//out.NetType = nil
out.AddrType = nil
out.ConnAddr = nil
out.Src = nil
// Keep the source line if needed
if keep_src {
out.Src = v
}
// Loop through the bytes making up the line
for pos < len(v) {
// FSM
switch state {
case FIELD_BASE:
if v[pos] == ' ' {
state = FIELD_ADDRTYPE
pos++
continue
}
case FIELD_ADDRTYPE:
if v[pos] == ' ' {
state = FIELD_CONNADDR
pos++
continue
}
out.AddrType = append(out.AddrType, v[pos])
case FIELD_CONNADDR:
if v[pos] == ' ' {
state = FIELD_BASE
pos++
continue
}
out.ConnAddr = append(out.ConnAddr, v[pos])
}
pos++
}
}