Skip to content

Commit

Permalink
Merge pull request #1165 from lukasmalkmus/lukasmalkmus/mac-primitive
Browse files Browse the repository at this point in the history
feat: add 'mac' primitive for 'net.HardwareAddr' (MAC)
  • Loading branch information
tdakkota authored Feb 6, 2024
2 parents 5ca9a91 + 9c84f12 commit 3ae5daa
Show file tree
Hide file tree
Showing 24 changed files with 20,557 additions and 10,986 deletions.
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

0 comments on commit 3ae5daa

Please sign in to comment.