[nio-cvs] r54 - branches/home/psmith/restructure/src/buffer

psmith at common-lisp.net psmith at common-lisp.net
Mon Jan 29 01:54:11 UTC 2007


Author: psmith
Date: Sun Jan 28 20:54:10 2007
New Revision: 54

Modified:
   branches/home/psmith/restructure/src/buffer/buffer.lisp
Log:
Added 8 & 32 accessors for the bytebuffer

Modified: branches/home/psmith/restructure/src/buffer/buffer.lisp
==============================================================================
--- branches/home/psmith/restructure/src/buffer/buffer.lisp	(original)
+++ branches/home/psmith/restructure/src/buffer/buffer.lisp	Sun Jan 28 20:54:10 2007
@@ -68,6 +68,12 @@
 
 ;;-- end utils
 
+(defun get-readable-char (char-code)
+  (if (<= char-code 32)
+      (code-char 46)
+      (if (> char-code 127)
+	  (code-char 46)
+	  (code-char char-code))))
 
 (defun pretty-hex-dump (start-address length)
 ;  (format t "start: ~A length ~A~%" start-address length)
@@ -86,7 +92,7 @@
 			    (format readable "--"))
 			  (progn 
 			    (format str (if (eql column-index 7) "~A   " "~A ") (hex-dump-byte address))
-			    (format readable "~A" (code-char (byte-value address)))))))))))))
+			    (format readable "~A" (get-readable-char (byte-value address)))))))))))))
 
 (defun make-uint8-seq (size)
   "Make uint8 sequence."
@@ -100,7 +106,7 @@
 
 (defmethod print-object ((byte-buffer byte-buffer) stream)
   (with-slots (capacity position limit buf) byte-buffer
-    (format stream "<byte-buffer :capacity ~A :position ~A :limit ~A :buf ~%~A>~%" capacity position limit (if buf (hex-dump-memory (cffi:pointer-address buf) limit) nil))))
+    (format stream "<byte-buffer :capacity ~A :position ~A :limit ~A :buf ~%~A>~%" capacity position limit (if buf (pretty-hex-dump (cffi:pointer-address buf) limit) nil))))
 
 (defmethod free-buffer((byte-buffer byte-buffer))
   (with-slots (capacity position limit buf) byte-buffer
@@ -171,9 +177,14 @@
 
 (defmethod bytebuffer-write-8 ((bb byte-buffer) value)
   (setf (cffi:mem-ref (buffer-buf bb) :unsigned-char (buffer-position bb)) value)
-;  (cffi:mem-set value (buffer-buf bb) :unsigned-char position)
   (inc-position bb 1))
 
+(defmethod bytebuffer-write-32 ((bb byte-buffer) value)
+  (setf (cffi:mem-ref (buffer-buf bb) :unsigned-int (buffer-position bb)) value)
+  (inc-position bb 4))
+
+
+
 ;; Write bytes from vector vec to bytebuffer
 (defmethod bytebuffer-write-vector((bb byte-buffer) vec)
   :documentation "Returns number of bytes written to bytebuffer"
@@ -244,6 +255,23 @@
 
     (format t "Mybuf (after clear): ~A~%" (clear mybuf))
 
+    ;test accessors
+    (setf (buffer-position mybuf) 11)
+    (bytebuffer-write-8 mybuf 243)
+    (assert (eql (buffer-position mybuf) 12))
+    (setf (buffer-position mybuf) 11)
+    (assert (eql (bytebuffer-read-8 mybuf) 243))
+    (format t "Mybuf (after r/w 8bit): ~A~%" mybuf)
+
+    (setf (buffer-position mybuf) 11)
+    (bytebuffer-write-32 mybuf 2147483649)
+    (assert (eql (buffer-position mybuf) 15))
+    (setf (buffer-position mybuf) 11)
+    (assert (eql (bytebuffer-read-32 mybuf) 2147483649))
+    (format t "Mybuf (after r/w 32bit): ~A~%" mybuf)
+
+
+
     (free-buffer mybuf)
     (format t "Mybuf after free: ~A~%" mybuf)))
 



More information about the Nio-cvs mailing list