package protocol

import (
	
	
	
)
RandReader is the random reader the protocol package will use to read random bytes from. This is exported for testing, and should not be used.
var RandReader = rand.Reader

const idempotencyTokenFillTag = `idempotencyToken`
CanSetIdempotencyToken returns true if the struct field should be automatically populated with a Idempotency token. Only *string and string type fields that are tagged with idempotencyToken which are not already set can be auto filled.
To auto fill an Idempotency token the field must be a string, tagged for auto fill, and have a zero value.
	case *string:
		return  == nil && len(.Tag.Get(idempotencyTokenFillTag)) != 0
	case string:
		return len() == 0 && len(.Tag.Get(idempotencyTokenFillTag)) != 0
	}

	return false
}
GetIdempotencyToken returns a randomly generated idempotency token.
func () string {
	 := make([]byte, 16)
	RandReader.Read()

	return UUIDVersion4()
}
SetIdempotencyToken will set the value provided with a Idempotency Token. Given that the value can be set. Will panic if value is not setable.
func ( reflect.Value) {
	if .Kind() == reflect.Ptr {
		if .IsNil() && .CanSet() {
			.Set(reflect.New(.Type().Elem()))
		}
		 = .Elem()
	}
	 = reflect.Indirect()

	if !.CanSet() {
		panic(fmt.Sprintf("unable to set idempotnecy token %v", ))
	}

	 := make([]byte, 16)
	,  := rand.Read()
TODO handle error
		return
	}

	.Set(reflect.ValueOf(UUIDVersion4()))
}
UUIDVersion4 returns a Version 4 random UUID from the byte slice provided
https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 13th character is "4"
17th character is "8", "9", "a", or "b"
	[8] = ([8] | 0x80) & 0xBF

	return fmt.Sprintf(`%X-%X-%X-%X-%X`, [0:4], [4:6], [6:8], [8:10], [10:])