From 45494a8d80e4c78144b653044b55f8572e12e67d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 18 Aug 2022 01:55:32 -0600 Subject: Work on the scandevices output --- lib/btrfs/internal/uuid.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/btrfs') diff --git a/lib/btrfs/internal/uuid.go b/lib/btrfs/internal/uuid.go index 3749b1a..96807b6 100644 --- a/lib/btrfs/internal/uuid.go +++ b/lib/btrfs/internal/uuid.go @@ -5,6 +5,7 @@ package internal import ( + "encoding" "encoding/hex" "fmt" "strings" @@ -14,6 +15,13 @@ import ( type UUID [16]byte +var ( + _ fmt.Stringer = UUID{} + _ fmt.Formatter = UUID{} + _ encoding.TextMarshaler = UUID{} + _ encoding.TextUnmarshaler = (*UUID)(nil) +) + func (uuid UUID) String() string { str := hex.EncodeToString(uuid[:]) return strings.Join([]string{ @@ -25,6 +33,20 @@ func (uuid UUID) String() string { }, "-") } +func (uuid UUID) MarshalText() ([]byte, error) { + return []byte(uuid.String()), nil +} + +func (uuid *UUID) UnmarshalText(text []byte) error { + var err error + *uuid, err = ParseUUID(string(text)) + return err +} + +func (uuid UUID) Format(f fmt.State, verb rune) { + fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb) +} + func (a UUID) Cmp(b UUID) int { for i := range a { if d := int(a[i]) - int(b[i]); d != 0 { @@ -34,10 +56,6 @@ func (a UUID) Cmp(b UUID) int { return 0 } -func (uuid UUID) Format(f fmt.State, verb rune) { - fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb) -} - func ParseUUID(str string) (UUID, error) { var ret UUID j := 0 -- cgit v1.2.3-54-g00ecf