diff options
Diffstat (limited to 'message.go')
-rw-r--r-- | message.go | 44 |
1 files changed, 23 insertions, 21 deletions
@@ -114,22 +114,14 @@ func (msg *Message) TryComputeLength() bool { return true } -// SetLength sets the length header parameter to n. -func (msg *Message) SetLength(n int64) { - if n == 0 { - msg.SetParam("length", "") - } else { - setInt(msg, "length", n) - } +// Intent retrieves the message header intent. +func (msg *Message) Intent() string { + return msg.Header.Intent } -// Length gets the length header parameter (or 0 if it's not set or invalid). -func (msg *Message) Length() int64 { - n, err := getInt(msg, "length") - if err != nil { - return 0 - } - return n +// SetIntent sets the message header intent. +func (msg *Message) SetIntent(s string) { + msg.Header.Intent = s } // Param retrieves a header parameter. It performs no value validation. @@ -147,19 +139,29 @@ func (msg *Message) SetParam(key, value string) { } } -// Intent retrieves the message header intent. -func (msg *Message) Intent() string { - return msg.Header.Intent +// Length gets the length header parameter (or 0 if it's not set or invalid). +func (msg *Message) Length() int64 { + n, err := getInt(msg, "length", 0) + if err != nil { + return 0 + } + return n } -// SetIntent sets the message header intent. -func (msg *Message) SetIntent(s string) { - msg.Header.Intent = s +// SetLength sets the length header parameter to n. +// +// If negative or zero, the parameter is unset. +func (msg *Message) SetLength(n int64) { + if n <= 0 { + msg.SetParam("length", "") + } else { + setInt(msg, "length", n) + } } // Validate validates the message header parameter value format (length). func (msg *Message) Validate() error { - _, err := getInt(msg, "length") + _, err := getInt(msg, "length", 0) return err } |