Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary.Write doesn't support slices #478

Closed
hoisie opened this issue Dec 29, 2009 · 6 comments
Closed

binary.Write doesn't support slices #478

hoisie opened this issue Dec 29, 2009 · 6 comments

Comments

@hoisie
Copy link
Contributor

hoisie commented Dec 29, 2009

What steps will reproduce the problem?
1. Calling binary.Write() with slice values doesn't work. For example:

http://pastie.org/760660

What is the expected output? What do you see instead?
Output is "binary.Write: invalid type main.Test"
I expect it to succeed

What is your $GOOS?  $GOARCH?
linux/386

Which revision are you using?  (hg identify)
eb3355e52683+ tip

Please provide any additional information below.
I understand that binary.Read() can't support slice types, because it 
doesn't know how much data to read. However it makes sense to be able to 
write slices, because you know the length. 

Unless the go authors don't want this, I could implement the fix.
@peterGo
Copy link
Contributor

peterGo commented Dec 29, 2009

Comment 1:

The documentation for 'binary.Read(r io.Reader, order ByteOrder, data interface{})
os.Error' states that "Data must be a pointer to a fixed-size value or a slice of
fixed-size values." The source code for binary.Read has a case for *reflect.SliceValue.

@robpike
Copy link
Contributor

robpike commented Dec 30, 2009

Comment 2:

Owner changed to r...@golang.org.

Status changed to Accepted.

@hoisie
Copy link
Contributor Author

hoisie commented Dec 30, 2009

Comment 3:

Patch out: http://golang.org/cl/183091/

@hoisie
Copy link
Contributor Author

hoisie commented Apr 7, 2010

Comment 4:

I'd also like binary.Write to support strings. Should I try to make another patch? I'm 
hesitant because I've submitted 2-3 patches against binary, all of which have been 
rejected, so I have no idea what the goals are for this package.

@rsc
Copy link
Contributor

rsc commented Apr 7, 2010

Comment 5:

Binary is intended for fixed-size structures with obvious encodings.
Strings are not fixed size and do not have an obvious encoding
(NUL-terminated?  size + data?).
Again, I would be interested in proposals to use interfaces to make
binary handle user-specified encodings.  That's a much more scalable
way for it to grow than just tossing feature upon feature into the core.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2010

Comment 6:

Status changed to TimedOut.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants