github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/twinj/uuid/array.go (about)

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