From dc7083e59bbf432623858a67266440c2cda37a5d Mon Sep 17 00:00:00 2001 From: Igor Almeida Date: Fri, 30 Dec 2022 12:37:35 -0300 Subject: [PATCH 1/2] support NEW_PID_EXT control messages --- src/erlang-pid.lisp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/erlang-pid.lisp b/src/erlang-pid.lisp index a87f80e..1be3e36 100644 --- a/src/erlang-pid.lisp +++ b/src/erlang-pid.lisp @@ -6,6 +6,7 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +pid-ext+ 103) + (defconstant +new-pid-ext+ 88) ) @@ -51,14 +52,18 @@ (defmethod decode-erlang-object ((tag (eql +pid-ext+)) bytes pos) (decode-external-pid bytes pos)) +(defmethod decode-erlang-object ((tag (eql +new-pid-ext+)) bytes pos) + (decode-external-pid bytes pos t)) + (defun decode-erlang-pid (bytes &optional (pos 0)) (let ((tag (aref bytes pos))) (case tag - (#.+pid-ext+ (decode-external-pid bytes (1+ pos))) + ((#.+pid-ext+ #.+new-pid-ext+) + (decode-external-pid bytes (1+ pos) (eql tag #.+new-pid-ext+))) (otherwise (error 'unexpected-erlang-term :received-tag tag - :expected-tags (list +pid-ext+))) ))) + :expected-tags (list +pid-ext+ +new-pid-ext+))) ))) ;; PID_EXT @@ -68,21 +73,32 @@ ;; | 103 | Node | ID | Serial | Creation | ;; +-----+------+----+--------+----------+ ;; +;; NEW_PID_EXT +;; +-----+------+----+--------+----------+ +;; | 1 | N | 4 | 4 | 4 | +;; +-----+------+----+--------+----------+ +;; | 88 | Node | ID | Serial | Creation | +;; +-----+------+----+--------+----------+ +;; (defun encode-external-pid (pid) (with-slots (node id serial creation) pid (concatenate 'nibbles:simple-octet-vector - (vector +pid-ext+) + (vector +new-pid-ext+) (encode-erlang-object node) id serial - (vector creation)))) + (uint32-to-bytes creation)))) -(defun decode-external-pid (bytes &optional (pos 0)) +(defun decode-external-pid (bytes &optional (pos 0) (new-pid-ext nil)) (multiple-value-bind (node pos1) (decode-erlang-atom bytes pos) (values (make-instance 'erlang-pid :node node :id (subseq bytes pos1 (+ pos1 4)) :serial (subseq bytes (+ pos1 4) (+ pos1 8)) - :creation (aref bytes (+ pos1 8))) - (+ pos1 9)))) + :creation (if new-pid-ext + (subseq bytes (+ pos1 8) (+ pos1 12)) + (aref bytes (+ pos1 8)))) + (if new-pid-ext + (+ pos1 12) + (+ pos1 9))))) From 2e9b9d596f1917b472dee8df4e54693f17e4a5cd Mon Sep 17 00:00:00 2001 From: Igor Almeida Date: Fri, 30 Dec 2022 16:15:36 -0300 Subject: [PATCH 2/2] tests for NEW_PID_EXT messages this feels incomplete, since it is using deprecated ATOM_REF and not utf8 atoms... FWIW, it does work. --- test/decode-tests.lisp | 7 +++++++ test/encode-tests.lisp | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/decode-tests.lisp b/test/decode-tests.lisp index 1613384..ec43322 100644 --- a/test/decode-tests.lisp +++ b/test/decode-tests.lisp @@ -148,6 +148,13 @@ 'erlang-pid)) ) +(test decode-new-pid + ;; NEW_PID_EXT + (is (typep (decode (nibbles:octet-vector 131 88 100 0 4 65 66 66 65 + 0 0 0 1 87 0 13 140 0 0 0 1)) + 'erlang-pid)) + ) + (test decode-port ;; PORT_EXT (is (typep (decode diff --git a/test/encode-tests.lisp b/test/encode-tests.lisp index 9ecad34..8a5b5ae 100644 --- a/test/encode-tests.lisp +++ b/test/encode-tests.lisp @@ -128,9 +128,9 @@ (encode (list 1))))) ) -(test encode-pid - ;; PID_EXT - (is (equalp (nibbles:octet-vector 131 103 115 4 65 66 66 65 0 0 0 1 0 0 0 0 1) +(test encode-new-pid + ;; NEW_PID_EXT + (is (equalp (nibbles:octet-vector 131 88 115 4 65 66 66 65 0 0 0 1 0 0 0 0 0 0 0 1) (encode (make-pid "ABBA" #(0 0 0 1) #(0 0 0 0) 1)))) )