podman
1// Copyright 2016 Google Inc. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package uuid
6
7import "fmt"
8
9// MarshalText implements encoding.TextMarshaler.
10func (uuid UUID) MarshalText() ([]byte, error) {
11var js [36]byte
12encodeHex(js[:], uuid)
13return js[:], nil
14}
15
16// UnmarshalText implements encoding.TextUnmarshaler.
17func (uuid *UUID) UnmarshalText(data []byte) error {
18id, err := ParseBytes(data)
19if err != nil {
20return err
21}
22*uuid = id
23return nil
24}
25
26// MarshalBinary implements encoding.BinaryMarshaler.
27func (uuid UUID) MarshalBinary() ([]byte, error) {
28return uuid[:], nil
29}
30
31// UnmarshalBinary implements encoding.BinaryUnmarshaler.
32func (uuid *UUID) UnmarshalBinary(data []byte) error {
33if len(data) != 16 {
34return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
35}
36copy(uuid[:], data)
37return nil
38}
39