Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.
This repository was archived by the owner on May 25, 2023. It is now read-only.

IPPort and IPPrefix MarshalText doesn't round trip #169

@josharian

Description

@josharian

I'm puzzling over how IPPort and IPPrefix's MarshalText methods should work when their IP is the zero IP but they have a non-zero port/bits.

Currently we return an empty slice, but that doesn't round trip. If you do IPPortFrom(IP{}, 80), MarshalText, and then UnmarshalText, you get a zero IPPort. That is, we lose the 80. Similarly so for IPPrefix.

Options:

  1. Make MarshalText return an error when there is a zero IP and a non-zero port/prefix. We then lose the nice property that MarshalText never returns an error.
  2. Make MarshalText return something like :80 (or invalid IP:80?), and then teach UnmarshalText to handle those inputs. We then lose the nice property that UnmarshalText is identical to ParseIPPort except in its handling of an empty input.
  3. Do the previous option, and also change ParseIPPort to match UnmarshalText. We then lose the nice property that there is no way to get a zero IP by parsing a textual input, only by constructing one in code.

I'm inclined towards 1, but don't feel strongly. Opinions?

cc @danderson @maisem @bradfitz @mdlayher

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions