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: net: add MarshalText/UnmarshalText to HardwareAddr #29678

Open
maja42 opened this Issue Jan 11, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@maja42
Copy link

maja42 commented Jan 11, 2019

What version of Go are you using (go version)?

$ go version
go1.10 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

I'm trying to unmarshal json content into net.IP and net.HardwareAddr.
Both types are actually of type []byte
Since net.IP implements json.Marshaler, it works as expected. However, net.HardwareAddr does not and fails with the error "illegal base64 data at input byte 2" (that's the position of the separator).

Here's an example:
https://play.golang.org/p/HOBBAyvpfrK

I found the google group discussion about adding the Marshaller to the net.IP type: https://groups.google.com/forum/#!topic/golang-nuts/io8aHJarm6U

What did you expect to see?

I expect net.HardwareAddr to be consistent with net.IP and implement json.Marshaler.
Strings in the form of "ab:cd:ef:ab:cd:ef" inside json should be parsable to MAC addresses.

@agnivade agnivade changed the title net, json: Add MarshalText/UnmarshalText to net.HardwareAddr proposal: net: Add MarshalText/UnmarshalText to HardwareAddr Jan 11, 2019

@gopherbot gopherbot added this to the Proposal milestone Jan 11, 2019

@agnivade agnivade changed the title proposal: net: Add MarshalText/UnmarshalText to HardwareAddr proposal: net: add MarshalText/UnmarshalText to HardwareAddr Jan 11, 2019

@gopherbot gopherbot added the Proposal label Jan 11, 2019

@agnivade

This comment has been minimized.

Copy link
Member

agnivade commented Jan 11, 2019

Considering there is a ParseMAC corresponding to ParseIP which is basically what the Unmarshaller for IP does, this seems like a reasonable request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment