// UUID converts this implementation to the default type uuid.UUID
327247
func (o Immutable) UUID() UUID {
	id := UUID{}
	id.unmarshal(o.Bytes())
	return id
}
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
	}
}
297586
func GenUUID() string {
	uuid := make([]byte, 24)
	n, err := rand.Read(uuid)
	if n != len(uuid) || err != nil {
		log.Fatal("can't generate uuid")
		return ""
	}
	// TODO: verify the two lines implement RFC 4122 correctly
	uuid[8] = 0x80 // variant bits see page 5
	uuid[4] = 0x40 // version 4 Pseudo Random, see page 7

	str := hex.EncodeToString(uuid)
	return fmt.Sprintf("%s-%s-%s-%s-%s", str[:8], str[9:13], str[14:18], str[19:23], str[29:])
}
470460
func IsUUID(str string) bool {
	const uuidLen = 36
	if len(str) != uuidLen {
		return false
	}

	return validUUID.MatchString(str)
}
958308
func uuid() string {
	f, _ := os.Open(randomSource)
	defer f.Close()
	b := make([]byte, 16)
	f.Read(b)
	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}
271583
func UUIDFromTime(aTime time.Time) UUID {
	utcTime := aTime.In(time.UTC)
	t := int64(utcTime.Unix()-timeBase)*10000000 + int64(utcTime.Nanosecond()/100)
	clock := atomic.AddUint32(&clockSeq, 1)

	return TimeUUIDWith(t, clock, hardwareAddr)
}
1323264
func (c *Client) ModelUUID() string {
	tag, ok := c.st.ModelTag()
	if !ok {
		logger.Warningf("controller-only API connection has no model tag")
	}
	return tag.Id()
}
1337275
func UUID16(i uint16) UUID {
	b := make([]byte, 2)
	binary.LittleEndian.PutUint16(b, i)
	return UUID{b}
}
473023
func MarshalUUID(uuid UUID) (s string, err error) {
	var b [16]byte

	_, err = io.ReadFull(bytes.NewBuffer(uuid[:]), b[:])
	if err != nil {
		return
	}

	bin := hex.EncodeToString(b[:])
	s = bin[0:8] + "-" + bin[8:12] + "-" + bin[12:16] + "-" + bin[16:20] + "-" + bin[20:]

	return
}
232914
func (m Map) UUIDs() ([]uuid.UUID, error) {
	ret := make([]uuid.UUID, len(m.uuidMap))
	i := 0
	for uuidStr := range m.uuidMap {
		u := uuid.Parse(uuidStr)
		if u == nil {
			return nil, ErrMalformedUUID{uuidStr: uuidStr}
		}
		ret[i] = u
		i++
	}
	return ret, nil
}
81317
func (p *Packet) UUIDs() []ble.UUID {
	var u []ble.UUID
	if b := p.Field(someUUID16); b != nil {
		u = uuidList(u, b, 2)
	}
	if b := p.Field(allUUID16); b != nil {
		u = uuidList(u, b, 2)
	}
	if b := p.Field(someUUID32); b != nil {
		u = uuidList(u, b, 4)
	}
	if b := p.Field(allUUID32); b != nil {
		u = uuidList(u, b, 4)
	}
	if b := p.Field(someUUID128); b != nil {
		u = uuidList(u, b, 16)
	}
	if b := p.Field(allUUID128); b != nil {
		u = uuidList(u, b, 16)
	}
	return u
}
791218
func UnmarshalUUID(s string) (uuid UUID, err error) {
	if len(s) != 36 {
		err = errors.New("Invalid UUID length")
		return
	}
	if s[8:9] != "-" || s[13:14] != "-" || s[18:19] != "-" || s[23:24] != "-" {
		err = errors.New("Invalid UUID format")
		return
	}

	b, err := hex.DecodeString(s[0:8] + s[9:13] + s[14:18] + s[19:23] + s[24:])
	if err != nil {
		return
	}

	_, err = io.ReadFull(bytes.NewBuffer(b), uuid[:])
	return
}
1108281
func (s *ResourceMetadata) SetUid(v string) *ResourceMetadata {
	s.Uid = &v
	return s
}
666506
func (l *LookupOptions) UUID() uuid.UUID {
	var buffer bytes.Buffer
	buffer.WriteString(l.String())
	return uuid.NewSHA1(uuid.NIL, buffer.Bytes())
}
212577
func uuid() []byte {
	uuid := make([]byte, 16)
	_, err := rand.Read(uuid)
	if err != nil {
		panic("cue/hosted: uuid() failed to read random bytes")
	}

	// The following bit twiddling is outlined in RFC 4122.  In short, it
	// identifies the UUID as a v4 random UUID.
	uuid[6] = (4 << 4) | (0xf & uuid[6])
	uuid[8] = (8 << 4) | (0x3f & uuid[8])
	return uuid
}
602880
func (c *Client) ModelUUID() (string, bool) {
	tag, ok := c.st.ModelTag()
	if !ok {
		return "", false
	}
	return tag.Id(), true
}
475258
func ParseUUID(s string) UUID {
	if len(s) == 36+9 {
		if strings.ToLower(s[:9]) != "urn:uuid:" {
			return nil
		}
		s = s[9:]
	} else if len(s) != 36 {
		return nil
	}
	if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
		return nil
	}
	uuid := make([]byte, 16)
	for i, x := range []int{
		0, 2, 4, 6,
		9, 11,
		14, 16,
		19, 21,
		24, 26, 28, 30, 32, 34} {
		var v int64
		var err error
		if v, err = strconv.ParseInt(s[x:x+2], 16, 16); err != nil {
			return nil
		}
		uuid[i] = byte(v)
	}
	return uuid
}