Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add msg data functions

  • Loading branch information...
commit 46869f882ff7f408cbb10d52e89ad859d99b754c 1 parent 92aff88
@galdor galdor authored
Showing with 24 additions and 1 deletion.
  1. +1 −1  src/packages.lisp
  2. +23 −0 src/zeromq.lisp
View
2  src/packages.lisp
@@ -15,7 +15,7 @@
:msg-init :msg-init-size :msg-init-data :msg-close
:with-msg-init :with-msg-init-size :with-msg-init-data
- :msg-size
+ :msg-size :msg-data :msg-data-string :msg-data-array
:msg-copy
:send :recv
View
23 src/zeromq.lisp
@@ -283,6 +283,29 @@ with DATA."
"Return the size in byte of the content of MESSAGE."
(%msg-size message))
+(defun msg-data (message)
+ "Get a foreign pointer on the content of MESSAGE."
+ (%msg-data message))
+
+(defun msg-data-array (message)
+ "Get the content of MESSAGE as an unsigned byte array."
+ (let ((data (%msg-data message)))
+ (unless (null-pointer-p data)
+ (let* ((length (- (msg-size message) 1))
+ (array (make-array length :element-type '(unsigned-byte 8))))
+ (with-pointer-to-vector-data (%array array)
+ (%memcpy %array data length))
+ array))))
+
+(defun msg-data-string (message &key (encoding *default-foreign-encoding*))
+ "Get the content of MESSAGE as a character string. The string is decoded
+using the character coding schema ENCODING."
+ (let ((data (%msg-data message)))
+ (unless (null-pointer-p data)
+ (foreign-string-to-lisp (%msg-data message)
+ :count (- (%msg-size message) 1)
+ :encoding encoding))))
+
(defun msg-copy (destination source)
"Copy the content of the message SOURCE to the message DESTINATION."
(call-ffi -1 '%msg-copy destination source))
Please sign in to comment.
Something went wrong with that request. Please try again.