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

proposal: encoding/hex: add an encoder and decoder #21590

Closed
Hamcha opened this issue Aug 24, 2017 · 4 comments
Closed

proposal: encoding/hex: add an encoder and decoder #21590

Hamcha opened this issue Aug 24, 2017 · 4 comments

Comments

@Hamcha
Copy link

Hamcha commented Aug 24, 2017

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 the encoding/hex package doesn't. (Except for hex.Dumper which isn't a viable alternative).

Proposal

My proposal is to add structs hex.Decoder and hex.Encoder (which respectively implement io.Reader and io.Writer) to make the encoding/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.

@gopherbot gopherbot added this to the Proposal milestone Aug 24, 2017
@ianlancetaylor ianlancetaylor changed the title Proposal: Add an encoder/decoder for encoding/hex proposal: add an encoder/decoder for encoding/hex Aug 25, 2017
@odeke-em odeke-em changed the title proposal: add an encoder/decoder for encoding/hex proposal: encoding/hex: add an encoder and decoder Aug 26, 2017
@rsc
Copy link
Contributor

rsc commented Aug 28, 2017

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?

@rsc
Copy link
Contributor

rsc commented Oct 9, 2017

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.

@gopherbot
Copy link

Change https://golang.org/cl/70210 mentions this issue: encoding/hex: add NewEncoder, NewDecoder

@gopherbot
Copy link

Change https://golang.org/cl/78120 mentions this issue: encoding/hex: make Decode, Decoder, DecodeString agree about partial results and errors

gopherbot pushed a commit that referenced this issue Nov 16, 2017
…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>
@golang golang locked and limited conversation to collaborators Nov 15, 2018
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

3 participants