ducky/devices

Paddy 2015-11-29 Parent:b6494e1a499e

14:1ae5bae472c1 Go to Latest

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

Set up DeleteDevices in Memstore. Implement the DeleteDevices method for our Memstore, removing the Devices specified by the passed IDs. Also, create a simple test that verifies that when Devices are deleted, only the Devices you intend to delete are actually deleted. Further tests should be written to verify that this extends to ListDevicesByOwner (e.g., deleted devices will not be returned when listing them), CreateDevices (e.g., will not result in an ErrDeviceAlreadyExists error), and UpdateDevice (e.g., will return an ErrDeviceNotFound error after the Device is deleted). But for now, we're confident that it works in the simplest possible case.

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 }