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/hex: add an encoder and decoder #21590
Comments
It does seem like hex should match base32 and base64 as far as defining a NewDecoder and NewEncoder. I'm not convinced they should be parameterized as in those packages. Do you think it's OK for NewEncoder to just assume lower case? |
Proposal accepted assuming no parameterization. If there's a strong argument to be made for parameterization, please continue discussion here. If anyone would like to send a CL, please do. |
Change https://golang.org/cl/70210 mentions this issue: |
Change https://golang.org/cl/78120 mentions this issue: |
…results and errors CL 70210 added Decoder for #21590, and in doing so it changed the existing func Decode to return partial results for decoding errors. That seems like a good change to make to Decode, but it was untested (except as used by Decoder), inconsistent with DecodeString in all error cases, and inconsistent with Decoder in not returning partial results for odd-length input strings. This CL makes Decode, DecodeString, and Decoder all agree about the handling of partial results (they are returned) and error precedence (the error earliest in the input is reported), and it documents and tests this. Change-Id: Ifb7d1e100ecb66fe2ed5ba34a621084d480f16db Reviewed-on: https://go-review.googlesource.com/78120 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Introduction
I use Go for writing net applications so I often find myself using readers and writers to sockets to un/serialize data. While most of the packages inside
encoding
do support that via Encoders/Decoders (base64, csv, json, xml..) I was pretty surprised to find that theencoding/hex
package doesn't. (Except forhex.Dumper
which isn't a viable alternative).Proposal
My proposal is to add structs
hex.Decoder
andhex.Encoder
(which respectively implementio.Reader
andio.Writer
) to make theencoding/hex
package more consistent with the rest of its siblings.I don't think it would be hard to implement (it could be a nice way for me to contribute something back, but I'm fine if someone else wants to do it) and I understand that it's not anything vital or required (you can definitely achieve it right now with an external package like this one) but I still think it would be a nice thing to have.
The text was updated successfully, but these errors were encountered: