author | Claus Gittinger <cg@exept.de> |
Tue, 25 Jun 2019 14:28:51 +0200 | |
changeset 5050 | 44fa8672d102 |
parent 4634 | 134765d28a26 |
child 5076 | 185b8f374d44 |
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:[ |
|
4505 | 72 |
Lock := RecursionLock 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 |
|
4298 | 432 |
" |
1647 | 433 |
(Timestamp epoch asDate subtractDate:(Date day:15 month:10 year:1582)) |
434 |
* (24 * 60 * 60) |
|
4298 | 435 |
* 1000 |
436 |
* 1000 |
|
437 |
* 10 |
|
438 |
" |
|
1613 | 439 |
|
4496 | 440 |
^ (OperatingSystem getMicrosecondTime + 12219292800000000) * 10 |
441 |
"/ ^ (Timestamp now getMilliseconds + 12219292800000) * 10000 . |
|
4298 | 442 |
|
4496 | 443 |
"Modified: / 05-08-2017 / 10:17:57 / cg" |
1213 | 444 |
! |
445 |
||
446 |
getValidMACAddress |
|
3641 | 447 |
"return the first valid MAC address (i.e. having at least 6 bytes with the first six bytes ~~ 0). |
448 |
As a side effect, initialize anything needed for timestamp UUIDs." |
|
1213 | 449 |
|
450 |
CachedMACAddress isNil ifTrue:[ |
|
4634 | 451 |
Lock isNil ifTrue:[ |
452 |
"/ is there an early access possible befor initialization? |
|
453 |
self initialize. |
|
454 |
]. |
|
2978 | 455 |
CachedMACAddress := false. "negative caching: remember the fact, that there is no MAC address" |
3641 | 456 |
PrimitiveFailure catch:[ |
2977 | 457 |
CachedMACAddress := OperatingSystem getNetworkMACAddresses |
2978 | 458 |
detect:[:macAddress | macAddress size >= 6 |
459 |
and:[(macAddress startsWith:#[0 0 0 0 0 0]) not]] |
|
2977 | 460 |
ifNone:false. |
3641 | 461 |
]. |
462 |
"try again when restarted from a snapshot" |
|
463 |
ObjectMemory addDependent:self. |
|
1213 | 464 |
]. |
465 |
||
466 |
^ CachedMACAddress |
|
467 |
||
468 |
" |
|
469 |
CachedMACAddress := nil. |
|
470 |
self getValidMACAddress |
|
471 |
" |
|
1491
512b21b45a9e
noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents:
1467
diff
changeset
|
472 |
|
512b21b45a9e
noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents:
1467
diff
changeset
|
473 |
"Modified: / 17-11-2004 / 01:45:53 / cg" |
4634 | 474 |
"Modified: / 19-04-2018 / 10:13:18 / stefan" |
1213 | 475 |
! ! |
476 |
||
3807 | 477 |
|
1213 | 478 |
!UUID methodsFor:'accessing'! |
479 |
||
1602 | 480 |
clockSeqHiAndReserved |
481 |
^ self at:9 |
|
482 |
! |
|
1213 | 483 |
|
1602 | 484 |
clockSeqLow |
485 |
^ self at:10 |
|
1213 | 486 |
! |
487 |
||
488 |
node |
|
2738 | 489 |
"answer the node (ethernet) address of this uuid" |
490 |
||
3122 | 491 |
self isTimestampUUID ifFalse:[ |
492 |
ConversionError raiseWith:self errorString:' - trying to get node address from random UUID'. |
|
493 |
]. |
|
2738 | 494 |
^ (ByteArray new:6) replaceFrom:1 to:6 with:self startingAt:11. |
495 |
||
496 |
" |
|
497 |
(self allInstances |
|
498 |
select:[:e| e isTimestampUUID] |
|
499 |
thenCollect:[:e| e node]) asBag |
|
500 |
" |
|
1213 | 501 |
! |
502 |
||
503 |
timeHighAndVersion |
|
3769 | 504 |
^ self unsignedInt16At:7 MSB:true |
1213 | 505 |
! |
506 |
||
507 |
timeLow |
|
3769 | 508 |
^ self unsignedInt32At:1 MSB:true |
1213 | 509 |
! |
510 |
||
511 |
timeMid |
|
3769 | 512 |
^ self unsignedInt16At:5 MSB:true |
2738 | 513 |
! |
514 |
||
515 |
timestamp |
|
516 |
"Get the UTC timestamp, when the UUID has been created. |
|
517 |
This is only valid for timestampUUIDs" |
|
518 |
||
519 |
|low med high dtssUtcTime| |
|
520 |
||
3121 | 521 |
self isTimestampUUID ifFalse:[ |
522 |
ConversionError raiseWith:self errorString:' - trying to get timestamp from random UUID'. |
|
523 |
]. |
|
524 |
||
3769 | 525 |
low := self unsignedInt32At:1 MSB:true. |
526 |
med := self unsignedInt16At:5 MSB:true. |
|
527 |
high := (self unsignedInt16At:7 MSB:true) bitAnd:16rFFF. |
|
2738 | 528 |
|
529 |
dtssUtcTime := low + ((med + (high bitShift:16)) bitShift:32). |
|
530 |
||
3850 | 531 |
^ UtcTimestamp utcMillisecondsSince1970:(dtssUtcTime//10000) - 12219292800000. |
2738 | 532 |
|
533 |
" |
|
534 |
self genTimestampUUID timestamp |
|
3121 | 535 |
self genRandomUUID timestamp |
2738 | 536 |
|
537 |
(self allInstances asSet asArray select:[:e| e isTimestampUUID] |
|
538 |
thenCollect:[:e| e timestamp]) sort |
|
539 |
" |
|
540 |
! |
|
541 |
||
542 |
version |
|
543 |
"the version number of the uuid" |
|
544 |
||
545 |
^ ((self at:7) bitAnd:16rF0) bitShift:-4. |
|
546 |
||
547 |
" |
|
548 |
self genTimestampUUID version |
|
549 |
self genRandomUUID version |
|
550 |
" |
|
1213 | 551 |
! ! |
552 |
||
1188 | 553 |
!UUID methodsFor:'converting'! |
554 |
||
1382 | 555 |
asBytes |
1602 | 556 |
"convert this UUID to a ByteArray in network byte order (MSB-first)" |
1382 | 557 |
|
1602 | 558 |
|bytes| |
1188 | 559 |
|
560 |
bytes := ByteArray new:16. |
|
561 |
bytes replaceFrom:1 to:16 with:self. |
|
1602 | 562 |
^ bytes |
1188 | 563 |
|
1602 | 564 |
" |
565 |
|bytes| |
|
566 |
||
567 |
bytes := #[16r01 16r02 16r03 16r04 |
|
568 |
16r05 16r06 16r07 16r08 |
|
569 |
16r09 16r10 16r11 16r12 |
|
570 |
16r13 16r14 16r15 16r16]. |
|
571 |
(UUID fromBytes:bytes) asBytes ~= bytes ifTrue:[self halt] |
|
572 |
" |
|
573 |
! |
|
1188 | 574 |
|
1602 | 575 |
asBytesMSB:msb |
576 |
"convert this UUID to a ByteArray. |
|
1898 | 577 |
If msb == false, it is converted into LSB-first byte ordering" |
1602 | 578 |
|
579 |
|bytes| |
|
580 |
||
581 |
bytes := self asBytes. |
|
582 |
||
583 |
msb ifFalse:[ |
|
584 |
self class adjustByteOrder:bytes. |
|
1188 | 585 |
]. |
586 |
^ bytes |
|
1898 | 587 |
|
588 |
"Modified: / 10-10-2007 / 22:51:09 / cg" |
|
1602 | 589 |
! |
590 |
||
591 |
asNativeBytes |
|
592 |
"convert this uuid to a ByteArray in host byte order. |
|
593 |
Use this only to pass the UUID to the OS (Windows)" |
|
594 |
||
595 |
|bytes| |
|
596 |
||
597 |
bytes := self asBytes. |
|
3542 | 598 |
IsBigEndian ifFalse:[ |
1602 | 599 |
self class adjustByteOrder:bytes. |
600 |
]. |
|
601 |
^ bytes. |
|
2021 | 602 |
! |
603 |
||
3585 | 604 |
asString |
605 |
^ self printString |
|
606 |
||
607 |
" |
|
608 |
self genUUID asString |
|
609 |
" |
|
610 |
! |
|
611 |
||
2170 | 612 |
asUUID |
613 |
^ self |
|
614 |
! |
|
615 |
||
2021 | 616 |
literalArrayEncoding |
617 |
^ Array |
|
618 |
with:(self class name) |
|
619 |
with:(self printString). |
|
1188 | 620 |
! ! |
621 |
||
2132 | 622 |
!UUID methodsFor:'copying'! |
623 |
||
624 |
deepCopy |
|
2738 | 625 |
"I am never changed, after I have been created. |
626 |
So there is no need to make a copy" |
|
627 |
||
2132 | 628 |
^ self |
629 |
! |
|
630 |
||
631 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2738 | 632 |
"I am never changed, after I have been created. |
633 |
So there is no need to make a copy" |
|
634 |
||
2132 | 635 |
^ self |
636 |
! |
|
637 |
||
638 |
shallowCopy |
|
2738 | 639 |
"I am never changed, after I have been created. |
640 |
So there is no need to make a copy" |
|
641 |
||
2132 | 642 |
^ self |
643 |
! |
|
644 |
||
645 |
simpleDeepCopy |
|
2738 | 646 |
"I am never changed, after I have been created. |
647 |
So there is no need to make a copy" |
|
648 |
||
2132 | 649 |
^ self |
650 |
! ! |
|
651 |
||
1188 | 652 |
!UUID methodsFor:'generating uuids'! |
653 |
||
3641 | 654 |
genTimestampUUID |
655 |
"generate a timestamp (and mac-address) based uuid" |
|
656 |
||
657 |
|macBytes utcTime seqNr| |
|
1608
e1cf5d2b6f2f
Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents:
1602
diff
changeset
|
658 |
|
2738 | 659 |
(self at:7) ~~ 0 ifTrue:[ |
660 |
"once created, an UUID is immutable" |
|
661 |
self noModificationError. |
|
662 |
]. |
|
663 |
||
3641 | 664 |
macBytes := CachedMACAddress. |
665 |
macBytes isNil ifTrue:[ |
|
2701 | 666 |
macBytes := self class getValidMACAddress. |
3641 | 667 |
macBytes size < 6 ifTrue:[ |
668 |
self error:'no mac address - cannot generate UUID'. |
|
669 |
]. |
|
2738 | 670 |
]. |
671 |
||
1612 | 672 |
"use 60 bit counter of 100ns ticks since 00:00:00 15.oct 1582 (sigh)" |
1610 | 673 |
utcTime := self class getDtssUtcTime. |
674 |
||
1213 | 675 |
Lock critical:[ |
1467
a394ade68816
Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents:
1447
diff
changeset
|
676 |
SequenceNumber isNil ifTrue:[ |
1608
e1cf5d2b6f2f
Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents:
1602
diff
changeset
|
677 |
SequenceNumber := RandomGenerator new nextIntegerBetween:0 and:16383. |
1467
a394ade68816
Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents:
1447
diff
changeset
|
678 |
]. |
1612 | 679 |
utcTime > (LastTime+Increment) ifTrue:[ |
1213 | 680 |
Increment := 0. |
681 |
] ifFalse:[ |
|
682 |
LastTime = utcTime ifTrue:[ |
|
683 |
"clock didn't advance since last call. Simply add a tick" |
|
684 |
Increment := Increment + 1. |
|
685 |
] ifFalse:[ |
|
1467
a394ade68816
Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents:
1447
diff
changeset
|
686 |
"clock went backwards - increment SequenceNumber" |
1213 | 687 |
Increment := 0. |
1214 | 688 |
SequenceNumber := SequenceNumber + 1. |
689 |
SequenceNumber >= 16384 ifTrue:[SequenceNumber := 0]. |
|
1213 | 690 |
]. |
1188 | 691 |
]. |
1214 | 692 |
|
1213 | 693 |
LastTime := utcTime. |
694 |
utcTime := utcTime + Increment. |
|
1610 | 695 |
seqNr := SequenceNumber. |
1188 | 696 |
]. |
697 |
||
1612 | 698 |
|
699 |
"time low: long" |
|
3769 | 700 |
self unsignedInt32At:1 put:(utcTime bitAnd:16rFFFFFFFF) MSB:true. |
1612 | 701 |
|
702 |
"time med: short" |
|
703 |
utcTime := utcTime bitShift:-32. |
|
3769 | 704 |
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
|
705 |
|
1612 | 706 |
"time high and version: short |
707 |
multiplex the 4 bit version number in highest 4 bits (version 1 -> time based version)" |
|
3769 | 708 |
self unsignedInt16At:7 put:((utcTime bitShift:-16) bitOr:16r1000) MSB:true. |
1188 | 709 |
|
1612 | 710 |
"2 sequence bytes + reserved bits (this is not a short!!)" |
711 |
self at:9 put:(((seqNr bitShift:-8) bitAnd:16r3F) bitOr:16r80). |
|
712 |
self at:10 put:(seqNr bitAnd:16rFF). |
|
1213 | 713 |
|
714 |
"48 bits of MAC-Address" |
|
715 |
self replaceFrom:11 to:16 with:macBytes startingAt:1. |
|
1188 | 716 |
|
717 |
" |
|
2977 | 718 |
self genTimestampUUID |
2738 | 719 |
self genTimestampUUID genTimestampUUID |
1213 | 720 |
" |
1188 | 721 |
|
1213 | 722 |
" |
723 |
1 to: 100 do:[ : el | |
|
724 |
Transcript show:el. |
|
725 |
Transcript show:': '. |
|
4496 | 726 |
Transcript showCR:(UUID genTimestampUUID). |
1213 | 727 |
]. |
728 |
" |
|
2701 | 729 |
|
730 |
"Modified: / 26-12-2011 / 13:41:23 / cg" |
|
4496 | 731 |
"Modified (comment): / 05-08-2017 / 10:08:44 / cg" |
1608
e1cf5d2b6f2f
Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents:
1602
diff
changeset
|
732 |
! |
e1cf5d2b6f2f
Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents:
1602
diff
changeset
|
733 |
|
3641 | 734 |
genUUID:nameStringOrBytes inNameSpace:namespaceStringOrUUID |
2977 | 735 |
"generate a namespace UUID (Version 5, hashed by SHA-1). |
736 |
See RFC4122." |
|
737 |
||
3641 | 738 |
|sha1 namespaceUUID| |
2977 | 739 |
|
740 |
(self at:7) ~~ 0 ifTrue:[ |
|
741 |
"once created, an UUID is immutable" |
|
742 |
self noModificationError. |
|
743 |
]. |
|
744 |
||
3641 | 745 |
namespaceStringOrUUID isUUID ifTrue:[ |
746 |
namespaceUUID := namespaceStringOrUUID. |
|
747 |
] ifFalse:[ |
|
748 |
"this throws an exception, if namespaceStringOrUUID is unknown" |
|
749 |
namespaceUUID := self class nameSpaceToUuidBytes at:namespaceStringOrUUID. |
|
750 |
]. |
|
751 |
||
2977 | 752 |
sha1 := SHA1Stream new. |
753 |
sha1 |
|
3641 | 754 |
nextPutAll:namespaceUUID; |
2977 | 755 |
nextPutAll:nameStringOrBytes. |
756 |
||
757 |
self replaceFrom:1 to:16 with:(sha1 hashValue). |
|
758 |
"multiplex the 4 bit version number (Version 5 -> SHA1 Namspace UUID) in high bits of byte 7" |
|
759 |
self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r50). |
|
760 |
self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80). |
|
761 |
||
762 |
" |
|
763 |
self genUUID:'www.example.org' inNameSpace:'DNS'. |
|
764 |
self genUUID:'http://www.exept.de' inNameSpace:'URL'. |
|
3641 | 765 |
self genUUID:'some text' inNameSpace:(UUID fromString:'885f7d80-7d60-11e5-a133-101f74535bd0'). |
2977 | 766 |
self genUUID:'1.2.3.4.5' inNameSpace:'OID'. |
767 |
self genUUID:(OSI::DERCoder encode:(OSI::ASN1_OID newID:#(1 2 3 4 5))) |
|
768 |
inNameSpace:'OID'. |
|
769 |
self genUUID:'c=de, o=eXept Software AG, cn=Development' |
|
770 |
inNameSpace:'X500'. |
|
771 |
self genUUID:(OSI::DERCoder encode:(OSI::DistinguishedName fromString:'c=de, o=eXept Software AG, cn=Development') asAsn1Value) |
|
772 |
inNameSpace:'X500'. |
|
773 |
" |
|
3641 | 774 |
! |
775 |
||
776 |
setRandomUUIDFromBytes:sixteenBytes |
|
777 |
"answer a randomly generated uuid as defined in RFC4122 section 4.4" |
|
778 |
||
779 |
(self at:7) ~~ 0 ifTrue:[ |
|
780 |
"once created, an UUID is immutable" |
|
781 |
self noModificationError. |
|
782 |
]. |
|
783 |
||
784 |
self replaceFrom:1 to:16 with:sixteenBytes. |
|
785 |
"multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7" |
|
786 |
self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40). |
|
787 |
self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80). |
|
1188 | 788 |
! ! |
789 |
||
2426 | 790 |
!UUID methodsFor:'hashing'! |
791 |
||
792 |
hash |
|
793 |
"Generate a 30 bit hash value. |
|
794 |
For Timestamp-UUIDs: |
|
795 |
Bytes 1,2,3,4 are the least significant bits of the timestamp, |
|
2428 | 796 |
Bytes 13,14,15,16 are the least significant bytes of the mac address - |
2426 | 797 |
but considering these bytes does not generate a better hash to |
798 |
justify the additional computations. |
|
799 |
||
800 |
For random UUIDs, every byte is random anyway." |
|
801 |
||
2428 | 802 |
^ (self computeXorHashFrom:1 to:4) |
803 |
"/ bitXor:(self computeXorHashFrom:13 to:16) |
|
2426 | 804 |
|
805 |
" |
|
806 |
|allHashes| |
|
807 |
allHashes := UUID allInstances collect:[:each| each hash]. |
|
808 |
(allHashes asSet size / allHashes size) asFloat |
|
809 |
" |
|
810 |
! ! |
|
811 |
||
3121 | 812 |
|
4354 | 813 |
!UUID methodsFor:'printing & storing'! |
1188 | 814 |
|
2495
721d3888cbab
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2433
diff
changeset
|
815 |
displayOn:aGCOrStream |
721d3888cbab
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2433
diff
changeset
|
816 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4354 | 817 |
"/ old ST80 means: draw-yourself on a GC. |
818 |
aGCOrStream isStream ifFalse:[ |
|
819 |
^ super displayOn:aGCOrStream. |
|
2495
721d3888cbab
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2433
diff
changeset
|
820 |
]. |
721d3888cbab
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2433
diff
changeset
|
821 |
|
4354 | 822 |
self printOn:aGCOrStream. |
2977 | 823 |
|
824 |
" |
|
825 |
self genUUID displayOn:Transcript |
|
826 |
" |
|
4354 | 827 |
|
828 |
"Modified: / 22-02-2017 / 16:58:50 / cg" |
|
1188 | 829 |
! |
830 |
||
831 |
printOn:aStream |
|
1612 | 832 |
1 to:4 do:[:idx| |
3999 | 833 |
(self basicAt:idx) printOn:aStream base:-16 size:2 fill:$0. |
1612 | 834 |
]. |
3999 | 835 |
aStream nextPut:$-. |
1612 | 836 |
5 to:6 do:[:idx| |
3999 | 837 |
(self basicAt:idx) printOn:aStream base:-16 size:2 fill:$0. |
1612 | 838 |
]. |
3999 | 839 |
aStream nextPut:$-. |
1612 | 840 |
7 to:8 do:[:idx| |
3999 | 841 |
(self basicAt:idx) printOn:aStream base:-16 size:2 fill:$0. |
1612 | 842 |
]. |
3999 | 843 |
aStream nextPut:$-. |
844 |
9 to:10 do:[:idx| |
|
845 |
(self basicAt:idx) printOn:aStream base:-16 size:2 fill:$0. |
|
846 |
]. |
|
847 |
aStream nextPut:$-. |
|
1602 | 848 |
11 to:16 do:[:idx| |
3999 | 849 |
(self basicAt:idx) printOn:aStream base:-16 size:2 fill:$0. |
1188 | 850 |
]. |
851 |
||
2741 | 852 |
" |
853 |
UUID genUUID printString |
|
3585 | 854 |
UUID genUUID asString |
2741 | 855 |
" |
856 |
||
857 |
"/ d := self unsignedLongAt:1 bigEndian:true. |
|
858 |
"/ d printOn:tmpStream base:16 size:8 fill:$0. |
|
859 |
"/ tmpStream nextPut:$-. |
|
860 |
"/ |
|
861 |
"/ d := self unsignedShortAt:1+4 bigEndian:true. |
|
862 |
"/ d printOn:tmpStream base:16 size:4 fill:$0. |
|
863 |
"/ tmpStream nextPut:$-. |
|
864 |
"/ |
|
865 |
"/ d := self unsignedShortAt:1+4+2 bigEndian:true. |
|
866 |
"/ d printOn:tmpStream base:16 size:4 fill:$0. |
|
867 |
"/ tmpStream nextPut:$-. |
|
868 |
"/ |
|
869 |
"/ d := self at:1+4+2+2. |
|
870 |
"/ d printOn:tmpStream base:16 size:2 fill:$0. |
|
871 |
"/ d := self at:1+4+2+2+1. |
|
872 |
"/ d printOn:tmpStream base:16 size:2 fill:$0. |
|
873 |
"/ tmpStream nextPut:$-. |
|
874 |
"/ |
|
875 |
"/ 11 to:16 do:[:idx| |
|
876 |
"/ d := self at:idx. |
|
877 |
"/ d printOn:tmpStream base:16 size:2 fill:$0. |
|
878 |
"/ ]. |
|
879 |
||
880 |
||
1898 | 881 |
"Modified: / 10-10-2007 / 23:19:03 / cg" |
2069 | 882 |
! |
883 |
||
4623 | 884 |
printString |
885 |
"return a printed representation of the receiver for printing. |
|
886 |
Uses the basic print mechanism of the underlying technology." |
|
887 |
||
888 |
|s| |
|
889 |
||
890 |
"Speed: we know, that the printed representation of a UUID has exactly 36 chars" |
|
891 |
s := WriteStream on:(String new:36). |
|
892 |
self printOn:s. |
|
893 |
^ s contents. |
|
894 |
||
895 |
" |
|
896 |
UUID genUUID printString |
|
897 |
" |
|
898 |
||
899 |
"Created: / 20-03-2018 / 16:08:10 / stefan" |
|
900 |
! |
|
901 |
||
2069 | 902 |
storeOn:aStream |
903 |
aStream |
|
2741 | 904 |
nextPut:$(; |
2069 | 905 |
nextPutAll:self class name; |
2741 | 906 |
nextPutAll:' fromString:'''. |
907 |
self printOn:aStream. |
|
908 |
aStream nextPutAll:''')'. |
|
2069 | 909 |
|
910 |
" |
|
911 |
Object readFrom:(UUID genUUID storeString) |
|
912 |
" |
|
1188 | 913 |
! ! |
914 |
||
2755 | 915 |
!UUID methodsFor:'testing'! |
2738 | 916 |
|
3122 | 917 |
isRandomUUID |
918 |
^ self version == 4 |
|
919 |
||
920 |
" |
|
921 |
self genRandomUUID isRandomUUID |
|
922 |
" |
|
923 |
! |
|
924 |
||
2738 | 925 |
isTimestampUUID |
926 |
^ self version == 1 |
|
3122 | 927 |
|
928 |
" |
|
929 |
self genTimestampUUID isTimestampUUID |
|
930 |
" |
|
2755 | 931 |
! |
932 |
||
933 |
isUUID |
|
934 |
^ true |
|
2738 | 935 |
! ! |
936 |
||
1188 | 937 |
!UUID class methodsFor:'documentation'! |
938 |
||
939 |
version |
|
3585 | 940 |
^ '$Header$' |
2426 | 941 |
! |
942 |
||
943 |
version_CVS |
|
3585 | 944 |
^ '$Header$' |
1188 | 945 |
! ! |
1213 | 946 |
|
2950 | 947 |
|
1213 | 948 |
UUID initialize! |