emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master dcb301b 1/2: Support for binary blobs


From: Mario Lang
Subject: [elpa] master dcb301b 1/2: Support for binary blobs
Date: Thu, 19 Dec 2019 07:33:48 -0500 (EST)

branch: master
commit dcb301bb9894e2862183317622e6207bc0b8e8ed
Author: Mario Lang <address@hidden>
Commit: Mario Lang <address@hidden>

    Support for binary blobs
    
    * packages/osc/osc.el: (osc-blob, osc-read-blob): New functions.
    * (osc-send-message, osc-filter): Adjust.
---
 packages/osc/osc.el | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/packages/osc/osc.el b/packages/osc/osc.el
index e88f135..5450751 100644
--- a/packages/osc/osc.el
+++ b/packages/osc/osc.el
@@ -35,7 +35,7 @@
 
 ;; BUGS/TODO:
 ;;
-;; * Timetags and binary blobs are not supported yet.
+;; * Timetags are not supported yet.
 
 ;; Usage:
 ;;
@@ -55,6 +55,12 @@
   (setq string (encode-coding-string string 'binary))
   (concat string (make-string (1+ (- 3 (% (length string) 4))) 0)))
 
+(defun osc-blob (vector)
+  (let ((length (length vector)))
+    (concat (osc-int32 length)
+           vector
+           (make-string (% (- 4 (% length 4)) 4) 0))))
+
 (defun osc-float32 (value)
   (let (s (e 0) f)
     (cond
@@ -112,6 +118,7 @@
                 ((floatp arg) "f")
                 ((integerp arg) "i")
                 ((stringp arg) "s")
+                ((vectorp arg) "b")
                 (t (error "Invalid argument: %S" arg))))
              args)))
     (mapcar
@@ -119,7 +126,8 @@
        (cond
        ((floatp arg) (osc-float32 arg))
        ((integerp arg) (osc-int32 arg))
-       ((stringp arg) (osc-string arg))))
+       ((stringp arg) (osc-string arg))
+       ((vectorp arg) (osc-blob arg))))
      args))))
 
 (defun osc-read-string ()
@@ -129,6 +137,16 @@
     (forward-char (- 4 (% (length string) 4)))
     string))
 
+(defun osc-read-blob ()
+  (let* ((length (osc-read-int32))
+        (pos (point))
+        (vector (progn
+                  (forward-char length)
+                  (string-to-vector (buffer-substring pos (point)))))
+        (padding (% (- 4 (% length 4)) 4)))
+    (forward-char padding)
+    vector))
+
 (defun osc-read-int32 ()
   (let ((value 0))
     (dotimes (i 4)
@@ -179,13 +197,14 @@ the generic handler for SERVER."
       (goto-char (point-min))
       (let ((path (osc-read-string)))
        (if (not (string= path "#bundle"))
-           (when (looking-at ",")
+           (when (= (char-after) ?,)
              (save-excursion
                (apply (osc-server-get-handler proc path)
                       path
                       (mapcar
                        (lambda (type)
                          (cl-case type
+                           (?b (osc-read-blob))
                            (?f (osc-read-float32))
                            (?i (osc-read-int32))
                            (?s (osc-read-string))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]