Commit 63c83f34 authored by  Hayley Patton's avatar Hayley Patton 🐢

Use byte arrays for hashes in references, helper functions in renderers for base64 and base64-data

parent 2b77c2e9
......@@ -16,11 +16,7 @@
(define-codec integer
(lambda (number)
(format nil "~d" number))
(lambda (string)
(parse-integer string)
(condition ()
(error "not parseable")))))
(define-codec boolean
(lambda (boolean)
......@@ -38,28 +34,20 @@
(define-codec base64
(lambda (string)
(with-output-to-string (output)
(encode-base64-bytes (string-to-octets string :external-format *encoding*)
(bytes->base64 (string-to-octets string :external-format *encoding*)))
(lambda (base64)
(with-input-from-string (input base64)
(octets-to-string (decode-base64-bytes input)
:external-format *encoding*))))
(octets-to-string (base64->bytes base64)
:external-format *encoding*)))
(define-codec base64-data
(lambda (vector)
(with-output-to-string (output)
(encode-base64-bytes vector output)))
(lambda (base64)
(with-input-from-string (input base64)
(decode-base64-bytes input))))
#'bytes->base64 #'base64->bytes)
(define-codec ref
(lambda (reference)
(check-type reference reference)
(format nil (reference-hash reference)))
(bytes->base64 (reference-hash reference)))
(lambda (string)
(make-instance 'reference :hash string)))
(make-instance 'reference :hash (base64->bytes string))))
(defun find-codec (name type)
(let ((codec-definition (gethash name *codecs*)))
......@@ -151,4 +151,3 @@ string; but RENDER-OBJECT will emit Netfarm standard format text."))
(:method ((vector vector) stream)
(write-string "base64-data:" stream)
(s-base64:encode-base64-bytes vector stream nil)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment