-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrugal-uuid-v8.lisp
40 lines (33 loc) · 1.24 KB
/
frugal-uuid-v8.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;;;; frugal-uuid-v8.lisp
(in-package #:frugal-uuid)
(declaim (ftype (function ((unsigned-byte 48)
(unsigned-byte 12)
(unsigned-byte 62))
(values uuid &optional))
make-v8))
(defun make-v8 (a b c)
(let ((time-high #xFFFF)
(clock-seq-high #xFF))
(setf (ldb (byte 4 12) time-high) #x8 ; Set version to 8
(ldb (byte 12 0) time-high) b
(ldb (byte 2 6) clock-seq-high) #b10
(ldb (byte 6 0) clock-seq-high) (ldb (byte 6 56) c))
(make-instance 'uuid
:time-low (ldb (byte 32 16) a)
:time-mid (ldb (byte 16 0) a)
:time-hi-and-version time-high
:clock-seq-hi-and-res clock-seq-high
:clock-seq-low (ldb (byte 8 48) c)
:node (ldb (byte 48 0) c))))
(declaim (inline make-v8-integer))
(defun make-v8-integer (a b c)
(to-integer (make-v8 a b c)))
(declaim (inline make-v8-string))
(defun make-v8-string (a b c)
(to-string (make-v8 a b c)))
(declaim (inline make-v8-octets))
(defun make-v8-octets (a b c)
(to-octets (make-v8 a b c)))
(declaim (inline make-v8-sym))
(defun make-v8-sym (a b c)
(to-sym (make-v8 a b c)))