Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created August 22, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AeroNotix/6b5aa70ca115362fb8b3 to your computer and use it in GitHub Desktop.
Save AeroNotix/6b5aa70ca115362fb8b3 to your computer and use it in GitHub Desktop.
(in-package :cl-zk)
(defun make-clos-field (name)
(let ((keyword-name (values (alexandria:make-keyword name))))
`(,name :accessor ,name :initarg ,keyword-name)))
(defun writer-for-type (fieldspec stream)
(let ((name (first fieldspec))
(type (second fieldspec)))
(ccase type
(int `(write-int ,name ,stream)))))
(defmacro define-message (name superclasses fields)
(let ((names (mapcar #'car fields))
(value-sym (gensym))
(stream-sym (gensym)))
`(progn
(defclass ,name ,superclasses
,(mapcar #'make-clos-field names))
(defmethod encode-value ((,value-sym ,name) ,stream-sym)
(with-slots ,names ,value-sym
,@(mapcar (lambda (p)
(writer-for-type p stream-sym)) fields))))))
(define-message connect-request ()
((protocol-version int)
(last-zxid-seen bigint)
(timeout int)
(session-id bigint)
(password byte-array)))
(define-message connect-request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment