forked from sippy/go-b2bua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sip_numeric_hf.go
53 lines (46 loc) · 812 Bytes
/
sip_numeric_hf.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
package sippy_header
import (
"strconv"
)
type SipNumericHF struct {
stringBody string
Number int
parsed bool
}
func newSipNumericHF(num int) SipNumericHF {
return SipNumericHF{
Number: num,
parsed: true,
}
}
func createSipNumericHF(body string) SipNumericHF {
return SipNumericHF{
stringBody: body,
parsed: false,
}
}
func (s *SipNumericHF) StringBody() string {
if s.parsed {
return strconv.Itoa(s.Number)
}
return s.stringBody
}
func (s *SipNumericHF) parse() error {
if !s.parsed {
var err error
s.Number, err = strconv.Atoi(s.stringBody)
if err != nil {
return err
}
s.parsed = true
}
return nil
}
func (s *SipNumericHF) GetBody() (*SipNumericHF, error) {
if !s.parsed {
if err := s.parse(); err != nil {
return nil, err
}
}
return s, nil
}