(require "olunit") (defpackage #:xdr (:use #:openlisp #:olunit) (:export #:h-to-xdr #:xdr-to-h)) (in-package #:xdr) (defglobal *encode-buf* nil) (defun buffer-init (buf op) (case op ((encode) (setq *encode-buf* buf)) ((decode) (setq *decode-buf* buf)) (t (error "bad op")))) (defun set-be-x (buf n) (setf (elt buf 0) (logand (ash -56 n) #xFF)) (setf (elt buf 1) (logand (ash -48 n) #xFF))) (defun h-to-xdr (n) (set-be-x xdr-encode-buf n)) (provide "xdr") (deftest wrt-test () (buffer-init buffer 'encode) (i-to-xdr 1234) (write-file buffer +bytes-per-unit+ fh))