ducky/devices

Paddy 2015-12-19 Parent:a700ede02f91

17:ad63b888f899 Go to Latest

ducky/devices/vendor/github.com/pborman/uuid/version1.go

Fix JSON pointers in errors when creating devices. Our JSON pointers used to point at the root of the document, but the properties were actually in objects in an array keyed off of "devices", so we had to update the field property of our errors to match. While we were in there, we fixed the "insufficient" error for a Device's name to be "missing" when the name is an empty string. So far, the only way for a Device's name for it to be insufficient is _for it to be the empty string_, but if in the future we raise the minimum length of the Device name, there will be a distinction and I'd like the code to recognise it.

History
paddy@0 1 // Copyright 2011 Google Inc. All rights reserved.
paddy@0 2 // Use of this source code is governed by a BSD-style
paddy@0 3 // license that can be found in the LICENSE file.
paddy@0 4
paddy@0 5 package uuid
paddy@0 6
paddy@0 7 import (
paddy@0 8 "encoding/binary"
paddy@0 9 )
paddy@0 10
paddy@0 11 // NewUUID returns a Version 1 UUID based on the current NodeID and clock
paddy@0 12 // sequence, and the current time. If the NodeID has not been set by SetNodeID
paddy@0 13 // or SetNodeInterface then it will be set automatically. If the NodeID cannot
paddy@0 14 // be set NewUUID returns nil. If clock sequence has not been set by
paddy@0 15 // SetClockSequence then it will be set automatically. If GetTime fails to
paddy@0 16 // return the current NewUUID returns nil.
paddy@0 17 func NewUUID() UUID {
paddy@0 18 if nodeID == nil {
paddy@0 19 SetNodeInterface("")
paddy@0 20 }
paddy@0 21
paddy@0 22 now, seq, err := GetTime()
paddy@0 23 if err != nil {
paddy@0 24 return nil
paddy@0 25 }
paddy@0 26
paddy@0 27 uuid := make([]byte, 16)
paddy@0 28
paddy@0 29 time_low := uint32(now & 0xffffffff)
paddy@0 30 time_mid := uint16((now >> 32) & 0xffff)
paddy@0 31 time_hi := uint16((now >> 48) & 0x0fff)
paddy@0 32 time_hi |= 0x1000 // Version 1
paddy@0 33
paddy@0 34 binary.BigEndian.PutUint32(uuid[0:], time_low)
paddy@0 35 binary.BigEndian.PutUint16(uuid[4:], time_mid)
paddy@0 36 binary.BigEndian.PutUint16(uuid[6:], time_hi)
paddy@0 37 binary.BigEndian.PutUint16(uuid[8:], seq)
paddy@0 38 copy(uuid[10:], nodeID)
paddy@0 39
paddy@0 40 return uuid
paddy@0 41 }