ducky/devices
2015-11-15
Parent:b6494e1a499e
ducky/devices/vendor/code.google.com/p/go-uuid/uuid/json.go
Ignore coverage output. Add a .hgignore file to ignore the output file that tracks our test coverage.
1 // Copyright 2014 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.
5 package uuid
7 import "errors"
9 func (u UUID) MarshalJSON() ([]byte, error) {
10 if len(u) == 0 {
11 return []byte(`""`), nil
12 }
13 return []byte(`"` + u.String() + `"`), nil
14 }
16 func (u *UUID) UnmarshalJSON(data []byte) error {
17 if len(data) == 0 || string(data) == `""` {
18 return nil
19 }
20 if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
21 return errors.New("invalid UUID format")
22 }
23 data = data[1 : len(data)-1]
24 uu := Parse(string(data))
25 if uu == nil {
26 return errors.New("invalid UUID format")
27 }
28 *u = uu
29 return nil
30 }