proposal: encoding/binary: Read (or a new call) should return number of bytes read #18585
Labels
Go2Cleanup
Used by Ian and Robert for Go 2 organization. Unless you’re Ian or Robert, please do not use this.
Proposal
v2
A language change or incompatible library change
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.4
What operating system and processor architecture are you using (
go env
)?linux/amd64
linux/arm
darwin/amd64
What did you do?
I want to use
binary.Read()
to marshall data to/from network byte-order.I must keep track of my offset from the beginning of the stream (I'm decoding DNS records, which sometimes refer to strings found at offsets-from-0 farther back as a form of compression).
I would prefer not to require the use of an
io.ReadSeeker
just for the sake of discovering my current offset.What did you expect to see?
I expected
binary.Read()
to return the number of bytes read, as all of theio.Read
implementations do.What did you see instead?
It doesn't! This seems like a silly oversight, but also not a big or difficult change.
I created a trivial library to replace the function. In retrospect, it would be better to have a differently-named function in the upstream Golang
binary
package so that Go-1.x compatibility isn't broken.binary.Read
could be a wrapper which just drops the bytesRead return value.The text was updated successfully, but these errors were encountered: