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
proposal: encoding/json: accept and use io.ByteReader or expose input buffering #8658
Comments
I think it is possible today to pass Perhaps it would make sense to develop a set of conventions for handling a single byte stream that contains different kinds of data, with buffer sharing. The problem in general seems larger than JSON. But this issue doesn't describe a general approach, and I don't have any ideas myself. Since this specific problem can be handled reasonably today, and since the larger problem needs a proposal, closing this issue. |
I don't see what bigger proposal is needed than "accept As far as I can see, this part of the |
It's not clear that we want to require buffering where it is not appropriate. Accepting a simple io.Reader interface is a standard Go approach; changing all streaming packages to use a fixed type rather than an interface does not sound right to me. However, I encourage you to write that up as a separate proposal if you think it is the best approach. |
I'm not suggesting to change json.NewDecoder argument types. I'm suggesting it check if it was passed a *bufio.Reader, and if so use that for buffering. (If not, it can call bufio.NewReader itself, and store a bool that it did so; that matters for .Buffered behavior.) In fact, other decoders in stdlib do just that, and don't even offer the Buffered api. The check-and-reuse is delegated to bufio.NewReader{,Size} https://golang.org/src/bufio/bufio.go?s=1304:1354#L36 and not really ever documented :-( For example, csv.NewReader: https://golang.org/src/encoding/csv/reader.go?s=4576:4611#L125 |
I encourage you to write that up as a separate proposal. |
sigh ... this was that proposal ... I mean, I could use more words, for argumentation, but the "separate" part comes off very weird. |
This proposal was written as specific to JSON. It says that I'm saying that if you want to change something, it should be broader than JSON, and it should not have anything to do with a I don't see any of that in this proposal. All this proposal says is to use |
The text was updated successfully, but these errors were encountered: