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