// UUID generate a new V4 UUID
762412
func ID() string {
	u, err := uuid.NewV4()
	if err != nil {
		panic(err)
	}
	return "_" + u.String()
}
1143120
func (s *UpdateEventSourceMappingInput) SetUUID(v string) *UpdateEventSourceMappingInput {
	s.UUID = &v
	return s
}
1240478
func (o *Object) UUID() uuid.UUID {
	switch {
	case o.l != nil:
		return o.l.UUID()
	case o.p != nil:
		return o.p.UUID()
	default:
		return o.n.UUID()
	}
}
1200955
func (s *DeleteEventSourceMappingInput) SetUUID(v string) *DeleteEventSourceMappingInput {
	s.UUID = &v
	return s
}
1159948
func NewUUID(domain Domain) ([]byte, error) {
	uuid, err := timebased.NewUUID()
	if err != nil {
		return nil, err
	}

	switch domain {
	case User:
		uid := os.Getuid()
		binary.BigEndian.PutUint32(uuid[0:], uint32(uid)) // network byte order
	case Group:
		gid := os.Getgid()
		binary.BigEndian.PutUint32(uuid[0:], uint32(gid)) // network byte order
	default:
		return nil, errors.New("domain is invalid")
	}

	// set version(v2)
	internal.SetVersion(uuid, internal.VersionDCESecurity)
	// set layout(RFC4122)
	internal.SetLayout(uuid, internal.LayoutRFC4122)

	return uuid, nil
}
1081133
func (f *UUIDFuncs) V1() (string, error) {
	u, err := uuid.NewUUID()
	if err != nil {
		return "", err
	}
	return u.String(), nil
}
1307562
func NewUUID36() (string, error) {
	b := make([]byte, 16)
	_, err := randSource.Read(b)
	if err != nil {
		return "", err
	}
	s := fmt.Sprintf("%x", b)
	return ConvertUp(s, base36alphabet), nil
}
1340739
func NewUUIDv1() (UUID, error) {
	uuid := UUID{}
	epoch := int64(0x01b21dd213814000)
	now := uint64(time.Now().UnixNano()/100 + epoch)

	clockSeqRand := [2]byte{}
	rand.Read(clockSeqRand[:])
	clockSeq := binary.LittleEndian.Uint16(clockSeqRand[:])

	timeLow := uint32(now & (0x100000000 - 1))
	timeMid := uint16((now >> 32) & 0xffff)
	timeHighVer := uint16((now >> 48) & 0x0fff)
	clockSeq &= 0x3fff

	binary.LittleEndian.PutUint32(uuid[0:4], timeLow)
	binary.LittleEndian.PutUint16(uuid[4:6], timeMid)
	binary.LittleEndian.PutUint16(uuid[6:8], timeHighVer)
	binary.LittleEndian.PutUint16(uuid[8:10], clockSeq)
	copy(uuid[10:16], cachedMACAddress)

	uuid.setVersion(UUIDv1)
	uuid.setVariant(UUIDVariantRFC4122)
	return uuid, nil
}
3620
func (n *Network) GetUUID() ([]byte, error) {
	var cUuid [C.VIR_UUID_BUFLEN](byte)
	cuidPtr := unsafe.Pointer(&cUuid)
	var err C.virError
	result := C.virNetworkGetUUIDWrapper(n.ptr, (*C.uchar)(cuidPtr), &err)
	if result != 0 {
		return []byte{}, makeError(&err)
	}
	return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
951753
func (uuid UUID) Version() (Version, bool) {
	if len(uuid) != 16 {
		return 0, false
	}
	return Version(uuid[6] >> 4), true
}
794465
func ParseUUID(s string) (UUID, error) {
	s = strings.Replace(s, "-", "", -1)
	b, err := hex.DecodeString(s)
	if err != nil {
		return UUID{}, err
	}
	if err := lenErr(len(b)); err != nil {
		return UUID{}, err
	}
	return UUID{reverse(b)}, nil
}
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
}
589754
func UUID4() (u UUID) {
	// s := make([]byte, 16)
	// n, err := rand.Read(s)
	// if n != 16 || err != nil {
	// 	return nil
	// }

	for i, _ := range u {
		// u[i] = v
		u[i] = byte(rand.Int31n(256))
	}

	// Set the four most significant bits (bits 12 through 15) of the
	// time_hi_and_version field to the 4-bit version number from Section 4.1.3.
	u[6] = u[6]&0x0f | 0x40

	// Set the two most significant bits (bits 6 and 7) of the
	// clock_seq_hi_and_reserved to zero and one, respectively.
	u[8] = u[8]&0x3f | 0x80

	return u
}
1307997
func PrefixUUID(prefix string, uuid string) (string, error) {
	uuidLetters := uuid[:8] + uuid[9:13] + uuid[14:18] + uuid[19:23] + uuid[24:36]
	prefixedUUID, err := FormatUUID(prefix + uuidLetters)
	if err != nil {
		return "", err
	}
	return prefixedUUID, nil
}
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
}
242224
func NewUUID() ([]byte, error) {
	uuid := make([]byte, 16)
	n, err := rand.Read(uuid[:])
	if err != nil {
		return nil, errors.Wrap(err, "could not generate random bytes")
	}
	if n != len(uuid) {
		return nil, errors.New("could not generate random bytes with 16 length")
	}

	// set version(v4)
	internal.SetVersion(uuid, internal.VersionRandom)
	// set layout(RFC4122)
	internal.SetLayout(uuid, internal.LayoutRFC4122)

	return uuid, nil
}
337969
func NewV4() (UUID, error) {
	u := UUID{}
	if _, err := randomReader.Read(u[:]); err != nil {
		return Nil, err
	}
	u.setVersion(V4)
	u.setVariant(VariantRFC4122)

	return u, nil
}