ducky/devices

Paddy 2015-11-27 Parent:b6494e1a499e

10:74dbc04879a7 Go to Latest

ducky/devices/vendor/code.google.com/p/go-uuid/uuid/json.go

Implement and test updating devices, and reuse contexts. Update all our tests to use the same context.Context instance within each test case, so static analysis about how we're passing contexts around dosn't get tripped up. Also, write a test that will check to make sure that our Storer implementations all actually update the Device correctly. We create every possible permutation of a DeviceChange, just to make sure they all work.

History
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 }