// Variant returns the variant encoded in uuid.  It returns Invalid if
// uuid is invalid.
491657
func (uuid UUID) Variant() Variant {
	if len(uuid) != 16 {
		return Invalid
	}
	switch {
	case (uuid[8] & 0xc0) == 0x80:
		return RFC4122
	case (uuid[8] & 0xe0) == 0xc0:
		return Microsoft
	case (uuid[8] & 0xe0) == 0xe0:
		return Future
	default:
		return Reserved
	}
}
34384
func (n *Node) UUID() uuid.UUID {
	var buffer bytes.Buffer
	buffer.WriteString(string(*n.t))
	buffer.WriteString(string(*n.id))
	return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
}
279333
func (l *Client) GetVariation(id string) (Variation, error) {
	res := ApiResp{}
	data := Variation{}

	// make the request
	err := l.Get(parseLyticsURL(variationEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
1005172
func SetVersion(uuid []byte, version Version) {
	switch version {
	case VersionTimeBased:
		uuid[6] = (uuid[6] | 0x10) & 0x1f
	case VersionDCESecurity:
		uuid[6] = (uuid[6] | 0x20) & 0x2f
	case VersionNameBasedMD5:
		uuid[6] = (uuid[6] | 0x30) & 0x3f
	case VersionRandom:
		uuid[6] = (uuid[6] | 0x40) & 0x4f
	case VersionNameBasedSHA1:
		uuid[6] = (uuid[6] | 0x50) & 0x5f
	default:
		panic("version is unknown")
	}
}
259200
func (r *Containerd) Version() (string, error) {
	ver, err := r.Runner.CombinedOutput("containerd --version")
	if err != nil {
		return "", err
	}

	// containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39
	words := strings.Split(ver, " ")
	if len(words) >= 4 && words[0] == "containerd" {
		return strings.Replace(words[2], "v", "", 1), nil
	}
	return "", fmt.Errorf("unknown version: %q", ver)
}
1183311
func (v VirtualMachine) UUID(ctx context.Context) string {
	var o mo.VirtualMachine

	err := v.Properties(ctx, v.Reference(), []string{"config.uuid"}, &o)
	if err != nil {
		return ""
	}

	return o.Config.Uuid
}
254216
func Version(ver string) {
	if api, ok := apiDefinition(); ok {
		api.Version = ver
	}
}
906749
func UUID() string {
	version := byte(4)
	uuid := make([]byte, 16)
	rand.Read(uuid)

	// Set version
	uuid[6] = (uuid[6] & 0x0f) | (version << 4)

	// Set variant
	uuid[8] = (uuid[8] & 0xbf) | 0x80

	buf := make([]byte, 36)
	var dash byte = '-'
	hex.Encode(buf[0:8], uuid[0:4])
	buf[8] = dash
	hex.Encode(buf[9:13], uuid[4:6])
	buf[13] = dash
	hex.Encode(buf[14:18], uuid[6:8])
	buf[18] = dash
	hex.Encode(buf[19:23], uuid[8:10])
	buf[23] = dash
	hex.Encode(buf[24:], uuid[10:])

	return string(buf)
}
624507
func UUIDVersion4(u []byte) string {
	// https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29
	// 13th character is "4"
	u[6] = (u[6] | 0x40) & 0x4F
	// 17th character is "8", "9", "a", or "b"
	u[8] = (u[8] | 0x80) & 0xBF

	return fmt.Sprintf(`%X-%X-%X-%X-%X`, u[0:4], u[4:6], u[6:8], u[8:10], u[10:])
}
935802
func VariantClear(v *VARIANT) (err error) {
	hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
	if hr != 0 {
		err = NewError(hr)
	}
	return
}
1120872
func Version(name string, url string, kvdbOptions map[string]string) (string, error) {
	lock.RLock()
	defer lock.RUnlock()

	if dsVersion, exists := datastoreVersions[name]; exists {
		return dsVersion(url, kvdbOptions)
	}
	return "", ErrNotSupported
}
91327
func (v UUIDValue) encode(w io.Writer) error {
	raw := rawValue{
		Type: v.valueType(),
	}

	return raw.encodeFixedSlice(w, v[:])
}
467313
func (t *Triple) UUID() uuid.UUID {
	var buffer bytes.Buffer

	buffer.Write([]byte(t.s.UUID()))
	buffer.Write([]byte(t.p.UUID()))
	buffer.Write([]byte(t.o.UUID()))

	return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
}
1228407
func (u *UUID) setVariant(v byte) {
	switch v {
	case ReservedNCS:
		u[8] = (u[8] | ReservedNCS) & 0xBF
	case ReservedRFC4122:
		u[8] = (u[8] | ReservedRFC4122) & 0x7F
	case ReservedMicrosoft:
		u[8] = (u[8] | ReservedMicrosoft) & 0x3F
	}
}
43606
func UUID() (string, error) {
	u := make([]byte, 16)
	_, err := rand.Read(u)
	if err != nil {
		return "", err
	}

	u[6] = (u[6] & 0x0F) | 0x40 // Version 4
	u[8] = (u[8] & 0x3F) | 0x80 // Variant is 10

	uuid := fmt.Sprintf("{%08x-%04x-%04x-%04x-%012x}",
		u[:4], u[4:6], u[6:8], u[8:10], u[10:])

	return uuid, nil
}
466447
func uuidgen() string {
	b := uuidgenBytes()
	return fmt.Sprintf("%x-%x-%x-%x-%x",
		b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}
53338
func (v Variant) format() (string, bool) {
	switch v.sig.str[0] {
	case 'b', 'i':
		return fmt.Sprint(v.value), true
	case 'n', 'q', 'u', 'x', 't', 'd', 'h':
		return fmt.Sprint(v.value), false
	case 's':
		return strconv.Quote(v.value.(string)), true
	case 'o':
		return strconv.Quote(string(v.value.(ObjectPath))), false
	case 'g':
		return strconv.Quote(v.value.(Signature).str), false
	case 'v':
		s, unamb := v.value.(Variant).format()
		if !unamb {
			return "<@" + v.value.(Variant).sig.str + " " + s + ">", true
		}
		return "<" + s + ">", true
	case 'y':
		return fmt.Sprintf("%#x", v.value.(byte)), false
	}
	rv := reflect.ValueOf(v.value)
	switch rv.Kind() {
	case reflect.Slice:
		if rv.Len() == 0 {
			return "[]", false
		}
		unamb := true
		buf := bytes.NewBuffer([]byte("["))
		for i := 0; i < rv.Len(); i++ {
			// TODO: slooow
			s, b := MakeVariant(rv.Index(i).Interface()).format()
			unamb = unamb && b
			buf.WriteString(s)
			if i != rv.Len()-1 {
				buf.WriteString(", ")
			}
		}
		buf.WriteByte(']')
		return buf.String(), unamb
	case reflect.Map:
		if rv.Len() == 0 {
			return "{}", false
		}
		unamb := true
		var buf bytes.Buffer
		kvs := make([]string, rv.Len())
		for i, k := range rv.MapKeys() {
			s, b := MakeVariant(k.Interface()).format()
			unamb = unamb && b
			buf.Reset()
			buf.WriteString(s)
			buf.WriteString(": ")
			s, b = MakeVariant(rv.MapIndex(k).Interface()).format()
			unamb = unamb && b
			buf.WriteString(s)
			kvs[i] = buf.String()
		}
		buf.Reset()
		buf.WriteByte('{')
		sort.Strings(kvs)
		for i, kv := range kvs {
			if i > 0 {
				buf.WriteString(", ")
			}
			buf.WriteString(kv)
		}
		buf.WriteByte('}')
		return buf.String(), unamb
	}
	return `"INVALID"`, true
}