UUID.st
author Stefan Vogel <sv@exept.de>
Fri, 24 Apr 2015 14:18:00 +0200
changeset 3542 b00b42c1378d
parent 3122 9d0a142eee9f
child 3549 ae696bf10bf5
permissions -rw-r--r--
class: UUID changed: #asNativeBytes #fromNativeBytes: use IsBigEndian classVar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
     1
"{ Encoding: utf8 }"
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
     2
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2002 by eXept Software AG
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
    16
"{ NameSpace: Smalltalk }"
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
    17
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
ByteArray variableByteSubclass:#UUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    20
	classVariableNames:'CachedMACAddress Lock SequenceNumber LastTime Increment
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    21
		NameSpaceToUuidBytes'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
1304
1c58aa764724 category
Claus Gittinger <cg@exept.de>
parents: 1287
diff changeset
    23
	category:'Net-Communication-Support'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
copyright
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 COPYRIGHT (c) 2002 by eXept Software AG
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
              All Rights Reserved
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 This software is furnished under a license and may be used
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 only in accordance with the terms of that license and with the
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 be provided or otherwise made available to, or used by, any
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 other person.  No title to or ownership of the software is
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 hereby transferred.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    40
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    41
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    42
documentation
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    43
"
1544
6c339f276b91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    44
    128-bit Universal Unique Ids (UUIDs) as defined by OpenGroup/DCE
