Open GoogleCodeExporter opened 9 years ago
The documentation is actually correct as written. OP has paid attention to the
wrong part.
"The returned slice may be a sub-slice of dst if dst was large enough to hold
the entire encoded block."
In this case the encoded block has length 0. And dst (a nil slice) is large
enough to hold zero elements. So a sub-slice of dst, dst[:0], is returned.
A subslice of a nil slice is nil itself. http://play.golang.org/p/HR9EsRYhJo
The statement in question by OP is the lower precedence "Otherwise" clause
which applies only if the first one quoted here does not apply.
Original comment by bmat...@janrain.com
on 5 Nov 2014 at 11:08
OP here. I suppose you're right, the nil slice is a subslice of the nil slice
which is big enough to contain 0 bytes. So the docs are correct.
Original comment by Dave.Revell@gmail.com
on 5 Nov 2014 at 11:17
Oops. I copied the docs from Encode().
Decode() has similar docs, you just have to replace "encoded block" in my
previous response with "decoded block".
Sorry for any confusion that caused.
Original comment by bmat...@janrain.com
on 5 Nov 2014 at 11:19
FWIW, because of things like this you almost never want to check if a slice is
nil in Go. Instead it is generally better to check that its length is 0.
Original comment by bmat...@janrain.com
on 5 Nov 2014 at 11:25
Original issue reported on code.google.com by
Dave.Revell@gmail.com
on 28 Aug 2014 at 5:25Attachments: