forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSeqParser.go
54 lines (44 loc) · 1.11 KB
/
RSeqParser.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
package parser
import (
"github.com/tutuvss/sip/core"
"github.com/tutuvss/sip/header"
)
/** SIPParser for RSeq header.
*/
type RSeqParser struct {
HeaderParser
}
/** Creates a new instance of RSeqParser
*@param rseq the header to parse
*/
func NewRSeqParser(rseq string) *RSeqParser {
this := &RSeqParser{}
this.HeaderParser.super(rseq)
return this
}
/** Constructor
* param lexer the lexer to use to parse the header
*/
func NewRSeqParserFromLexer(lexer core.Lexer) *RSeqParser {
this := &RSeqParser{}
this.HeaderParser.superFromLexer(lexer)
return this
}
/** parse the String message
* @return SIPHeader ( RSeq object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *RSeqParser) Parse() (sh header.Header, ParseException error) {
rseq := header.NewRSeq()
lexer := this.GetLexer()
this.HeaderName(TokenTypes_RSEQ)
rseq.SetHeaderName(core.SIPHeaderNames_RSEQ)
var number int
if number, ParseException = lexer.Number(); ParseException != nil {
return nil, ParseException
}
rseq.SetSequenceNumber(number)
lexer.SPorHT()
lexer.Match('\n')
return rseq, nil
}