Created
September 30, 2011 17:58
-
-
Save joelreymont/1254505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro read-foreign (foreign-type buffer index) | |
(let ((size (fli:size-of foreign-type))) | |
`(let ((index ,index)) | |
(fli:with-dynamic-foreign-objects ((value ,foreign-type)) | |
(fli:with-coerced-pointer (bytes :type '(:unsigned :char)) value | |
(dotimes (byte-index ,size) | |
(let ((endian-byte-index #+LITTLE-ENDIAN byte-index | |
#-LITTLE-ENDIAN (- (1- limit) byte-index))) | |
(setf (fli:dereference bytes :index endian-byte-index) | |
(aref ,buffer index))) | |
(incf index)) | |
(values (fli:dereference value) index) | |
))))) | |
(defmacro write-foreign (value foreign-type buffer index) | |
(let ((size (fli:size-of foreign-type))) | |
`(fli:with-dynamic-foreign-objects ((value ,foreign-type :initial-element ,value)) | |
(fli:with-coerced-pointer (bytes :type '(:unsigned :char)) value | |
(dotimes (byte-index ,size) | |
(let ((endian-byte-index #+LITTLE-ENDIAN byte-index | |
#-LITTLE-ENDIAN (- (1- limit) byte-index))) | |
(setf (aref ,buffer ,index) | |
(fli:dereference bytes :index endian-byte-index))) | |
(incf ,index)) | |
,index | |
)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment