ducky/devices

Paddy 2015-11-29 Parent:b6494e1a499e

14:1ae5bae472c1 Go to Latest

ducky/devices/vendor/code.google.com/p/go-uuid/uuid/util.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 "io"
paddy@0 9 )
paddy@0 10
paddy@0 11 // randomBits completely fills slice b with random data.
paddy@0 12 func randomBits(b []byte) {
paddy@0 13 if _, err := io.ReadFull(rander, b); err != nil {
paddy@0 14 panic(err.Error()) // rand should never fail
paddy@0 15 }
paddy@0 16 }
paddy@0 17
paddy@0 18 // xvalues returns the value of a byte as a hexadecimal digit or 255.
paddy@0 19 var xvalues = []byte{
paddy@0 20 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 21 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 22 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 23 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
paddy@0 24 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 25 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 26 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 27 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 28 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 29 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 30 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 31 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 32 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 33 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 34 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 35 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 36 }
paddy@0 37
paddy@0 38 // xtob converts the the first two hex bytes of x into a byte.
paddy@0 39 func xtob(x string) (byte, bool) {
paddy@0 40 b1 := xvalues[x[0]]
paddy@0 41 b2 := xvalues[x[1]]
paddy@0 42 return (b1 << 4) | b2, b1 != 255 && b2 != 255
paddy@0 43 }