Avoid C-isms #5
1 changed files with 15 additions and 18 deletions
33
osc.lisp
33
osc.lisp
|
@ -291,25 +291,22 @@
|
||||||
(ldb (byte 16 0) (decode-int32 s)))
|
(ldb (byte 16 0) (decode-int32 s)))
|
||||||
#-(or sbcl cmucl openmcl allegro) (error "cant decode floats using this implementation"))
|
#-(or sbcl cmucl openmcl allegro) (error "cant decode floats using this implementation"))
|
||||||
|
|
||||||
(defun decode-uint32 (s)
|
(defmacro defint-decoder (num-of-octets &optional docstring)
|
||||||
"4 byte -> 32 bit unsigned int"
|
(let ((decoder-name (intern (format nil "~:@(decode-uint~)~D" (* 8 num-of-octets))))
|
||||||
(let ((i (+ (ash (elt s 0) 24)
|
(seq (gensym))
|
||||||
(ash (elt s 1) 16)
|
(int (gensym)))
|
||||||
(ash (elt s 2) 8)
|
`(defun ,decoder-name (,seq)
|
||||||
(elt s 3))))
|
,@(when docstring
|
||||||
i))
|
(list docstring))
|
||||||
|
(let* ((,int 0)
|
||||||
|
,@(loop
|
||||||
|
for n below num-of-octets
|
||||||
|
collect `(,int (dpb (aref ,seq ,n) (byte 8 (* 8 (- (1- ,num-of-octets) ,n)))
|
||||||
|
,int))))
|
||||||
|
int))))
|
||||||
|
|
||||||
(defun decode-uint64 (s)
|
(defint-decoder 4 "4 byte -> 32 bit unsigned int")
|
||||||
"8 byte -> 64 bit unsigned int"
|
(defint-decoder 8 "8 byte -> 64 bit unsigned int")
|
||||||
(let ((i (+ (ash (elt s 0) 56)
|
|
||||||
(ash (elt s 1) 48)
|
|
||||||
(ash (elt s 2) 40)
|
|
||||||
(ash (elt s 3) 32)
|
|
||||||
(ash (elt s 4) 24)
|
|
||||||
(ash (elt s 5) 16)
|
|
||||||
(ash (elt s 6) 8)
|
|
||||||
(elt s 7))))
|
|
||||||
i))
|
|
||||||
|
|
||||||
(defmacro defint-encoder (num-of-octets &optional docstring)
|
(defmacro defint-encoder (num-of-octets &optional docstring)
|
||||||
(let ((enc-name (intern (format nil "~:@(encode-int~)~D" (* 8 num-of-octets))))
|
(let ((enc-name (intern (format nil "~:@(encode-int~)~D" (* 8 num-of-octets))))
|
||||||
|
|
Loading…
Reference in a new issue