forked from rainliu/sip
/
ContentLengthImpl.go
109 lines (98 loc) · 2.82 KB
/
ContentLengthImpl.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package header
import (
"errors"
"sip/core"
"strconv"
)
/**
* ContentLength Header (of which there can be only one in a SIPMessage).
*<pre>
*Fielding, et al. Standards Track [Page 119]
*RFC 2616 HTTP/1.1 June 1999
*
*
* 14.13 Content-Length
*
* The Content-Length entity-header field indicates the size of the
* entity-body, in decimal number of OCTETs, sent to the recipient or,
* in the case of the HEAD method, the size of the entity-body that
* would have been sent had the request been a Get.
*
* Content-Length = "Content-Length" ":" 1*DIGIT
*
* An example is
*
* Content-Length: 3495
*
* Applications SHOULD use this field to indicate the transfer-length of
* the message-body, unless this is prohibited by the rules in section
* 4.4.
*
* Any Content-Length greater than or equal to zero is a valid value.
* Section 4.4 describes how to determine the length of a message-body
* if a Content-Length is not given.
*
* Note that the meaning of this field is significantly different from
* the corresponding definition in MIME, where it is an optional field
* used within the "message/external-body" content-type. In HTTP, it
* SHOULD be sent whenever the message's length can be determined prior
* to being transferred, unless this is prohibited by the rules in
* section 4.4.
* </pre>
*/
type ContentLength struct {
SIPHeader
/** contentLength field.
*/
contentLength int
}
/** Default constructor.
*/
func NewContentLength() *ContentLength {
this := &ContentLength{}
this.SIPHeader.super(core.SIPHeaderNames_CONTENT_LENGTH)
return this
}
/**
*Constructor given a length.
*/
func NewContentLengthFromInt(length int) *ContentLength {
this := &ContentLength{}
this.SIPHeader.super(core.SIPHeaderNames_CONTENT_LENGTH)
this.contentLength = length
return this
}
/** Get the ContentLength field.
* @return int
*/
func (this *ContentLength) GetContentLength() int {
return this.contentLength
}
/**
* Set the contentLength member
* @param contentLength int to Set
*/
func (this *ContentLength) SetContentLength(contentLength int) error {
if contentLength < 0 {
return errors.New("InvalidArgumentException: ContentLength.SetContentLength(), the contentLength parameter is <0")
}
this.contentLength = contentLength
return nil
}
func (this *ContentLength) String() string {
return this.headerName + core.SIPSeparatorNames_COLON +
core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE
}
/**
* Encode into a canonical string.
* @return String
*/
func (this *ContentLength) EncodeBody() string {
return strconv.Itoa(this.contentLength)
}
/** Pattern matcher ignores content length.
*/
func (this *ContentLength) Match(other interface{}) bool {
_, ok := other.(*ContentLength)
return ok
}