From 9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 25 Aug 2017 17:04:42 +0200 Subject: Add support for the draft/cnp-select "select" request/response parameter --- message.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'message.go') diff --git a/message.go b/message.go index eb3d2b9..fdb16b3 100644 --- a/message.go +++ b/message.go @@ -31,7 +31,7 @@ func NewMessage(intent string, body io.Reader) *Message { // ParseMessage parses a CNP message. // -// The message's Body field is set to a bufio.Reader wrapping r. If r is a +// The message's Body field is set to a bufio.Reader wrapping r. If r is an // io.Closer, it is also stored separately for usage with Message.Close(). func ParseMessage(r io.Reader) (*Message, error) { br := bufio.NewReader(r) @@ -77,7 +77,7 @@ func (msg *Message) Close() error { // ComputeLength sets the length header parameter based on the message body. // First, msg.TryComputeLength() is attempted; if that fails, the request is -// fully read into a buffer and msg.Body is set to a bytes.Reader. +// fully read into a bytes.Buffer and msg.Body is set to it. func (msg *Message) ComputeLength() error { if !msg.TryComputeLength() { buf, err := ioutil.ReadAll(msg.Body) @@ -94,9 +94,10 @@ func (msg *Message) ComputeLength() error { } // TryComputeLength sets the length header parameter to the length of the -// message body if it's one of *bytes.Buffer, *bytes.Reader or *strings.Reader -// and returns true. If msg.Body is nil, the length parameter is unset and the -// function returns true. Otherwise, false is returned. +// message body if the body's type is one of *bytes.Buffer, *bytes.Reader or +// *strings.Reader and returns true. If msg.Body is nil, the length parameter +// is unset and the function returns true. Otherwise, false is returned and the +// length parameter remains unchanged. func (msg *Message) TryComputeLength() bool { switch v := msg.Body.(type) { case *bytes.Buffer: @@ -131,13 +132,13 @@ func (msg *Message) Length() int64 { return n } -// Param retrieves a header parameter. +// Param retrieves a header parameter. It performs no value validation. func (msg *Message) Param(key string) string { return msg.Header.Parameters[key] } // SetParam sets a header parameter. If the value is empty, the parameter is -// unset. +// unset. It performs no value validation. func (msg *Message) SetParam(key, value string) { if len(value) == 0 { delete(msg.Header.Parameters, key) -- cgit