mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
vendor new go-memdb
This commit is contained in:
75
vendor/github.com/hashicorp/go-memdb/index.go
generated
vendored
75
vendor/github.com/hashicorp/go-memdb/index.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package memdb
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@@ -249,6 +250,80 @@ func (s *StringMapFieldIndex) FromArgs(args ...interface{}) ([]byte, error) {
|
||||
return []byte(key), nil
|
||||
}
|
||||
|
||||
// UintFieldIndex is used to extract a uint field from an object using
|
||||
// reflection and builds an index on that field.
|
||||
type UintFieldIndex struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
func (u *UintFieldIndex) FromObject(obj interface{}) (bool, []byte, error) {
|
||||
v := reflect.ValueOf(obj)
|
||||
v = reflect.Indirect(v) // Dereference the pointer if any
|
||||
|
||||
fv := v.FieldByName(u.Field)
|
||||
if !fv.IsValid() {
|
||||
return false, nil,
|
||||
fmt.Errorf("field '%s' for %#v is invalid", u.Field, obj)
|
||||
}
|
||||
|
||||
// Check the type
|
||||
k := fv.Kind()
|
||||
size, ok := IsUintType(k)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("field %q is of type %v; want a uint", u.Field, k)
|
||||
}
|
||||
|
||||
// Get the value and encode it
|
||||
val := fv.Uint()
|
||||
buf := make([]byte, size)
|
||||
binary.PutUvarint(buf, val)
|
||||
|
||||
return true, buf, nil
|
||||
}
|
||||
|
||||
func (u *UintFieldIndex) FromArgs(args ...interface{}) ([]byte, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf("must provide only a single argument")
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(args[0])
|
||||
if !v.IsValid() {
|
||||
return nil, fmt.Errorf("%#v is invalid", args[0])
|
||||
}
|
||||
|
||||
k := v.Kind()
|
||||
size, ok := IsUintType(k)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("arg is of type %v; want a uint", k)
|
||||
}
|
||||
|
||||
val := v.Uint()
|
||||
buf := make([]byte, size)
|
||||
binary.PutUvarint(buf, val)
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// IsUintType returns whether the passed type is a type of uint and the number
|
||||
// of bytes the type is. To avoid platform specific sizes, the uint type returns
|
||||
// 8 bytes regardless of if it is smaller.
|
||||
func IsUintType(k reflect.Kind) (size int, okay bool) {
|
||||
switch k {
|
||||
case reflect.Uint:
|
||||
return 8, true
|
||||
case reflect.Uint8:
|
||||
return 1, true
|
||||
case reflect.Uint16:
|
||||
return 2, true
|
||||
case reflect.Uint32:
|
||||
return 4, true
|
||||
case reflect.Uint64:
|
||||
return 8, true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
// UUIDFieldIndex is used to extract a field from an object
|
||||
// using reflection and builds an index on that field by treating
|
||||
// it as a UUID. This is an optimization to using a StringFieldIndex
|
||||
|
||||
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@@ -701,10 +701,10 @@
|
||||
"revisionTime": "2017-02-14T02:52:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "pc2EZl8culxKGGIdstQ60l6avjU=",
|
||||
"checksumSHA1": "KeH4FuTKuv3tqFOr3NpLQtL1jPs=",
|
||||
"path": "github.com/hashicorp/go-memdb",
|
||||
"revision": "6b158e314030abfb0dbbbc24d0ac71b132259ebf",
|
||||
"revisionTime": "2017-02-10T23:23:44Z"
|
||||
"revision": "ed59a4bb9146689d4b00d060b70b9e9648b523af",
|
||||
"revisionTime": "2017-04-11T17:33:47Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/hashicorp/go-msgpack/codec",
|
||||
|
||||
Reference in New Issue
Block a user