(defmacro read-var-integer (vec index)
(once-only ((val `(aref ,vec ,index)))
`(cond ((<= ,val 253)
(defmacro read-var-integer (vec index)
(once-only ((val `(aref ,vec ,index)))
`(cond ((<= ,val 253)
- (incf ,index)
- ,val)
- ((= ,val 254)
- (prog1
- (logior (aref ,vec (+ ,index 1))
- (ash (aref ,vec (+ ,index 2)) 8))
- (incf ,index 3)))
- (t
- (prog1
- (logior (aref ,vec (+ ,index 1))
- (ash (aref ,vec (+ ,index 2)) 8)
- (ash (aref ,vec (+ ,index 3)) 16)
- (ash (aref ,vec (+ ,index 4)) 24))
- (incf ,index 5))))))
+ (incf ,index)
+ ,val)
+ ((= ,val 254)
+ (prog1
+ (logior (aref ,vec (+ ,index 1))
+ (ash (aref ,vec (+ ,index 2)) 8))
+ (incf ,index 3)))
+ (t
+ (prog1
+ (logior (aref ,vec (+ ,index 1))
+ (ash (aref ,vec (+ ,index 2)) 8)
+ (ash (aref ,vec (+ ,index 3)) 16)
+ (ash (aref ,vec (+ ,index 4)) 24))
+ (incf ,index 5))))))
-;;; Takes an adjustable vector Vec with a fill pointer and pushes the
-;;; variable length representation of Int on the end.
+;;; Take an adjustable vector VEC with a fill pointer and push the
+;;; variable length representation of INT on the end.
- (vector-push-extend int vec))
- (t
- (let ((32-p (> int #xFFFF)))
- (vector-push-extend (if 32-p 255 254) vec)
- (vector-push-extend (ldb (byte 8 0) int) vec)
- (vector-push-extend (ldb (byte 8 8) int) vec)
- (when 32-p
- (vector-push-extend (ldb (byte 8 16) int) vec)
- (vector-push-extend (ldb (byte 8 24) int) vec)))))
+ (vector-push-extend int vec))
+ (t
+ (let ((32-p (> int #xFFFF)))
+ (vector-push-extend (if 32-p 255 254) vec)
+ (vector-push-extend (ldb (byte 8 0) int) vec)
+ (vector-push-extend (ldb (byte 8 8) int) vec)
+ (when 32-p
+ (vector-push-extend (ldb (byte 8 16) int) vec)
+ (vector-push-extend (ldb (byte 8 24) int) vec)))))
(defmacro read-var-string (vec index)
(once-only ((len `(read-var-integer ,vec ,index)))
(once-only ((res `(make-string ,len)))
`(progn
(defmacro read-var-string (vec index)
(once-only ((len `(read-var-integer ,vec ,index)))
(once-only ((res `(make-string ,len)))
`(progn
- (%primitive byte-blt ,vec ,index ,res 0 ,len)
- (incf ,index ,len)
- ,res))))
+ (loop for i from 0 below ,len
+ do (setf (aref ,res i)
+ (code-char (read-var-integer ,vec ,index))))
+ ,res))))
-;;; Write String into Vec (adjustable, fill-pointer) represented as the
-;;; length (in a var-length integer) followed by the codes of the characters.
+;;; Write STRING into VEC (adjustable, with fill-pointer) represented
+;;; as the length (in a var-length integer) followed by the codes of
+;;; the characters.
(defun write-var-string (string vec)
(declare (simple-string string))
(let ((len (length string)))
(write-var-integer len vec)
(dotimes (i len)
(defun write-var-string (string vec)
(declare (simple-string string))
(let ((len (length string)))
(write-var-integer len vec)
(dotimes (i len)
-;;; Read the specified number of Bytes out of Vec at Index and convert them
-;;; to a bit-vector. Index is incremented.
+;;; Read the specified number of BYTES out of VEC at INDEX and convert
+;;; them to a BIT-VECTOR. INDEX is incremented.
(defmacro read-packed-bit-vector (bytes vec index)
(once-only ((n-bytes bytes))
(once-only ((n-res `(make-array (* ,n-bytes 8) :element-type 'bit)))
`(progn
(defmacro read-packed-bit-vector (bytes vec index)
(once-only ((n-bytes bytes))
(once-only ((n-res `(make-array (* ,n-bytes 8) :element-type 'bit)))
`(progn
- (%primitive byte-blt ,vec ,index ,n-res 0 ,n-bytes)
- (incf ,index ,n-bytes)
- ,n-res))))
+ (%byte-blt ,vec ,index ,n-res 0 ,n-bytes)
+ (incf ,index ,n-bytes)
+ ,n-res))))