inetaf / netaddr

Network address types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add methods to IPRange for parity with other types

dsnet opened this issue · comments

The IPRange lack some functions and methods that consistently exist onIP, IPPort, and IPPrefix. See the following table.

func IP IPPort IPPrefix IPRange
func ParseT(string) (T, error)
func MustParseT(string) T
func (T) IsValid() bool
func (T) IsZero() bool
func (T) String() string
func (T) AppendTo([]byte) []byte
func (T) MarshalText() ([]byte, error)
func (*T) UnmarshalText([]byte) error

Given that a parse method exists already for IPRange, I don't see any reason why we can't also provide MustParse, AppendTo, MarshalText, and UnmarshalText.

The use case of this change is for tailscale.com/util/deephash, where the netaddr.IPRange type is the only type ever visited by deephash where the package must touch unexported fields because the type has no AppendTo method (which deephash specially understands). Adding AppendTo would be a one step closer to generating deephash functionality for all relevant tailscale types.

\cc @bradfitz @josharian

Make it so!