1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- Foreign memory buffers.
6 (in-package :io.zeta-streams
)
10 (define-constant +bytes-per-iobuf
+ 4096)
12 (defun make-iobuf (&optional
(size +bytes-per-iobuf
+))
13 (let ((b (%make-iobuf
)))
14 (setf (iobuf-data b
) (make-array size
:element-type
'ub8
)
18 (defun iobuf-length (iobuf)
19 (declare (type iobuf iobuf
))
23 (defun iobuf-empty-p (iobuf)
24 (declare (type iobuf iobuf
))
28 (defun iobuf-full-p (iobuf)
29 (declare (type iobuf iobuf
))
33 (defun iobuf-end-space-length (iobuf)
34 (declare (type iobuf iobuf
))
38 (defun iobuf-reset (iobuf)
39 (declare (type iobuf iobuf
))
40 (setf (iobuf-start iobuf
) 0
45 ;;; UNSAFE functions which *DO NOT* check boundaries
46 ;;; that must be done by their callers
49 (defun bref (iobuf index
)
50 (declare (type iobuf iobuf
)
51 (type iobuf-index index
))
52 (aref (iobuf-data iobuf
) index
))
54 (defun (setf bref
) (octet iobuf index
)
55 (declare (type ub8 octet
)
57 (type iobuf-index index
))
58 (setf (aref (iobuf-data iobuf
) index
) octet
))
60 (defun iobuf-pop-octet (iobuf)
61 (declare (type iobuf iobuf
))
62 (let ((start (iobuf-start iobuf
)))
63 (prog1 (bref iobuf start
)
64 (incf (iobuf-start iobuf
)))))
66 (defun iobuf-push-octet (iobuf octet
)
67 (declare (type iobuf iobuf
)
68 (type (unsigned-byte 8) octet
))
69 (let ((end (iobuf-end iobuf
)))
70 (prog1 (setf (bref iobuf end
) octet
)
71 (incf (iobuf-end iobuf
)))))