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

feat: add 'mac' primitive for 'net.HardwareAddr' (MAC) #1165

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
603 changes: 603 additions & 0 deletions _testdata/positive/format_gen.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions conv/decode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conv

import (
"net"
"net/netip"
"net/url"
"strconv"
Expand Down Expand Up @@ -126,6 +127,10 @@ func ToUUID(s string) (uuid.UUID, error) {
return uuid.Parse(s)
}

func ToMAC(s string) (net.HardwareAddr, error) {
return net.ParseMAC(s)
}

func ToAddr(s string) (netip.Addr, error) {
return netip.ParseAddr(s)
}
Expand Down Expand Up @@ -245,3 +250,7 @@ func ToBoolArray(a []string) ([]bool, error) {
func ToUUIDArray(a []string) ([]uuid.UUID, error) {
return decodeArray(a, ToUUID)
}

func ToMACArray(a []string) ([]net.HardwareAddr, error) {
return decodeArray(a, ToMAC)
}
7 changes: 7 additions & 0 deletions conv/encode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conv

import (
"net"
"net/netip"
"net/url"
"strconv"
Expand Down Expand Up @@ -42,6 +43,8 @@ func DurationToString(v time.Duration) string { return v.String() }

func UUIDToString(v uuid.UUID) string { return v.String() }

func MACToString(v net.HardwareAddr) string { return v.String() }

func AddrToString(v netip.Addr) string { return v.String() }

func URLToString(v url.URL) string { return v.String() }
Expand Down Expand Up @@ -104,3 +107,7 @@ func BoolArrayToString(vs []bool) []string {
func UUIDArrayToString(vs []uuid.UUID) []string {
return encodeArray(vs, UUIDToString)
}

func MACArrayToString(vs []net.HardwareAddr) []string {
return encodeArray(vs, MACToString)
}
Loading
Loading