-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes.lisp
71 lines (43 loc) · 1.58 KB
/
bytes.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;;; -*- Mode: Lisp -*-
;;;; bytes.lisp --
;;;;
;;;; Functions needed to handle bytes (UNISIGNED-BYTE 8) and byte
;;;; buffers.
(in-package "CL3270")
(deftype octet ()
'(unsigned-byte 8))
(deftype buffer ()
'(array (unsigned-byte 8) (*)))
(declaim (inline make-buffer))
(defun make-buffer (&key (length 0)
(capacity 2048) ; A bit more than 80 * 24.
)
(declare (type (integer 0 (#.array-total-size-limit)) length)
(type (integer 1 (#.array-total-size-limit)) capacity))
(make-array capacity
:element-type '(unsigned-byte 8)
:initial-element 0
:fill-pointer (min length (max 1 (1- capacity))) ; Being paranoid.
))
(declaim (inline write-buffer))
(defun write-buffer (buffer b)
"Write a (unsigned) byte B at the end of BUFFER.
The 'end' of BUFFER is actually its FILL-POINTER; that is, BUFFER must
be a vector with a FILL-POINTER.
The (modified) BUFFER is returned."
(declare (type buffer buffer)
(type unsigned-byte b))
(vector-push b buffer)
buffer)
(declaim (inline write-buffer*))
(defun write-buffer* (buffer bs)
"Appends a vector of (unsigned) bytes BS at the end of BUFFER.
The 'end' of BUFFER is actually its FILL-POINTER; that is, BUFFER must
be a vector with a FILL-POINTER.
The (modified) BUFFER is returned."
(declare (type vector bs)
(type buffer buffer))
(loop for b of-type unsigned-byte across bs
do (vector-push b buffer))
buffer)
;;;; end of file -- bytes.lisp