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.
11 guuid "github.com/google/uuid"
14 // MarshalText implements encoding.TextMarshaler.
15 func (u UUID) MarshalText() ([]byte, error) {
24 // UnmarshalText implements encoding.TextUnmarshaler.
25 func (u *UUID) UnmarshalText(data []byte) error {
29 id := Parse(string(data))
31 return errors.New("invalid UUID")
37 // MarshalBinary implements encoding.BinaryMarshaler.
38 func (u UUID) MarshalBinary() ([]byte, error) {
42 // UnmarshalBinary implements encoding.BinaryUnmarshaler.
43 func (u *UUID) UnmarshalBinary(data []byte) error {
48 return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
56 // MarshalText implements encoding.TextMarshaler.
57 func (u Array) MarshalText() ([]byte, error) {
59 encodeHex(js[:], u[:])
63 // UnmarshalText implements encoding.TextUnmarshaler.
64 func (u *Array) UnmarshalText(data []byte) error {
65 id, err := guuid.ParseBytes(data)
73 // MarshalBinary implements encoding.BinaryMarshaler.
74 func (u Array) MarshalBinary() ([]byte, error) {
78 // UnmarshalBinary implements encoding.BinaryUnmarshaler.
79 func (u *Array) UnmarshalBinary(data []byte) error {
81 return fmt.Errorf("invalid UUID (got %d bytes)", len(data))