forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PriorityParser.go
54 lines (43 loc) · 1.12 KB
/
PriorityParser.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 (
"sip/core"
"sip/header"
)
/** SIPParser for Priority header.
*/
type PriorityParser struct {
HeaderParser
}
/** Creates a new instance of PriorityParser
* @param priority the header to parse
*/
func NewPriorityParser(priority string) *PriorityParser {
this := &PriorityParser{}
this.HeaderParser.super(priority)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewPriorityParserFromLexer(lexer core.Lexer) *PriorityParser {
this := &PriorityParser{}
this.HeaderParser.superFromLexer(lexer)
return this
}
/** parse the String header
* @return SIPHeader (Priority object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *PriorityParser) Parse() (sh header.Header, ParseException error) {
priority := header.NewPriority()
lexer := this.GetLexer()
this.HeaderName(TokenTypes_PRIORITY)
priority.SetHeaderName(core.SIPHeaderNames_PRIORITY)
lexer.SPorHT()
lexer.Match(TokenTypes_ID)
token := lexer.GetNextToken()
priority.SetPriority(token.GetTokenValue())
lexer.SPorHT()
lexer.Match('\n')
return priority, nil
}