Use Read-time evaluation to make code more readable
This commit is contained in:
parent
f8cb331753
commit
d472261c4f
1 changed files with 9 additions and 9 deletions
18
osc.lisp
18
osc.lisp
|
@ -370,10 +370,10 @@ with the current time use (encode-timetag :time)."
|
||||||
(list docstring))
|
(list docstring))
|
||||||
(let ((,buf (make-array ,num-of-octets :element-type '(unsigned-byte 8))))
|
(let ((,buf (make-array ,num-of-octets :element-type '(unsigned-byte 8))))
|
||||||
,@(loop
|
,@(loop
|
||||||
for n below num-of-octets
|
for n below num-of-octets
|
||||||
collect `(setf (aref ,buf ,n)
|
collect `(setf (aref ,buf ,n)
|
||||||
(ldb (byte 8 (* 8 (- (1- ,num-of-octets) ,n)))
|
(ldb (byte 8 (* 8 (- (1- ,num-of-octets) ,n)))
|
||||||
,int)))
|
,int)))
|
||||||
,buf))))
|
,buf))))
|
||||||
|
|
||||||
(defint-encoder 4 "Convert an integer into a sequence of 4 bytes in network byte order (32 bit).")
|
(defint-encoder 4 "Convert an integer into a sequence of 4 bytes in network byte order (32 bit).")
|
||||||
|
@ -382,15 +382,15 @@ with the current time use (encode-timetag :time)."
|
||||||
(defun decode-int32 (s)
|
(defun decode-int32 (s)
|
||||||
"4 byte -> 32 bit int -> two's complement (in network byte order)"
|
"4 byte -> 32 bit int -> two's complement (in network byte order)"
|
||||||
(let ((i (decode-uint32 s)))
|
(let ((i (decode-uint32 s)))
|
||||||
(if (>= i #x7fffffff)
|
(if (>= i #.(1- (expt 2 31)))
|
||||||
(- 0 (- #x100000000 i))
|
(- (- #.(expt 2 32) i))
|
||||||
i)))
|
i)))
|
||||||
|
|
||||||
(defun decode-int64 (s)
|
(defun decode-int64 (s)
|
||||||
"8 byte -> 64 bit int -> two's complement (in network byte order)"
|
"8 byte -> 64 bit int -> two's complement (in network byte order)"
|
||||||
(let ((i (decode-uint64 s)))
|
(let ((i (decode-uint64 s)))
|
||||||
(if (>= i #x7fffffffffffffff)
|
(if (>= i #.(1- (expt 2 63)))
|
||||||
(- 0 (- #x10000000000000000 i))
|
(- (- #.(expt 2 64) i))
|
||||||
i)))
|
i)))
|
||||||
|
|
||||||
;; osc-strings are unsigned bytes, padded to a 4 byte boundary
|
;; osc-strings are unsigned bytes, padded to a 4 byte boundary
|
||||||
|
|
Loading…
Reference in a new issue