You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

  1. package uuid
  2. /****************
  3. * Date: 1/02/14
  4. * Time: 10:08 AM
  5. ***************/
  6. const (
  7. variantIndex = 8
  8. versionIndex = 6
  9. )
  10. // A clean UUID type for simpler UUID versions
  11. type Array [length]byte
  12. func (Array) Size() int {
  13. return length
  14. }
  15. func (o Array) Version() int {
  16. return int(o[versionIndex]) >> 4
  17. }
  18. func (o *Array) setVersion(pVersion int) {
  19. o[versionIndex] &= 0x0F
  20. o[versionIndex] |= byte(pVersion) << 4
  21. }
  22. func (o *Array) Variant() byte {
  23. return variant(o[variantIndex])
  24. }
  25. func (o *Array) setVariant(pVariant byte) {
  26. setVariant(&o[variantIndex], pVariant)
  27. }
  28. func (o *Array) Unmarshal(pData []byte) {
  29. copy(o[:], pData)
  30. }
  31. func (o *Array) Bytes() []byte {
  32. return o[:]
  33. }
  34. func (o Array) String() string {
  35. return formatter(&o, format)
  36. }
  37. func (o Array) Format(pFormat string) string {
  38. return formatter(&o, pFormat)
  39. }
  40. // Set the three most significant bits (bits 0, 1 and 2) of the
  41. // sequenceHiAndVariant equivalent in the array to ReservedRFC4122.
  42. func (o *Array) setRFC4122Variant() {
  43. o[variantIndex] &= 0x3F
  44. o[variantIndex] |= ReservedRFC4122
  45. }
  46. // Marshals the UUID bytes into a slice
  47. func (o *Array) MarshalBinary() ([]byte, error) {
  48. return o.Bytes(), nil
  49. }
  50. // Un-marshals the data bytes into the UUID.
  51. func (o *Array) UnmarshalBinary(pData []byte) error {
  52. return UnmarshalBinary(o, pData)
  53. }