Skip to content

Commit

Permalink
Protocol version should be passed in to the encoding functions, not s…
Browse files Browse the repository at this point in the history
…pecified by a global constant.

The protocol version is still specified with a constant, but higher level function now pass it in when encoding terms.
  • Loading branch information
flambard committed Nov 10, 2012
1 parent d6f2e27 commit e405e22
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/bert.lisp
Expand Up @@ -44,6 +44,7 @@


(in-package :bert) (in-package :bert)


(defconstant +protocol-version+ 131)


(defgeneric translate-complex-type (object) (defgeneric translate-complex-type (object)
(:documentation "Translates tuples with the 'bert' tag to corresponding Lisp objects.")) (:documentation "Translates tuples with the 'bert' tag to corresponding Lisp objects."))
Expand Down Expand Up @@ -113,7 +114,8 @@




(defmethod encode (object &key berp-header) (defmethod encode (object &key berp-header)
(let ((bytes (cleric:encode (translate-complex-type object) :version-tag t))) (let ((bytes (cleric:encode (translate-complex-type object)
:version-tag +protocol-version+)))
(if berp-header (if berp-header
(concatenate '(vector (unsigned-byte 8)) (concatenate '(vector (unsigned-byte 8))
(uint32-to-bytes (length bytes)) (uint32-to-bytes (length bytes))
Expand Down Expand Up @@ -206,6 +208,7 @@




(defun decode (bytes) (defun decode (bytes)
(multiple-value-bind (term pos) (cleric:decode bytes :version-tag t) (multiple-value-bind (term pos)
(cleric:decode bytes :version-tag +protocol-version+)
(values (translate-complex-terms term) pos))) (values (translate-complex-terms term) pos)))


1 change: 0 additions & 1 deletion src/constants.lisp
Expand Up @@ -4,7 +4,6 @@


;;; Node protocol type tags ;;; Node protocol type tags
(defconstant +pass-through+ 112) (defconstant +pass-through+ 112)
(defconstant +protocol-version+ 131)




;;; Erlang data tags ;;; Erlang data tags
Expand Down
6 changes: 3 additions & 3 deletions src/decode.lisp
Expand Up @@ -6,12 +6,12 @@


(defun decode (bytes &key (start 0) (version-tag nil)) (defun decode (bytes &key (start 0) (version-tag nil))
"Decode a sequence of bytes to an Erlang object." "Decode a sequence of bytes to an Erlang object."
(when version-tag (when (integerp version-tag)
(let ((version (aref bytes start))) (let ((version (aref bytes start)))
(unless (= version +protocol-version+) (unless (= version version-tag)
(error 'unexpected-message-tag-error (error 'unexpected-message-tag-error
:received-tag version :received-tag version
:expected-tags (list +protocol-version+)))) :expected-tags (list version-tag))))
(incf start)) (incf start))
(let ((tag (aref bytes start))) (let ((tag (aref bytes start)))
(case tag (case tag
Expand Down
1 change: 1 addition & 0 deletions src/distribution-header.lisp
Expand Up @@ -48,6 +48,7 @@
;; +----------------------+ ;; +----------------------+
;; ;;


(defconstant +protocol-version+ 131)
(defconstant +distribution-header-tag+ 68) (defconstant +distribution-header-tag+ 68)


(defun decode-distribution-header (bytes &optional (pos 0)) (defun decode-distribution-header (bytes &optional (pos 0))
Expand Down
6 changes: 3 additions & 3 deletions src/erlang-tuple.lisp
Expand Up @@ -51,12 +51,12 @@
(encode-external-large-tuple x atom-cache-entries))) (encode-external-large-tuple x atom-cache-entries)))


(defun decode-erlang-tuple (bytes &key (start 0) (version-tag nil)) (defun decode-erlang-tuple (bytes &key (start 0) (version-tag nil))
(when version-tag (when (integerp version-tag)
(let ((version (aref bytes start))) (let ((version (aref bytes start)))
(unless (= version +protocol-version+) (unless (= version version-tag)
(error 'unexpected-message-tag-error (error 'unexpected-message-tag-error
:received-tag version :received-tag version
:expected-tags (list +protocol-version+)))) :expected-tags (list version-tag))))
(incf start)) (incf start))
(let ((tag (aref bytes start))) (let ((tag (aref bytes start)))
(case tag (case tag
Expand Down
4 changes: 2 additions & 2 deletions src/generic-functions.lisp
Expand Up @@ -8,9 +8,9 @@
(:documentation "Encodes the Erlang translatable object to a vector of bytes.")) (:documentation "Encodes the Erlang translatable object to a vector of bytes."))


(defmethod encode :around (x &key version-tag atom-cache-entries) (defmethod encode :around (x &key version-tag atom-cache-entries)
(if version-tag (if (integerp version-tag)
(concatenate '(vector octet) (concatenate '(vector octet)
(vector +protocol-version+) (vector version-tag)
(call-next-method x :atom-cache-entries atom-cache-entries)) (call-next-method x :atom-cache-entries atom-cache-entries))
(call-next-method x :atom-cache-entries atom-cache-entries))) (call-next-method x :atom-cache-entries atom-cache-entries)))


Expand Down
7 changes: 5 additions & 2 deletions src/node-protocol.lisp
Expand Up @@ -101,7 +101,8 @@
(write-uint32 (+ (length dh) (length cm)) stream) (write-uint32 (+ (length dh) (length cm)) stream)
(write-sequence dh stream) (write-sequence dh stream)
(write-sequence cm stream))) (write-sequence cm stream)))
(let ((cm (encode-control-message control-message :version-tag t))) (let ((cm (encode-control-message control-message
:version-tag +protocol-version+)))
(write-uint32 (1+ (length cm)) stream) (write-uint32 (1+ (length cm)) stream)
(write-byte +pass-through+ stream) (write-byte +pass-through+ stream)
(write-sequence cm stream))) (write-sequence cm stream)))
Expand All @@ -123,7 +124,9 @@
(error 'connection-closed-error))))) (error 'connection-closed-error)))))
(case (aref bytes 0) (case (aref bytes 0)
(#.+pass-through+ (#.+pass-through+
(decode-control-message bytes :start 1 :version-tag t)) (decode-control-message bytes
:start 1
:version-tag +protocol-version+))
(#.+protocol-version+ (#.+protocol-version+
(multiple-value-bind (cache pos) (decode-distribution-header bytes 1) (multiple-value-bind (cache pos) (decode-distribution-header bytes 1)
(let ((*cached-atoms* cache)) (let ((*cached-atoms* cache))
Expand Down

0 comments on commit e405e22

Please sign in to comment.