-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbytes.lisp
More file actions
116 lines (80 loc) · 2.77 KB
/
Copy pathbytes.lisp
File metadata and controls
116 lines (80 loc) · 2.77 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;;;; -*- Mode: Lisp: Coding: utf-8 -*-
;;;; bytes.lisp --
;;;;
;;;; Functions needed to handle bytes (UNISIGNED-BYTE 8) and byte
;;;; buffers.
;;;;
;;;; See the file COPYING for copyright and licensing information.
(in-package "CL3270")
(deftype octet ()
"The Octet Type.
Useful as a shorthand."
'(unsigned-byte 8))
(deftype rune ()
"The Rune Type.
A shorthand for two-bytes 'code points'."
'(unsigned-byte 16))
(deftype dict ()
"The Dict Type.
Just a synonym of hash-table."
'hash-table)
(deftype buffer ()
"The Buffer Type.
Denotes the vectors that contain `octet's.
Notes:
Often these vectors have a fill pointer and are adjustable."
'(array octet (*)))
(declaim (inline make-buffer))
(defun make-buffer (&key (length 0)
(capacity 5280) ; 132 * 40.
)
(declare (type (integer 0 (#.array-total-size-limit)) length)
(type (integer 1 (#.array-total-size-limit)) capacity))
(assert (<= length capacity))
(make-array capacity
:element-type 'octet
:initial-element 0
:fill-pointer length
))
(declaim (ftype (function (buffer octet) buffer) write-buffer)
(inline write-buffer))
(defun write-buffer (buffer b)
"Write a (unsigned) byte, an octet, 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 (ftype (function (buffer (vector octet)) buffer) write-buffer*)
(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 octet across bs
do (vector-push b buffer))
buffer)
(declaim (ftype (function (buffer &rest octet) buffer) write-octets-buffer)
(inline write-octets-buffer))
(defun write-octets-buffer (buffer &rest octets)
"Appends OCTETS at the end of BUFFER.
OCTETS is a list of OCTET.
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 list octets)
(type buffer buffer))
(loop for b of-type octet in octets
do (vector-push b buffer))
buffer)
(declaim (ftype (function (&rest octet) buffer) bufferize))
(defun bufferize (&rest octets)
(let ((buf (make-buffer :capacity (length octets))))
(dolist (o octets buf)
(vector-push o buf))))
;;;; end of file -- bytes.lisp