6c339f276b91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    45
        http://www.opengroup.org/onlinepubs/9629399/apdxa.htm.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    46
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    47
    See also RFC4122.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    48
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    49
    A UUID is unique in time and space (at least until about Year 3400).
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    50
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    51
    Several fields if the UUID are interpreted as integers, so host/network byte
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    52
    order is relevant. UUIDs are stored in a ByteArray in network byte order (MSB-first),
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    53
    so they may be exported/imported between different machines.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    54
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    55
    You can import UUIDs in host byte order using #fromNativeBytes:
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    56
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    57
    [author:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    58
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    59
    [instance variables:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    60
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    61
    [class variables:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    62
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    63
    [see also:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    64
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    65
"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    66
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    67
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    68
!UUID class methodsFor:'initialization'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    69
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    70
initialize
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    71
    "I want to get informed about image restarts"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    72
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    73
    Lock isNil ifTrue:[
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    74
        Lock := RecursionLock new name:#UUID.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    75
        LastTime := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    76
        Increment := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    77
        ObjectMemory addDependent:self.
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    78
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    79
        NameSpaceToUuidBytes := Dictionary withKeysAndValues:#(
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    80
                DNS  #[16r6B 16rA7 16rB8 16r10 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8]            
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    81
                URL  #[16r6B 16rA7 16rB8 16r11 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8]
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    82
                "ASN.1 OID in DER or as Text"
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    83
                OID  #[16r6B 16rA7 16rB8 16r12 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8]
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    84
                "X.500 DN as DER or as Text"
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    85
                X500 #[16r6B 16rA7 16rB8 16r14 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8]            
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
    86
            ).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    87
    ]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    88
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    89
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    90
update:something with:aParameter from:changedObject
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    91
    "flush cached MAC address (may have been restarted on another host)"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    92
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    93
    (something == #restarted) ifTrue:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    94
        CachedMACAddress := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    95
        SequenceNumber := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    96
    ]
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
!UUID class methodsFor:'instance creation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   101
basicNew
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   102
    ^ super basicNew:16
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   103
!
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   104
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   105
basicNew:size
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   106
    "allow creating with exact size. We need this for XMLStandardDecoder"
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   107
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   108
    size ~~ 16 ifTrue:[
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   109
        ^ self shouldNotImplement.
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   110
    ].
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   111
    ^ super basicNew:size.
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   112
!
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   113
2017
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   114
decodeFromLiteralArray:anArray
2018
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   115
    anArray size == 2 ifTrue:[
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   116
        "/ UUID 'uuid-string'
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   117
        ^ self readFrom:(anArray at:2).
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   118
    ].
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   119
    "/ UUID bytes...
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   120
    ^ super decodeFromLiteralArray:anArray "/ self readFrom:(anArray at:2)
2017
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   121
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   122
    "
2018
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   123
     (UUID decodeFromLiteralArray:#(UUID '5b023ce0-41f1-11dd-b99f-001558137da0'))
316b0a396e86 decodeFromLiterlArray
fm
parents: 2017
diff changeset
   124
       literalArrayEncoding   
2017
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   125
    "
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   126
!
d08521448dc0 decodeFromLiterlArray
fm
parents: 1923
diff changeset
   127
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   128
fromBytes:aByteArray
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   129
    "set uuid from aByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   130
     aByteArray must be 16 bytes in network byte order (MSB-first)"
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   131
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   132
    |uuid|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   134
    uuid := super basicNew:16.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    uuid replaceFrom:1 to:16 with:aByteArray.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   136
    ^ uuid.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   138
    "    
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   139
     UUID fromBytes:#[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   140
                      16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   141
                      16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   142
                      16r13 16r14 16r15 16r16]. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   143
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   144
!
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
2950
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   146
fromBytes:aByteArray MSB:msb
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   147
    "Set the UUID from aByteArray. UUIDS are stored internally as MSB-first. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   148
     So, alway set
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   149
        msb = true      if reading from network or persistent storage"
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   151
    |uuid|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   152
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   153
    uuid := self fromBytes:aByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   154
    msb ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   155
        self adjustByteOrder:uuid.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    ^ uuid
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
                      16r13 16r14 16r15 16r16] msb:false. 
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                      16r13 16r14 16r15 16r16] msb:true.    
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
2950
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   174
fromBytes:aByteArray msb:msb
2978
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   175
    <resource: #obsolete>
2950
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   176
    "Set the UUID from aByteArray. UUIDS are stored internally as MSB-first. 
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   177
     So, alway set
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   178
        msb = true      if reading from network or persistent storage"
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   179
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   180
    self obsoleteMethodWarning:'use fromBytes:MSB:'.
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   181
    ^ self fromBytes:aByteArray MSB:msb
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   182
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   183
    "
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   184
     UUID fromBytes:#[16r01 16r02 16r03 16r04
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   185
                      16r05 16r06 16r07 16r08
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   186
                      16r09 16r10 16r11 16r12
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   187
                      16r13 16r14 16r15 16r16] msb:false. 
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   188
    "
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   189
    "
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   190
     UUID fromBytes:#[16r01 16r02 16r03 16r04
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   191
                      16r05 16r06 16r07 16r08
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   192
                      16r09 16r10 16r11 16r12
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   193
                      16r13 16r14 16r15 16r16] msb:true.    
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   194
    "
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   195
!
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   196
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   197
fromNativeBytes:aByteArray
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   198
    "convert bytes to uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   199
     aByteArray represents a UUID in host byte order 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   200
     - e.g. an UUID fetched from the Windows OS"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   201
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   202
    |uuid|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   203
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   204
    uuid := self fromBytes:aByteArray.
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
   205
    IsBigEndian ifFalse:[
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   206
        self adjustByteOrder:uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   207
    ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   208
    ^ uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   209
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   210
    "    
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   211
     UUID fromNativeBytes:#[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   212
                              16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   213
                              16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   214
                              16r13 16r14 16r15 16r16]. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   215
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   216
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   217
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   218
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   219
genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   220
    "generate a new random UUID"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   221
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   222
    ^ (super basicNew:16) genRandomUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   223
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   224
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   225
      self genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   226
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   227
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   228
2431
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   229
genTimestampUUID
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   230
    "generate a new timestamp UUID"
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   231
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   232
    ^ (super basicNew:16) genTimestampUUID
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   233
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   234
    "
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   235
      self genTimestampUUID
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   236
    "
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   237
!
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   238
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   239
genUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   240
    "generate a uuid.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   241
     If a physical mac address can be retrieved from the OS,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   242
     a mac-address/timestamp uuid is generated,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   243
     otherwise a random uuid will be generated."
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   245
    ^ (super basicNew:16) genUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   246
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   247
    "
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   248
     self genUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   249
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   252
genUUID:nameStringOrBytes inNameSpace:namespaceString
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   253
    "generate a namespace UUID (Version 5, hashed by SHA-1).
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   254
     See RFC4122."
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   255
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   256
    ^ (super basicNew:16) genUUID:nameStringOrBytes inNameSpace:namespaceString
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   257
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   258
    "
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   259
        self genUUID:'www.example.org' inNameSpace:'DNS'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   260
        self genUUID:'http://www.exept.de' inNameSpace:'URL'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   261
        self genUUID:'1.2.3.4.5' inNameSpace:'OID'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   262
        self genUUID:(OSI::DERCoder encode:(OSI::ASN1_OID newID:#(1 2 3 4 5))) 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   263
             inNameSpace:'OID'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   264
        self genUUID:'c=de, o=eXept Software AG, cn=Development' 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   265
             inNameSpace:'X500'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   266
        self genUUID:(OSI::DERCoder encode:(OSI::DistinguishedName fromString:'c=de, o=eXept Software AG, cn=Development') asAsn1Value) 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   267
             inNameSpace:'X500'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   268
    "
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   269
!
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   270
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
new
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   272
    ^ (super basicNew:16) genUUID
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   273
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   274
    "
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   275
     self new 
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   276
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
new:size
1320
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   280
    "allow creating with exact size. We need this for XMLStandardDecoder"
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   281
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   282
    size ~~ 16 ifTrue:[
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   283
        ^ self shouldNotImplement.
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   284
    ].
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   285
    ^ super new:size.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   286
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   287
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   288
readFrom:aStringOrStream onError:errorBlock
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   289
    |d offs s uuid t byte hasBrackets|
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   290
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   291
    Error handle:[:ex |
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   292
        ^ errorBlock value.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   293
    ] do:[
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   294
        s := aStringOrStream readStream.
1923
6380ea5d7385 #new is now the same as genUUID (squeak compatibility)
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   295
        uuid := super basicNew:16.
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   296
        hasBrackets := false.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   297
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   298
        s skipSeparators.
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   299
        s peek == ${ ifTrue:[
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   300
            s next; skipSeparators.
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   301
            hasBrackets := true.
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   302
        ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   303
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   304
        t := s next:8.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   305
        d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   306
        uuid unsignedLongAt:1 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   307
        offs := 5.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   308
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   309
        s next.         "skip $-"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   310
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   311
        1 to:2 do:[:i |
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   312
            t := s next:4.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   313
            d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   314
            uuid unsignedShortAt:offs put:d bigEndian:true.
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   315
            offs := offs + 2.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   316
            s next.     "skip $-"
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   317
        ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   318
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   319
        1 to:2 do:[:i |
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   320
            t := s next:2.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   321
            d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   322
            uuid at:offs put:d.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   323
            offs := offs + 1.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   324
        ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   325
        s next.         "skip $-"
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   326
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   327
        1 to:6 do:[:i |
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   328
            t := s next:2.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   329
            byte := Integer readFrom:t radix:16 onError:[^ errorBlock value].
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   330
            uuid at:offs put:byte.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   331
            offs := offs + 1.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   332
        ].
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   333
        hasBrackets ifTrue:[
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   334
            s peek == $} 
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   335
                ifTrue:[s next] 
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   336
                ifFalse:errorBlock
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   337
        ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   338
    ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   339
    ^ uuid
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   340
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   341
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   342
     UUID readFrom:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77' 
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   343
     UUID readFrom:'{5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77}' 
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   344
     UUID readFrom:'{5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77' 
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   345
     UUID fromString:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77 bllll' 
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   346
     UUID fromString:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77' 
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   347
     UUID fromString:'00000001-0000-0000-C000-000000000046'
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   348
     UUID fromString:'00000001-0000-0000-C000-000000004600'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   349
     UUID fromString:'00000001-0000-0000-C000-000000460000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   350
     UUID fromString:'00000001-0000-0000-C000-000046000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   351
     UUID fromString:'00000001-0000-0000-C000-004600000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   352
     UUID fromString:'00000001-0000-0000-C000-460000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   353
     UUID fromString:'00000001-0000-0000-C046-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   354
     UUID fromString:'00000001-0000-0046-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   355
     UUID fromString:'00000001-0000-4600-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   356
     UUID fromString:'00000001-0046-0000-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   357
     UUID fromString:'00000001-4600-0000-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   358
     UUID fromString:'00000100-4600-0000-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   359
     UUID fromString:'00010000-4600-0000-C000-000000000000'
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   360
     UUID fromString:'10000000-4600-0000-C000-000000000000'
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   361
    "
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   362
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   363
    "Modified: / 10-10-2007 / 23:03:47 / cg"
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   366
!UUID class methodsFor:'helpers'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   367
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   368
adjustByteOrder:aByteArray
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   369
    "change the byte order of the uuid"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   370
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   371
    |d|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   372
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   373
    d := aByteArray unsignedLongAt:1 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   374
    aByteArray unsignedLongAt:1 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   375
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   376
    d := aByteArray unsignedShortAt:1+4 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   377
    aByteArray unsignedShortAt:1+4 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   378
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   379
    d := aByteArray unsignedShortAt:1+4+2 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   380
    aByteArray unsignedShortAt:1+4+2 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   381
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   382
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   383
getDtssUtcTime
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   384
    "return the DTSS based time in 100 nsec intervals
1647
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   385
     DTSS UTC base time is October 15, 1582 (the start of the Gregorian Calendar)."
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   386
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   387
     "Unix base time is January 1, 1970.
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   388
      The difference between both is: 122192928000000000"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   389
1647
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   390
"   
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   391
        (Timestamp epoch asDate subtractDate:(Date day:15 month:10 year:1582))
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   392
        *  (24 * 60 * 60)
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   393
"
1613
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   394
1647
124e977b6a8f comment
Stefan Vogel <sv@exept.de>
parents: 1613
diff changeset
   395
    ^ (Timestamp now getMilliseconds + 12219292800000) * 10000.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   396
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   397
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   398
getValidMACAddress
2978
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   399
    "return the first valid MAC address (i.e. having at least 6 bytes with the first six bytes ~~ 0)"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   400
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   401
    CachedMACAddress isNil ifTrue:[
2978
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   402
        CachedMACAddress := false.      "negative caching: remember the fact, that there is no MAC address" 
1577
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   403
        [
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   404
            CachedMACAddress := OperatingSystem getNetworkMACAddresses 
2978
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   405
                                    detect:[:macAddress | macAddress size >= 6 
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   406
                                                            and:[(macAddress startsWith:#[0 0 0 0 0 0]) not]]
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   407
                                    ifNone:false.
1577
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   408
        ] on:PrimitiveFailure do:[:ex| "ignore"].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   409
    ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   410
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   411
    ^ CachedMACAddress
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   412
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   413
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   414
       CachedMACAddress := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   415
       self getValidMACAddress
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   416
    "
1491
512b21b45a9e noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents: 1467
diff changeset
   417
512b21b45a9e noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents: 1467
diff changeset
   418
    "Modified: / 17-11-2004 / 01:45:53 / cg"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   419
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   420
2954
1f5e5edc610d class: UUID
Stefan Vogel <sv@exept.de>
parents: 2950
diff changeset
   421
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   422
!UUID methodsFor:'accessing'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   423
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   424
clockSeqHiAndReserved
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   425
    ^ self at:9
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   426
!
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   427
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   428
clockSeqLow
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   429
    ^ self at:10
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   430
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   431
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   432
node
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   433
    "answer the node (ethernet) address of this uuid"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   434
3122
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   435
    self isTimestampUUID ifFalse:[
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   436
        ConversionError raiseWith:self errorString:' - trying to get node address from random UUID'.
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   437
    ].            
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   438
    ^ (ByteArray new:6) replaceFrom:1 to:6 with:self startingAt:11.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   439
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   440
    "
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   441
       (self allInstances 
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   442
            select:[:e| e isTimestampUUID] 
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   443
            thenCollect:[:e| e node]) asBag
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   444
    "
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   445
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   446
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   447
timeHighAndVersion
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   448
    ^ self unsignedShortAt:7 bigEndian:true
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   449
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   450
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   451
timeLow
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   452
    ^ self unsignedLongAt:1 bigEndian:true
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   453
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   454
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   455
timeMid
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   456
    ^ self unsignedShortAt:5 bigEndian:true
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   457
!
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   458
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   459
timestamp
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   460
    "Get the UTC timestamp, when the UUID has been created.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   461
     This is only valid for timestampUUIDs"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   462
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   463
    |low med high dtssUtcTime|
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   464
3121
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   465
    self isTimestampUUID ifFalse:[
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   466
        ConversionError raiseWith:self errorString:' - trying to get timestamp from random UUID'.
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   467
    ].            
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   468
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   469
    low := self unsignedLongAt:1 bigEndian:true.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   470
    med := self unsignedShortAt:5 bigEndian:true.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   471
    high := (self unsignedShortAt:7 bigEndian:true) bitAnd:16rFFF.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   472
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   473
    dtssUtcTime := low + ((med + (high bitShift:16)) bitShift:32).
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   474
2739
00ec79f5bb61 Fix a stc problem
Stefan Vogel <sv@exept.de>
parents: 2738
diff changeset
   475
    ^ Timestamp utcMillisecondsSince1970:(dtssUtcTime//10000) - 12219292800000.
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   476
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   477
    "
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   478
        self genTimestampUUID timestamp
3121
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   479
        self genRandomUUID timestamp
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   480
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   481
        (self allInstances asSet asArray select:[:e| e isTimestampUUID] 
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   482
                                            thenCollect:[:e| e timestamp]) sort
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   483
    "
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   484
!
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   485
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   486
version
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   487
    "the version number of the uuid"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   488
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   489
    ^ ((self at:7) bitAnd:16rF0) bitShift:-4.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   490
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   491
    "
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   492
        self genTimestampUUID version
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   493
        self genRandomUUID version
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   494
    "
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   495
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   496
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
!UUID methodsFor:'converting'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   499
asBytes
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   500
    "convert this UUID to a ByteArray in network byte order (MSB-first)"
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   501
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   502
    |bytes|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
    bytes := ByteArray new:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
    bytes replaceFrom:1 to:16 with:self.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   506
    ^ bytes
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   508
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   509
     |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   510
        
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   511
     bytes := #[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   512
                      16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   513
                      16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   514
                      16r13 16r14 16r15 16r16].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   515
     (UUID fromBytes:bytes) asBytes ~= bytes ifTrue:[self halt] 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   516
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   517
!
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   519
asBytesMSB:msb
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   520
    "convert this UUID to a ByteArray.
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   521
     If msb == false, it is converted into LSB-first byte ordering"
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   522
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   523
    |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   524
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   525
    bytes := self asBytes.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   526
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   527
    msb ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   528
        self class adjustByteOrder:bytes.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
    ^ bytes
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   531
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   532
    "Modified: / 10-10-2007 / 22:51:09 / cg"
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   533
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   534
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   535
asNativeBytes
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   536
    "convert this uuid to a ByteArray in host byte order.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   537
     Use this only to pass the UUID to the OS (Windows)"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   538
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   539
    |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   540
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   541
    bytes := self asBytes.
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
   542
    IsBigEndian ifFalse:[
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   543
        self class adjustByteOrder:bytes.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   544
    ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   545
    ^ bytes.
2021
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   546
!
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   547
2170
8cd3d9480ab7 new: #asUUID
Stefan Vogel <sv@exept.de>
parents: 2132
diff changeset
   548
asUUID
8cd3d9480ab7 new: #asUUID
Stefan Vogel <sv@exept.de>
parents: 2132
diff changeset
   549
    ^ self
8cd3d9480ab7 new: #asUUID
Stefan Vogel <sv@exept.de>
parents: 2132
diff changeset
   550
!
8cd3d9480ab7 new: #asUUID
Stefan Vogel <sv@exept.de>
parents: 2132
diff changeset
   551
2021
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   552
literalArrayEncoding
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   553
    ^ Array 
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   554
        with:(self class name)
21f1faba832a literalArray
fm
parents: 2018
diff changeset
   555
        with:(self printString).
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
2132
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   558
!UUID methodsFor:'copying'!
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   559
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   560
deepCopy
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   561
    "I am never changed, after I have been created.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   562
     So there is no need to make a copy"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   563
2132
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   564
    ^ self
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   565
!
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   566
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   567
deepCopyUsing:aDictionary postCopySelector:postCopySelector
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   568
    "I am never changed, after I have been created.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   569
     So there is no need to make a copy"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   570
2132
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   571
    ^ self
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   572
!
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   573
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   574
shallowCopy
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   575
    "I am never changed, after I have been created.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   576
     So there is no need to make a copy"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   577
2132
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   578
    ^ self
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   579
!
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   580
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   581
simpleDeepCopy
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   582
    "I am never changed, after I have been created.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   583
     So there is no need to make a copy"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   584
2132
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   585
    ^ self
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   586
! !
c580316610e1 copying - a UUID is unique...
ca
parents: 2069
diff changeset
   587
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
!UUID methodsFor:'generating uuids'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   590
genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   591
    "answer a randomly generated uuid as defined in RFC4122 section 4.4"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   592
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   593
    (self at:7) ~~ 0 ifTrue:[
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   594
        "once created, an UUID is immutable"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   595
        self noModificationError.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   596
    ].
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   597
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   598
    self replaceFrom:1 to:16 with:(RandomGenerator new nextBytes:16).
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   599
    "multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   600
    self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40).
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   601
    self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80).
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   602
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   603
    "
2978
4497be5fc993 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
   604
      self genRandomUUID
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   605
      self genRandomUUID genRandomUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   606
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   607
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   608
    "
2431
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   609
      |uuids sample|
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   610
      sample := 100000.
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   611
      uuids := Set new:sample.  
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   612
      sample timesRepeat:[
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   613
          uuids add:UUID genRandomUUID.
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   614
      ].
2433
b225b9e4cde8 comment/format in: #genRandomUUID
Stefan Vogel <sv@exept.de>
parents: 2431
diff changeset
   615
      self assert:(uuids size = sample).  
b225b9e4cde8 comment/format in: #genRandomUUID
Stefan Vogel <sv@exept.de>
parents: 2431
diff changeset
   616
      uuids
2431
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   617
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   618
      1 to: 100 do:[ : el |
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   619
          Transcript show:el.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   620
          Transcript show:': '.
2431
ba791db4a743 added: #genTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2428
diff changeset
   621
          Transcript showCR:(UUID genRandomUUID).
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   622
      ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   623
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   624
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   625
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   626
genTimestampUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   627
    "generate a timestamp (and mac-address) based uuid"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   628
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   629
    |macBytes utcTime seqNr|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
2701
d726c35f7084 changed: #genTimestampUUID
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   631
    (macBytes := CachedMACAddress) isNil ifTrue:[
d726c35f7084 changed: #genTimestampUUID
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   632
        macBytes := self class getValidMACAddress.
d726c35f7084 changed: #genTimestampUUID
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   633
    ].
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   634
    macBytes size ~~ 6 ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   635
        self error:'no mac address - cannot generate UUID'.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   636
    ].
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   638
    (self at:7) ~~ 0 ifTrue:[
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   639
        "once created, an UUID is immutable"
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   640
        self noModificationError.
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   641
    ].
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   642
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   643
    "use 60 bit counter of 100ns ticks since 00:00:00 15.oct 1582 (sigh)"
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   644
    utcTime := self class getDtssUtcTime.
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   645
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   646
    Lock critical:[
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   647
        SequenceNumber isNil ifTrue:[
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   648
            SequenceNumber := RandomGenerator new nextIntegerBetween:0 and:16383.
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   649
        ].
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   650
        utcTime > (LastTime+Increment) ifTrue:[
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   651
            Increment := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   652
        ] ifFalse:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   653
            LastTime = utcTime ifTrue:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   654
                "clock didn't advance since last call. Simply add a tick"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   655
                Increment := Increment + 1.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   656
            ] ifFalse:[
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   657
                "clock went backwards - increment SequenceNumber"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   658
                Increment := 0.
1214
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   659
                SequenceNumber := SequenceNumber + 1.
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   660
                SequenceNumber >= 16384 ifTrue:[SequenceNumber := 0].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   661
            ].
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
        ].
1214
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   663
        
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   664
        LastTime := utcTime.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   665
        utcTime := utcTime + Increment.
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   666
        seqNr := SequenceNumber.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   669
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   670
    "time low: long"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   671
    self unsignedLongAt:1 put:(utcTime bitAnd:16rFFFFFFFF) bigEndian:true.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   672
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   673
    "time med: short"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   674
    utcTime := utcTime bitShift:-32.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   675
    self unsignedShortAt:5 put:(utcTime bitAnd:16rFFFF) bigEndian:true.
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   676
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   677
    "time high and version: short
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   678
     multiplex the 4 bit version number in highest 4 bits (version 1 -> time based version)"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   679
    self unsignedShortAt:7 put:((utcTime bitShift:-16) bitOr:16r1000) bigEndian:true.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   681
    "2 sequence bytes + reserved bits (this is not a short!!)"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   682
    self at:9  put:(((seqNr bitShift:-8) bitAnd:16r3F) bitOr:16r80).
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   683
    self at:10 put:(seqNr bitAnd:16rFF).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   684
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   685
    "48 bits of MAC-Address"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   686
    self replaceFrom:11 to:16 with:macBytes startingAt:1.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
    "
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   689
      self genTimestampUUID
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   690
      self genTimestampUUID genTimestampUUID
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   691
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   693
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   694
      1 to: 100 do:[ : el |
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   695
          Transcript show:el.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   696
          Transcript show:': '.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   697
          Transcript showCR:(UUID new genTimestampUUID).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   698
      ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   699
    "
2701
d726c35f7084 changed: #genTimestampUUID
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   700
d726c35f7084 changed: #genTimestampUUID
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   701
    "Modified: / 26-12-2011 / 13:41:23 / cg"
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   702
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   703
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   704
genUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   705
    "generate a uuid - the existing uuid bytes are overwritten.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   706
     If a physical mac address can be retrieved from the OS,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   707
     a mac-address/timestamp uuid is generated,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   708
     otherwise a random uuid will be generated."
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   709
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   710
    CachedMACAddress isNil ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   711
        self class getValidMACAddress.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   712
    ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   713
    CachedMACAddress == false ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   714
        "no mac address - generate random UUID"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   715
        ^ self genRandomUUID.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   716
    ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   717
    ^ self genTimestampUUID.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   718
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   719
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   720
      self genUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   721
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   722
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   723
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   724
      1 to: 100 do:[ : el |
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   725
          Transcript show:el.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   726
          Transcript show:': '.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   727
          Transcript showCR:(UUID genUUID).
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   728
      ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   729
    "
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   730
!
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   731
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   732
genUUID:nameStringOrBytes inNameSpace:namespaceString
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   733
    "generate a namespace UUID (Version 5, hashed by SHA-1).
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   734
     See RFC4122."
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   735
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   736
    |sha1|
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   737
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   738
    (self at:7) ~~ 0 ifTrue:[
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   739
        "once created, an UUID is immutable"
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   740
        self noModificationError.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   741
    ].
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   742
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   743
    sha1 := SHA1Stream new.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   744
    sha1 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   745
        nextPutAll:(NameSpaceToUuidBytes at:namespaceString);
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   746
        nextPutAll:nameStringOrBytes.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   747
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   748
    self replaceFrom:1 to:16 with:(sha1 hashValue).
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   749
    "multiplex the 4 bit version number (Version 5 -> SHA1 Namspace UUID) in high bits of byte 7"
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   750
    self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r50).
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   751
    self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80).
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   752
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   753
    "
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   754
        self genUUID:'www.example.org' inNameSpace:'DNS'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   755
        self genUUID:'http://www.exept.de' inNameSpace:'URL'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   756
        self genUUID:'1.2.3.4.5' inNameSpace:'OID'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   757
        self genUUID:(OSI::DERCoder encode:(OSI::ASN1_OID newID:#(1 2 3 4 5))) 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   758
             inNameSpace:'OID'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   759
        self genUUID:'c=de, o=eXept Software AG, cn=Development' 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   760
             inNameSpace:'X500'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   761
        self genUUID:(OSI::DERCoder encode:(OSI::DistinguishedName fromString:'c=de, o=eXept Software AG, cn=Development') asAsn1Value) 
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   762
             inNameSpace:'X500'.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   763
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
2426
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   766
!UUID methodsFor:'hashing'!
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   767
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   768
hash
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   769
   "Generate a 30 bit hash value.
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   770
    For Timestamp-UUIDs:
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   771
        Bytes 1,2,3,4 are the least significant bits of the timestamp,
2428
b283e32a8db5 changed: #hash
Stefan Vogel <sv@exept.de>
parents: 2426
diff changeset
   772
        Bytes 13,14,15,16 are the least significant bytes of the mac address - 
2426
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   773
            but considering these bytes does not generate a better hash to
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   774
            justify the additional computations.
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   775
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   776
    For random UUIDs, every byte is random anyway."
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   777
2428
b283e32a8db5 changed: #hash
Stefan Vogel <sv@exept.de>
parents: 2426
diff changeset
   778
    ^ (self computeXorHashFrom:1 to:4)
b283e32a8db5 changed: #hash
Stefan Vogel <sv@exept.de>
parents: 2426
diff changeset
   779
"/        bitXor:(self computeXorHashFrom:13 to:16)
2426
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   780
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   781
    "
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   782
        |allHashes|
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   783
        allHashes := UUID allInstances collect:[:each| each hash].
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   784
        (allHashes asSet size / allHashes size) asFloat
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   785
    "
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   786
! !
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   787
3121
ca7d3132c33f class: UUID
Stefan Vogel <sv@exept.de>
parents: 2978
diff changeset
   788
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
!UUID methodsFor:'printing'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
2495
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   791
displayOn:aGCOrStream
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   792
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   793
    "/ ST/X (and some old ST80's) mean: draw-yourself on a GC.
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   794
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   795
    aGCOrStream isStream ifTrue:[
2495
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   796
        self printOn:aGCOrStream.
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   797
        ^ self.
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   798
    ].
721d3888cbab Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 2433
diff changeset
   799
2977
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   800
    ^ super displayOn:aGCOrStream.
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   801
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   802
    "
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   803
        self genUUID displayOn:Transcript
afc4d10019c7 class: UUID
Stefan Vogel <sv@exept.de>
parents: 2954
diff changeset
   804
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
printOn:aStream
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   808
    |d tmpStream|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   810
    tmpStream := '' writeStream.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   812
    1 to:4 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   813
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   814
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   815
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   816
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   817
    5 to:6 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   818
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   819
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   820
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   821
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   822
    7 to:8 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   823
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   824
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   825
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   826
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   827
    9 to:10 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   828
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   829
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   830
    ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   831
    tmpStream nextPut:$-.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   832
    11 to:16 do:[:idx|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   833
        d := self at:idx.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   834
        d printOn:tmpStream base:16 size:2 fill:$0.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   837
    aStream nextPutAll:(tmpStream contents asLowercase).
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   838
2741
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   839
    "
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   840
     UUID genUUID printString 
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   841
    "
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   842
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   843
"/    d := self unsignedLongAt:1 bigEndian:true.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   844
"/    d printOn:tmpStream base:16 size:8 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   845
"/    tmpStream nextPut:$-.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   846
"/
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   847
"/    d := self unsignedShortAt:1+4 bigEndian:true.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   848
"/    d printOn:tmpStream base:16 size:4 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   849
"/    tmpStream nextPut:$-.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   850
"/
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   851
"/    d := self unsignedShortAt:1+4+2 bigEndian:true.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   852
"/    d printOn:tmpStream base:16 size:4 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   853
"/    tmpStream nextPut:$-.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   854
"/
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   855
"/    d := self at:1+4+2+2.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   856
"/    d printOn:tmpStream base:16 size:2 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   857
"/    d := self at:1+4+2+2+1.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   858
"/    d printOn:tmpStream base:16 size:2 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   859
"/    tmpStream nextPut:$-.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   860
"/
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   861
"/    11 to:16 do:[:idx|
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   862
"/        d := self at:idx.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   863
"/        d printOn:tmpStream base:16 size:2 fill:$0.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   864
"/    ].
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   865
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   866
1898
8041791c02c3 comments
Claus Gittinger <cg@exept.de>
parents: 1647
diff changeset
   867
    "Modified: / 10-10-2007 / 23:19:03 / cg"
2069
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   868
!
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   869
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   870
storeOn:aStream
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   871
    aStream 
2741
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   872
        nextPut:$(; 
2069
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   873
        nextPutAll:self class name; 
2741
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   874
        nextPutAll:' fromString:'''.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   875
    self printOn:aStream.
00d17c900df5 comment/format in: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2739
diff changeset
   876
    aStream nextPutAll:''')'.
2069
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   877
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   878
    "
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   879
     Object readFrom:(UUID genUUID storeString) 
e84a7576e3ee storeString
sr
parents: 2021
diff changeset
   880
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
2755
a3017684fcd3 added: #isUUID
Stefan Vogel <sv@exept.de>
parents: 2741
diff changeset
   883
!UUID methodsFor:'testing'!
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   884
3122
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   885
isRandomUUID
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   886
    ^ self version == 4
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   887
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   888
    "
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   889
      self genRandomUUID isRandomUUID
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   890
    "
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   891
!
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   892
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   893
isTimestampUUID
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   894
    ^ self version == 1
3122
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   895
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   896
    "
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   897
      self genTimestampUUID isTimestampUUID
9d0a142eee9f class: UUID
Stefan Vogel <sv@exept.de>
parents: 3121
diff changeset
   898
    "
2755
a3017684fcd3 added: #isUUID
Stefan Vogel <sv@exept.de>
parents: 2741
diff changeset
   899
!
a3017684fcd3 added: #isUUID
Stefan Vogel <sv@exept.de>
parents: 2741
diff changeset
   900
a3017684fcd3 added: #isUUID
Stefan Vogel <sv@exept.de>
parents: 2741
diff changeset
   901
isUUID
a3017684fcd3 added: #isUUID
Stefan Vogel <sv@exept.de>
parents: 2741
diff changeset
   902
    ^ true
2738
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   903
! !
Stefan Vogel <sv@exept.de>
parents: 2701
diff changeset
   904
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
version
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
   908
    ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.48 2015-04-24 12:18:00 stefan Exp $'
2426
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   909
!
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   910
5348d3922323 added: #hash
Stefan Vogel <sv@exept.de>
parents: 2170
diff changeset
   911
version_CVS
3542
b00b42c1378d class: UUID
Stefan Vogel <sv@exept.de>
parents: 3122
diff changeset
   912
    ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.48 2015-04-24 12:18:00 stefan Exp $'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
! !
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   914
2950
bf0c61112aa1 class: UUID
Claus Gittinger <cg@exept.de>
parents: 2756
diff changeset
   915
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   916
UUID initialize!