...
1
2
3
4
5 package uuid
6
7 import "fmt"
8
9
10 func (uuid UUID) MarshalText() ([]byte, error) {
11 var js [36]byte
12 encodeHex(js[:], uuid)
13 return js[:], nil
14 }
15
16
17 func (uuid *UUID) UnmarshalText(data []byte) error {
18 id, err := ParseBytes(data)
19 if err != nil {
20 return err
21 }
22 *uuid = id
23 return nil
24 }
25
26
27 func (uuid UUID) MarshalBinary() ([]byte, error) {
28 return uuid[:], nil
29 }
30
31
32 func (uuid *UUID) UnmarshalBinary(data []byte) error {
33 if len(data) != 16 {
34 return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
35 }
36 copy(uuid[:], data)
37 return nil
38 }
39
View as plain text