Commit 3d14cbf2 authored by rtoy's avatar rtoy
Browse files

o Add some docstrings to READ-VECTOR and WRITE-VECTOR.

o Fix a confusion about the length of the vector versus the start and
  end octets.  If END is not given, we use the length of the vector,
  but it must be scaled by the number of octets per element.
parent 38938011
......@@ -5,7 +5,7 @@
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
"$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/stream-vector-io.lisp,v 1.3 2007/11/05 15:25:03 rtoy Exp $")
"$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/stream-vector-io.lisp,v 1.4 2009/04/10 17:21:35 rtoy Exp $")
;;;
;;; **********************************************************************
;;;
......@@ -105,6 +105,10 @@
;;; READ-VECTOR --
(defun read-vector (vector stream &key (start 0) end (endian-swap :byte-8))
"Read from Stream into Vector. The Start and End indices of Vector
is in octets, and must be an multiple of the octets per element of
the vector element. The keyword argument :Endian-Swap specifies any
endian swapping to be done. "
(declare (type vector vector)
(type stream stream)
(type unsigned-byte start) ; a list does not have a limit
......@@ -129,14 +133,18 @@
;;; WRITE VECTOR --
;;; returns the next octet-position in vector.
(defun write-vector (vector stream &key (start 0) (end nil) (endian-swap :byte-8))
"Write Vector to Stream. The Start and End indices of Vector is in
octets, and must be an multiple of the octets per element of the
vector element. The keyword argument :Endian-Swap specifies any
endian swapping to be done. "
(declare (type vector vector)
(type stream stream)
(type unsigned-byte start) ; a list does not have a limit
(type (or null unsigned-byte) end)
(values unsigned-byte))
(let* ((end (or end (length vector)))
(octets-per-element (vector-elt-width vector))
(let* ((octets-per-element (vector-elt-width vector))
(end (or end (* octets-per-element (length vector))))
(swap-mask (endian-swap-value vector endian-swap))
(next-index end))
(declare (type fixnum swap-mask end octets-per-element next-index))
......@@ -153,7 +161,9 @@
stream))
(endian-swap-vector vector start end swap-mask)
(unwind-protect
(write-sequence vector stream :start start :end end)
(write-sequence vector stream
:start (floor start octets-per-element)
:end (floor end octets-per-element))
(endian-swap-vector vector start end swap-mask))
vector))
(* next-index octets-per-element)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment