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

Open
maja42 opened this Issue Jan 11, 2019 · 8 comments

Comments

Projects
None yet
7 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.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jan 23, 2019

There are backwards compatibility concerns with adding MarshalText/UnmarshalText where they did not exist before. Was it possible to marshal these to JSON/Gob/XML before and then decode them back? If so, we can't break the old encoding. Or even if it was only possible to marshal, if that was a form other languages/tools knew, we can't change that either.

While we're on the topic, do we need to think about net.IPMask too?

@rsc rsc added the WaitingForInfo label Feb 6, 2019

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Feb 6, 2019

Waiting for someone to dig into whether there are compatibility issues here.

@agnivade

This comment has been minimized.

Copy link
Member

agnivade commented Feb 21, 2019

/cc @mikioh

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Mar 6, 2019

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this Mar 6, 2019

@mikioh mikioh removed the WaitingForInfo label Mar 7, 2019

@mikioh

This comment has been minimized.

Copy link
Contributor

mikioh commented Mar 7, 2019

Just FYI.

As far as I can see/remember;

  • textual representation for link- or below-layer identifiers varies,
  • the existing net.ParseMAC accepts only a few well-known representations, IEEE and some vendors, for the sake of convenience,
  • the existing net.HardwareAddr.String method returns the form described in IEEE Std 802-2001, Section 3.1.8 hexadecimal representation with the pick of "colons" instead of "hyphens",
  • though, MAC-48 is now obsolete. IEEE RA states that "... octets separated by hyphens; the IEEE RA refers to this as the hexadecimal (hex) representation." in https://standards.ieee.org/content/dam/ieee-standards/standards/web/documents/tutorials/eui.pdf

@mikioh mikioh reopened this Mar 7, 2019

@mikioh

This comment has been minimized.

Copy link
Contributor

mikioh commented Mar 7, 2019

While we're on the topic, do we need to think about net.IPMask too?

Also net.IPNet? I don't think so. As shown in #30264, there is a need for flexible IP address printer but simple, single-form text marshaler and unmarshaler might not fit for the actual needs, not only for classical telco sectors but tech sectors.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Mar 20, 2019

Still looking for comments on compatibility issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.